forked from troncali/nest-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.yml
198 lines (190 loc) · 6.23 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
version: "3"
services:
db:
build:
context: .
dockerfile: ./src/docker/db-postgres.Dockerfile
# dockerfile: ./src/docker/db-mongo.Dockerfile
container_name: db
deploy:
mode: global
restart: always
volumes:
- db-data:/var/lib/postgresql/data
#- db-data:/data/db
secrets:
- DB_USERNAME
- DB_PASSWORD
environment:
- POSTGRES_USER_FILE=/run/secrets/DB_USERNAME
- POSTGRES_PASSWORD_FILE=/run/secrets/DB_PASSWORD
- POSTGRES_DB=${DB_DATABASE_NAME}
- TZ=${APP_TIMEZONE}
# - MONGO_INITDB_ROOT_USERNAME_FILE=/run/secrets/DB_USERNAME
# - MONGO_INITDB_ROOT_PASSWORD_FILE=/run/secrets/DB_PASSWORD
networks:
- backend-network
### Use `app_nework` so database is privately exposed only to these
### Docker services. Use ports instead of networks if public exposure
### is needed for external services.
# ports:
# - "${DB_PORT}:${DB_PORT}"
backend:
build:
context: .
dockerfile: ./src/docker/backend.Dockerfile
container_name: backend-blue
deploy:
mode: replicated
replicas: 1
restart: always
secrets:
- DB_USERNAME
- DB_PASSWORD
- BACKEND_SESSION_KEY_1
environment:
- NODE_ENV=production
- DOCKER_ENV=true
- BACKEND_PORT=${BACKEND_PORT}
- BACKEND_BASE_ROUTE=${BACKEND_BASE_ROUTE}
- DB_AUTO_LOAD_ENTITIES=${DB_AUTO_LOAD_ENTITIES}
- DB_DATABASE_NAME=${DB_DATABASE_NAME}
- DB_HOST=${DB_HOST}
- DB_PORT=${DB_PORT}
- DB_SCHEMA=${DB_SCHEMA}
- GRAPHQL_PATH=${GRAPHQL_PATH}
- TZ=${APP_TIMEZONE}
networks:
- backend-network
- frontend-network
### Use `app_nework` so service is not publicly exposed to ensure
### routing through nginx. Use ports instead of networks if public
### exposure is needed for external services.
# ports:
# - "${BACKEND_PORT}:${BACKEND_PORT}"
placeholder:
build:
context: .
dockerfile: ./src/docker/placeholder.Dockerfile
container_name: backend-green
networks:
- frontend-network
nginx:
build:
context: .
dockerfile: ./src/docker/nginx.Dockerfile
args:
- NGINX_DH_BITS=${NGINX_DH_BITS} # Used in Dockerfile for build
- NGINX_GID=${NGINX_GID}
- NGINX_UID=${NGINX_UID}
container_name: nginx
deploy:
mode: global
restart: always
read_only: true
secrets:
- NGINX_STAGING_AUTH
volumes:
- certbot-html:/usr/share/nginx/html/certbot:ro
- certbot-var:/var/lib/letsencrypt:ro
- dhparam:/var/certs:ro
- frontend-blue:/usr/share/nginx/html/blue:ro
- frontend-green:/usr/share/nginx/html/green:ro
- worker-flags:/opt/flags:ro
- nginx-writeable:/tmp
- nginx-confs:/tmp/confs
# Set up a read-only volume for consuming generated .conf files
- type: volume
source: nginx-confs
target: /etc/nginx/confs
read_only: true
ports:
- "80:8080"
- "443:8443"
networks:
- frontend-network
environment:
- APP_DOMAIN=${APP_DOMAIN}
- BACKEND_BLUE_NAME=backend-blue
- BACKEND_GREEN_NAME=backend-green
- BACKEND_BASE_ROUTE=${BACKEND_BASE_ROUTE}
- BACKEND_PORT=${BACKEND_PORT}
- NGINX_DH_BITS=${NGINX_DH_BITS}
- NGINX_ENVSUBST_TEMPLATE_DIR=/etc/nginx/templates
- NGINX_ENVSUBST_TEMPLATE_SUFFIX=.template
# Important: `nginx.conf` location after template interpolation
- NGINX_ENVSUBST_OUTPUT_DIR=/tmp/confs
- TZ=${APP_TIMEZONE}
certbot:
build:
context: .
dockerfile: ./src/docker/certbot.Dockerfile
container_name: certbot
deploy:
mode: global
command:
[
"certonly",
"--webroot",
"--webroot-path=/var/www/html",
"--keep-until-expiring",
"--agree-tos",
"--no-eff-email",
"--email=${CERTBOT_EMAIL}",
"-d=${APP_DOMAIN}",
"-d=www.${APP_DOMAIN}",
"-d=staging.${APP_DOMAIN}"
]
volumes:
- ./src/docker/nginx/dev-certs:/opt/certbot/dev-certs
- certbot-etc:/etc/letsencrypt
- certbot-var:/var/lib/letsencrypt
- certbot-html:/var/www/html
- worker-flags:/opt/certbot/flags
environment:
- APP_DOMAIN=${APP_DOMAIN}
- CERTBOT_EMAIL=${CERTBOT_EMAIL}
- NGINX_GID=${NGINX_GID}
- NGINX_UID=${NGINX_UID}
worker:
build:
context: .
dockerfile: ./src/docker/worker.Dockerfile
network: none
container_name: worker
restart: always
deploy:
mode: global
volumes:
- worker-flags:/app/flags
- /var/run/docker.sock:/var/run/docker.sock
environment:
- CERTBOT_CONTAINER_NAME=certbot
- NGINX_CONTAINER_NAME=nginx
- TZ=${APP_TIMEZONE}
volumes:
certbot-etc:
certbot-html:
certbot-var:
db-data:
dhparam:
frontend-blue:
frontend-green:
nginx-confs:
nginx-writeable:
worker-flags:
networks:
frontend-network:
driver: bridge
backend-network:
driver: bridge
secrets:
DB_USERNAME:
file: ./src/docker/secrets/DB_USERNAME
DB_PASSWORD:
file: ./src/docker/secrets/DB_PASSWORD
BACKEND_SESSION_KEY_1:
file: ./src/docker/secrets/BACKEND_SESSION_KEY_1
NGINX_STAGING_AUTH:
file: ./src/docker/secrets/NGINX_STAGING_AUTH
# TODO: convert other services to run in read-only mode?