Skip to content

Commit cc2f975

Browse files
committed
♻️ Refactor service env variables to *.env files
to avoid unnecessary duplication and double declaration
1 parent f5d803c commit cc2f975

File tree

8 files changed

+31
-52
lines changed

8 files changed

+31
-52
lines changed

{{cookiecutter.project_slug}}/.env

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,11 @@ DOMAIN=localhost
55
# DOMAIN=local.dockertoolbox.tiangolo.com
66
# DOMAIN=localhost.tiangolo.com
77
# DOMAIN=dev.{{cookiecutter.domain_main}}
8-
BACKEND_CORS_ORIGINS={{cookiecutter.backend_cors_origins}}
9-
PROJECT_NAME={{cookiecutter.project_name}}
10-
SECRET_KEY={{cookiecutter.secret_key}}
11-
FIRST_SUPERUSER={{cookiecutter.first_superuser}}
12-
FIRST_SUPERUSER_PASSWORD={{cookiecutter.first_superuser_password}}
13-
14-
USERS_OPEN_REGISTRATION=False
158

169
TRAEFIK_TAG={{cookiecutter.traefik_constraint_tag}}
1710
TRAEFIK_PUBLIC_NETWORK={{cookiecutter.traefik_public_network}}
1811
TRAEFIK_PUBLIC_TAG={{cookiecutter.traefik_public_constraint_tag}}
1912

20-
POSTGRES_SERVER=db
21-
POSTGRES_USER=postgres
22-
POSTGRES_PASSWORD={{cookiecutter.postgres_password}}
23-
POSTGRES_DB=app
24-
25-
PG_ADMIN_DEFAULT_USER={{cookiecutter.pgadmin_default_user}}
26-
PG_ADMIN_DEFAULT_PASSWORD={{cookiecutter.pgadmin_default_user_password}}
27-
28-
FLOWER_BASIC_AUTH={{cookiecutter.flower_auth}}
29-
30-
SENTRY_DSN={{cookiecutter.sentry_dsn}}
31-
3213
DOCKER_IMAGE_BACKEND={{cookiecutter.docker_image_backend}}
3314
DOCKER_IMAGE_CELERYWORKER={{cookiecutter.docker_image_celeryworker}}
3415
DOCKER_IMAGE_FRONTEND={{cookiecutter.docker_image_frontend}}

{{cookiecutter.project_slug}}/docker-compose.shared.admin.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ services:
44
image: fenglc/pgadmin4
55
depends_on:
66
- db
7-
environment:
8-
- DEFAULT_USER=${PG_ADMIN_DEFAULT_USER}
9-
- DEFAULT_PASSWORD=${PG_ADMIN_DEFAULT_PASSWORD}
7+
env_file:
8+
- env-pgadmin.env
109
swagger-ui:
1110
image: swaggerapi/swagger-ui
1211
environment:
@@ -17,5 +16,5 @@ services:
1716
- /var/run/docker.sock:/var/run/docker.sock
1817
flower:
1918
image: totem/celery-flower-docker
20-
environment:
21-
- FLOWER_BASIC_AUTH=${FLOWER_BASIC_AUTH}
19+
env_file:
20+
- env-flower.env
Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
11
version: '3'
22
services:
33
db:
4+
env_file:
5+
- env-postgres.env
46
environment:
5-
- POSTGRES_DB=app
6-
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
77
- PGDATA=/var/lib/postgresql/data/pgdata
88
backend:
9+
env_file:
10+
- env-backend.env
11+
- env-postgres.env
912
environment:
1013
- SERVER_NAME=${DOMAIN}
11-
- SECRET_KEY=${SECRET_KEY}
12-
- BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS}
13-
- PROJECT_NAME=${PROJECT_NAME}
14-
- SENTRY_DSN=${SENTRY_DSN}
15-
- POSTGRES_SERVER=${POSTGRES_SERVER}
16-
- POSTGRES_USER=${POSTGRES_USER}
17-
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
18-
- POSTGRES_DB=${POSTGRES_DB}
19-
- FIRST_SUPERUSER=${FIRST_SUPERUSER}
20-
- FIRST_SUPERUSER_PASSWORD=${FIRST_SUPERUSER_PASSWORD}
21-
- USERS_OPEN_REGISTRATION=${USERS_OPEN_REGISTRATION}
2214
celeryworker:
23-
environment:
24-
- SENTRY_DSN=${SENTRY_DSN}
25-
- POSTGRES_SERVER=${POSTGRES_SERVER}
26-
- POSTGRES_USER=${POSTGRES_USER}
27-
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
28-
- POSTGRES_DB=${POSTGRES_DB}
29-
- FIRST_SUPERUSER=${FIRST_SUPERUSER}
30-
- FIRST_SUPERUSER_PASSWORD=${FIRST_SUPERUSER_PASSWORD}
31-
- USERS_OPEN_REGISTRATION=${USERS_OPEN_REGISTRATION}
15+
env_file:
16+
- env-backend.env
17+
- env-postgres.env

{{cookiecutter.project_slug}}/docker-compose.test.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ services:
55
context: ./backend
66
dockerfile: tests.dockerfile
77
command: bash -c "while true; do sleep 1; done"
8+
env_file:
9+
- env-backend.env
10+
- env-postgres.env
811
environment:
912
- SERVER_NAME=backend
10-
- POSTGRES_SERVER=${POSTGRES_SERVER}
11-
- POSTGRES_USER=${POSTGRES_USER}
12-
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
13-
- POSTGRES_DB=${POSTGRES_DB}
14-
- FIRST_SUPERUSER=${FIRST_SUPERUSER}
15-
- FIRST_SUPERUSER_PASSWORD=${FIRST_SUPERUSER_PASSWORD}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BACKEND_CORS_ORIGINS={{cookiecutter.backend_cors_origins}}
2+
PROJECT_NAME={{cookiecutter.project_name}}
3+
SECRET_KEY={{cookiecutter.secret_key}}
4+
FIRST_SUPERUSER={{cookiecutter.first_superuser}}
5+
FIRST_SUPERUSER_PASSWORD={{cookiecutter.first_superuser_password}}
6+
7+
USERS_OPEN_REGISTRATION=False
8+
9+
SENTRY_DSN={{cookiecutter.sentry_dsn}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FLOWER_BASIC_AUTH={{cookiecutter.flower_auth}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PG_ADMIN_DEFAULT_USER={{cookiecutter.pgadmin_default_user}}
2+
PG_ADMIN_DEFAULT_PASSWORD={{cookiecutter.pgadmin_default_user_password}}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
POSTGRES_SERVER=db
2+
POSTGRES_USER=postgres
3+
POSTGRES_PASSWORD={{cookiecutter.postgres_password}}
4+
POSTGRES_DB=app

0 commit comments

Comments
 (0)