0

gitlab runner (shell executor) results in the following Error: django.db.utils.OperationalError: unable to open database file

.gitlab-ci.yml:

stages:
  - test

pytest:
  stage: test
  image: docker/compose:latest
  tags:
    - test
  before_script:
    - docker-compose build
    - docker-compose run --rm django python manage.py migrate
    - docker-compose up -d
  script:
    - docker-compose run django python manage.py test

Django Engine settings.py:


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

Here is my Dockerfile. The WORKDIR ist /app

FROM python:3.8-alpine

ENV PATH="/scripts:${PATH}"

COPY ./requirements /requirements
RUN pip install -r /requirements/local.txt -r /requirements/production.txt
RUN apk del .tmp

RUN mkdir /app
COPY ./app /app
WORKDIR /app
COPY ./scripts /scripts

RUN chmod +x /scripts/*

RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/static

RUN adduser -D user
RUN chown -R user:user /vol
RUN chown -R user:user /app

RUN chmod -R 755 /vol/web
USER user

CMD ["entrypoint.sh"]

I do not push db.sqlite3 to my gitlab project.

1
  • Are you using a root or non-root user in your Dockerfile? Commented Apr 16, 2021 at 19:04

1 Answer 1

1

Try to add current user to your "run" command

docker-compose run -u root --rm django python manage.py migrate

Also, as you use dind to build your images, check option of your runner, the option privileged must be in a True condition

Sign up to request clarification or add additional context in comments.

8 Comments

This solution worked only once for me. I removed the dind because I am using shell executor
Now I get the following Error rm: cannot remove app/welcome/migrations/__pycache__/__init__.cpython-38.pyc: Permission denied
is gitlab-runner user in docker group?
yes. gitlab-runner : gitlab-runner docker
show your Dockerfile, it seems that your BASEDIR is not same with your WORKDIR
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.