Skip to content

Commit 5bcac88

Browse files
committed
Refactor docker-compose and run scripts
- switch to using app object from autoapp.py - update docker-compose files - split configuration into 3 separate files - docker-compose.yaml as base file - add postgres data as volume - docker-compose.override.yaml as "production" compose - included automatically by docker-compose when not using "--file" - doesn't publish ports for any service other than frontend - docker-compose.dev.yaml for development compose - best used from dev-composition.sh - publishes ports for each service - update dev-composition.sh - uses docker-compose.yaml and docker-compose.dev.yaml - remove using "up" docker-compose command by default - add dev.env used by dev-composition.sh
1 parent 6a120aa commit 5bcac88

8 files changed

+77
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# .env files with settings and secrets
22
*.env
3+
!dev.env

api/main.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@echo off
22

3-
waitress-serve %* --call "everycache_api.app:create_app"
3+
waitress-serve %* "autoapp:app"

api/main.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
waitress-serve $@ --call "everycache_api.app:create_app"
3+
waitress-serve $@ "autoapp:app"

dev-composition.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/bash
2-
docker-compose -f docker-compose.dev.yaml up $@
2+
3+
docker-compose --env-file dev.env --file docker-compose.yaml --file docker-compose.dev.yaml $@

dev.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# development environment variables for docker-compose
2+
3+
HASHIDS_SALT=dev-hashids-salt
4+
SECRET_KEY=dev-secret-key
5+
POSTGRES_USER=admin
6+
POSTGRES_PASSWORD=root

docker-compose.dev.yaml

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
1+
# development docker-compose; extends and overrides base docker-compose.yaml file;
2+
# for usage example, please see dev-composition.sh
3+
14
version: "3.9"
25

36
services:
4-
db:
5-
image: postgres:latest
6-
environment:
7-
- POSTGRES_PASSWORD=password
87
frontend:
9-
build: frontend
108
ports:
11-
- 80:3000
12-
depends_on:
13-
- api
9+
- 3000:3000
10+
1411
api:
15-
build: api
16-
ports:
17-
- 5000:8080
12+
environment:
13+
FLASK_ENV: development
14+
FRONTEND_APP_URL: frontend:3000
15+
HASHIDS_SALT: dev-hashids-salt
16+
SECRET_KEY: dev-secret-key
17+
command: flask run --host 0.0.0.0
1818
volumes:
1919
- ./api:/code
20-
command: ["waitress-serve", "autoapp:app"]
21-
environment:
22-
- DATABASE_URI=${DATABASE_URI}
23-
- FLASK_APP=${FLASK_APP}
24-
- FLASK_ENV=${FLASK_ENV}
25-
- SECRET_KEY=${SECRET_KEY}
26-
- HASHIDS_SALT=${HASHIDS_SALT}
27-
- FRONTEND_APP_URL=${FRONTEND_APP_URL}
28-
- REDIS_URL=${REDIS_URL}
29-
depends_on:
30-
- redis
31-
- db
20+
ports:
21+
- 5000:5000
22+
23+
database:
24+
ports:
25+
- 5432:5432
26+
3227
redis:
33-
image: redis:alpine
3428
ports:
3529
- 6379:6379
30+
3631
redis-commander:
3732
image: rediscommander/redis-commander:latest
33+
depends_on:
34+
- redis
3835
environment:
39-
- REDIS_HOST=redis
40-
- REDIS_PORT=6379
36+
REDIS_HOST: redis
37+
REDIS_PORT: 6379
4138
ports:
4239
- 8081:8081

docker-compose.override.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# "production" docker-compose; this file is added by default by docker-compose,
2+
# unless --file is specified and is skipped in dev-composition.sh
3+
4+
version: "3.9"
5+
6+
services:
7+
frontend:
8+
ports:
9+
- 80:3000
10+
11+
api:
12+
environment:
13+
FLASK_ENV: production
14+
FRONTEND_APP_URL: frontend:8080

docker-compose.yaml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
1+
# base docker-compose; docker-compose.override.yaml is added by default by docker-compose,
2+
# unless --file is specified and is manually added in dev-composition.sh
3+
14
version: "3.9"
25

36
services:
47
frontend:
58
build: frontend
6-
ports:
7-
- 80:3000
89
depends_on:
910
- api
11+
1012
api:
1113
build: api
12-
ports:
13-
- 5000:8080
1414
depends_on:
15+
- database
1516
- redis
17+
environment:
18+
DATABASE_URI: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/everycache
19+
FLASK_APP: autoapp:app
20+
FLASK_ENV:
21+
FRONTEND_APP_URL:
22+
HASHIDS_ALPHABET:
23+
HASHIDS_SALT:
24+
JWT_ACCESS_TOKEN_EXPIRY_MINUTES:
25+
JWT_REFRESH_TOKEN_EXPIRY_MINUTES:
26+
REDIS_URL: redis://redis:6379/0
27+
SECRET_KEY:
28+
29+
database:
30+
image: postgres:latest
31+
environment:
32+
POSTGRES_DB: everycache
33+
POSTGRES_USER:
34+
POSTGRES_PASSWORD:
35+
volumes:
36+
- database-data:/var/lib/postgresql/data
37+
1638
redis:
1739
image: redis:alpine
40+
41+
volumes:
42+
database-data:

0 commit comments

Comments
 (0)