diff --git a/django/Dockerfile b/django/Dockerfile index 7af91c0..817235d 100644 --- a/django/Dockerfile +++ b/django/Dockerfile @@ -6,7 +6,7 @@ FROM python:3.9.3-slim-buster #RUN addgroup --system app && adduser --system --group app # Create Directory -ENV APP_HOME=/srv/webapp +ENV APP_HOME=/srv/app RUN mkdir -p $APP_HOME RUN mkdir -p $APP_HOME/static diff --git a/django/Dockerfile.prod b/django/Dockerfile.prod index 561666a..767f1bf 100644 --- a/django/Dockerfile.prod +++ b/django/Dockerfile.prod @@ -6,7 +6,7 @@ FROM python:3.9.3-slim-buster RUN addgroup --system app && adduser --system --group app # Create Directory -ENV APP_HOME=/srv/webapp +ENV APP_HOME=/srv/app RUN mkdir -p $APP_HOME RUN mkdir -p $APP_HOME/static diff --git a/django/Dockerfile.stage b/django/Dockerfile.stage index 69bb81e..dec8bc3 100644 --- a/django/Dockerfile.stage +++ b/django/Dockerfile.stage @@ -6,11 +6,7 @@ FROM python:3.9.3-slim-buster # RUN addgroup --system app && adduser --system --group app # Create Directory -# Heroku -ENV APP_HOME=/app - -# Digital Ocean -# ENV APP_HOME=/srv/webapp +ENV APP_HOME=/srv/app RUN mkdir -p $APP_HOME RUN mkdir -p $APP_HOME/static diff --git a/django/entrypoint.do.sh b/django/entrypoint.do.sh index 65b1989..25dc240 100755 --- a/django/entrypoint.do.sh +++ b/django/entrypoint.do.sh @@ -1,6 +1,6 @@ #!/bin/sh -#Production EntryPoint +# Production EntryPoint if [ "$DATABASE" = "postgres" ] then @@ -20,16 +20,27 @@ fi; python manage.py makemigrations python manage.py migrate python manage.py createsuperuser --noinput + if [ "$run_fixtures" = true ]; then - echo "\n Running Django Fixture \n" + cat << EOF + + |-------------------------------------| + | Running Django Fixtures.... | + |-------------------------------------| + +EOF python manage.py loaddata categories python manage.py loaddata galleries python manage.py loaddata photos python manage.py collectstatic --noinput +else + cat << EOF + + |-------------------------------------| + | Ignoring Django Fixtures... | + |-------------------------------------| - # Disable run fixture command - export run_fixtures=false - #heroku config:add run_fixtures=false +EOF fi; exec "$@" diff --git a/django/entrypoint.sh b/django/entrypoint.sh index b3dbd5d..a97add5 100755 --- a/django/entrypoint.sh +++ b/django/entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/sh -#Entrypoint for Local Development +# Local Development Environment if [ "$DATABASE" = "postgres" ] then @@ -20,9 +20,26 @@ fi; python manage.py makemigrations python manage.py migrate python manage.py createsuperuser --noinput -python manage.py loaddata categories -python manage.py loaddata galleries -python manage.py loaddata photos -python manage.py collectstatic --noinput +if [ "$run_fixtures" = true ]; +then + cat << EOF + + |-------------------------------------| + | Running Django Fixtures.... | + |-------------------------------------| + +EOF + python manage.py loaddata categories + python manage.py loaddata galleries + python manage.py loaddata photos + python manage.py collectstatic --noinput +else + cat << EOF + |-------------------------------------| + | Ignoring Django Fixtures... | + |-------------------------------------| + +EOF +fi; exec "$@" diff --git a/docker-compose.prod.yaml b/docker-compose.prod.yaml index 45cde00..e26fa71 100644 --- a/docker-compose.prod.yaml +++ b/docker-compose.prod.yaml @@ -3,6 +3,7 @@ version: "3.3" services: django: + restart: always image: "${DJANGO_IMAGE}" container_name: django command: gunicorn photoshare.wsgi:application --worker-tmp-dir /dev/shm --workers=2 --threads=4 --worker-class=gthread --log-file=- --bind 0.0.0.0:8000 @@ -18,6 +19,7 @@ services: - redis db: + restart: always image: postgres:9.6.22-buster container_name: db ports: diff --git a/docker-compose.stage.yml b/docker-compose.stage.yml index 3223697..33b9d2e 100644 --- a/docker-compose.stage.yml +++ b/docker-compose.stage.yml @@ -3,6 +3,7 @@ version: "3.3" services: django: + restart: always image: "${DJANGO_IMAGE}" container_name: django command: gunicorn photoshare.wsgi:application --worker-tmp-dir /dev/shm --workers=2 --threads=4 --worker-class=gthread --log-file=- --bind 0.0.0.0:8000 @@ -17,7 +18,8 @@ services: - db - redis db: - image: postgres:12.0-alpine + restart: always + image: postgres:9.6.22-buster container_name: db restart: always ports: diff --git a/docker-compose.yml b/docker-compose.yml index 53ec5b4..9187dd3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,11 +2,12 @@ version: "3.3" services: django: + restart: always build: context: ./django dockerfile: Dockerfile container_name: dev-django - command: python manage.py runserver 0.0.0.0:8000 + command: gunicorn photoshare.wsgi:application --worker-tmp-dir /dev/shm --workers=2 --threads=4 --worker-class=gthread --log-file=- --bind 0.0.0.0:8000 environment: - REDIS_URL=redis://redis:6379/ ports: @@ -14,7 +15,6 @@ services: env_file: - ./.env.dev volumes: - - ./django/:/srv/app - static:/srv/app/static - media:/srv/app/media depends_on: @@ -22,7 +22,8 @@ services: - redis db: - image: postgres:12.0-alpine + restart: always + image: postgres:9.6.22-buster container_name: dev-db restart: always ports: