Permission denied with django migrations in docker

A.Raouf

I'm using docker compose with django - postgres - rabbitmq

All is going good even django container is up and running to the point I want to makemigrations it stops with django-celery-beat

Migrations for 'django_celery_beat':
django_1        |   /usr/local/lib/python2.7/site-packages/django_celery_beat/migrations/0005_auto_20190512_1531.py
django_1        |     - Alter field event on solarschedule
django_1        | Traceback (most recent call last):
django_1        |   File "/app/manage.py", line 10, in <module>
django_1        |     execute_from_command_line(sys.argv)
django_1        |   File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
django_1        |     utility.execute()
django_1        |   File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
django_1        |     self.fetch_command(subcommand).run_from_argv(self.argv)
django_1        |   File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
django_1        |     self.execute(*args, **cmd_options)
django_1        |   File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
django_1        |     output = self.handle(*args, **options)
django_1        |   File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 193, in handle
django_1        |     self.write_migration_files(changes)
django_1        |   File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 232, in write_migration_files
django_1        |     with io.open(writer.path, "w", encoding='utf-8') as fh:
django_1        | IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/django_celery_beat/migrations/0005_auto_20190512_1531.py

while user model is written down at migrations and it supposed to be inherited from AbstractUser at django itself but no permission error raised there

django_1        | Migrations for 'users':
django_1        |   users/migrations/0001_initial.py
django_1        |     - Create model UserAccount
django_1        |     - Create model Branch
django_1        |     - Create model Organization
django_1        |     - Add field organization to branch
django_1        |     - Add field bills_groups to useraccount
django_1        |     - Add field branch to useraccount
django_1        |     - Add field groups to useraccount
django_1        |     - Add field user_permissions to useraccount

so I tried to add sudo user to the python-2.7 alpine but actually I failed to run this command with sudo permission

So what should I do, should I run the image using virtualenv inside docker or is there any tweak to fix this one

Dockerfile

FROM python:2.7-alpine

ENV PYTHONUNBUFFERED 1
RUN addgroup -S django \
    && adduser -S -G django django

RUN apk update \
  && apk add sudo \
  # psycopg2 dependencies
  && apk add --virtual build-deps gcc python-dev musl-dev \
  && apk add postgresql-dev \
  # CFFI dependencies
  && apk add libffi-dev py-cffi \
  # Translations dependencies
  && apk add gettext \
  # https://docs.djangoproject.com/en/dev/ref/django-admin/#dbshell
  && apk add postgresql-client

# Requirements are installed here to ensure they will be cached.
COPY ./requirements.txt /requirements.txt
RUN pip install --no-cache-dir --default-timeout=100 -r /requirements.txt \
        && rm -rf /requirements

COPY ./compose/testing/django/entrypoint /entrypoint
RUN sed -i 's/\r//' /entrypoint
RUN chmod +x /entrypoint
RUN chown django /entrypoint

COPY ./compose/testing/django/start /start
RUN sed -i 's/\r//' /start
RUN chmod +x /start
RUN chown django /start

COPY . /app

RUN chown -R django /app

USER django

WORKDIR /app

ENTRYPOINT ["/entrypoint"]

docker-compose.yml

version: '3'

volumes:
  production_postgres_data: {}
  production_postgres_data_backups: {}

services:
  django: &django
    build:
      context: .
      dockerfile: ./compose/testing/django/Dockerfile
    image: panel_testing_django
    depends_on:
      - postgres
      - rabbitmq
    env_file:
      - ./.envs/.production/.django
      - ./.envs/.production/.postgres
    command: /start
    ports:
      - "8000"
    expose:
      - "8000"

  postgres:
    build:
      context: .
      dockerfile: ./compose/staging/postgres/Dockerfile
    image: panel_testing_postgres
    env_file:
      - ./.envs/.production/.postgres
    volumes:
      - production_postgres_data:/var/lib/postgresql/data
      - production_postgres_data_backups:/backups
    ports:
     - "5432"

  rabbitmq:
    hostname: rabbit
    image: rabbitmq:3-management
    environment:
      - RABBITMQ_DEFAULT_USER=admin
      - RABBITMQ_DEFAULT_PASS=mypass
    ports:
      - "5672:5672"  
      - "15672:15672"

  celeryworker:
    <<: *django
    image: panel_testing_celeryworker
    command: /start-celeryworker

  celerybeat:
    <<: *django
    image: panel_testing_celerybeat
    command: /start-celerybeat

  flower:
    <<: *django
    image: panel_testing_flower
    ports:
      - "5555:5555"
    command: /start-flower
A.Raouf

I've just used virtualenv inside docker and gives ownership to my user over the environment site-packages dir

RUN pip install virtualenv && virtualenv -p python /app/venv
RUN /app/venv/bin/pip install -r req.txt
RUN /app/venv/bin/python /app/code/manage.py makemigrations

and DONE

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related