Use docker extensions for env variables

This commit is contained in:
Sonny Bakker 2023-07-02 08:24:11 +02:00
parent 72f8426f72
commit 858c2c6eb3
3 changed files with 20 additions and 29 deletions

View file

@ -5,13 +5,9 @@ volumes:
node-modules: node-modules:
services: services:
db:
env_file: ./.development.env
celery: celery:
build: build:
target: development target: development
env_file: ./.development.env
volumes: volumes:
- ./src/:/app/src - ./src/:/app/src
@ -19,7 +15,6 @@ services:
build: build:
target: development target: development
command: python /app/src/manage.py runserver 0.0.0.0:8000 command: python /app/src/manage.py runserver 0.0.0.0:8000
env_file: ./.development.env
ports: ports:
- "${DJANGO_PORT:-8000}:8000" - "${DJANGO_PORT:-8000}:8000"
volumes: volumes:

View file

@ -5,21 +5,11 @@ volumes:
static-files: static-files:
services: services:
db:
env_file: ./.production.env
celery:
env_file: ./.production.env
django:
env_file: ./.production.env
nginx: nginx:
image: nginx:1.23 image: nginx:1.23
depends_on: depends_on:
django: django:
condition: service_healthy condition: service_healthy
env_file: ./.production.env
ports: ports:
# Note that --env-file should be used to set these correctly # Note that --env-file should be used to set these correctly
- "${NGINX_HTTP_PORT:-80}:80" - "${NGINX_HTTP_PORT:-80}:80"

View file

@ -6,8 +6,22 @@ volumes:
postgres-data: postgres-data:
static-files: static-files:
x-db-env: &db-env
POSTGRES_HOST:
POSTGRES_PORT:
POSTGRES_DB:
POSTGRES_USER:
POSTGRES_PASSWORD:
x-django-env: &django-env
<<: *db-env
DJANGO_SECRET_KEY:
DJANGO_SETTINGS_MODULE:
services: services:
db: db:
environment:
<<: *db-env
image: postgres:15 image: postgres:15
healthcheck: healthcheck:
# Note that --env-file should be used to set these correctly # Note that --env-file should be used to set these correctly
@ -33,13 +47,9 @@ services:
dockerfile: ./docker/django dockerfile: ./docker/django
target: production target: production
args: args:
POSTGRES_HOST: <<: *django-env
POSTGRES_PORT: environment:
POSTGRES_DB: <<: *django-env
POSTGRES_USER:
POSTGRES_PASSWORD:
DJANGO_SECRET_KEY:
DJANGO_SETTINGS_MODULE:
command: | command: |
celery worker -n worker1@%h celery worker -n worker1@%h
-n worker2@%h -n worker2@%h
@ -67,13 +77,9 @@ services:
dockerfile: ./docker/django dockerfile: ./docker/django
target: production target: production
args: args:
POSTGRES_HOST: <<: *django-env
POSTGRES_PORT: environment:
POSTGRES_DB: <<: *django-env
POSTGRES_USER:
POSTGRES_PASSWORD:
DJANGO_SECRET_KEY:
DJANGO_SETTINGS_MODULE:
entrypoint: /app/bin/docker-entrypoint.sh entrypoint: /app/bin/docker-entrypoint.sh
command: | command: |
gunicorn --bind 0.0.0.0:8000 gunicorn --bind 0.0.0.0:8000