Skip to content

Commit 537349b

Browse files
committed
adds migrator service to docker compose
1 parent d662d0e commit 537349b

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

docker-compose.yaml

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
1+
version: "3.9"
2+
13
services:
24
postgres:
3-
image: postgres:17
5+
image: postgres:17 # PostgreSQL image
46
container_name: postgres
57
environment:
6-
POSTGRES_USER: ${POSTGRES_USER}
8+
POSTGRES_USER: ${POSTGRES_USER} # From .env
79
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
810
POSTGRES_DB: ${POSTGRES_DB}
911
ports:
1012
- "${POSTGRES_PORT}:5432"
1113
volumes:
12-
- postgres_data:/var/lib/postgresql/data
13-
- ./migration/src/setup.sql:/docker-entrypoint-initdb.d/0-setup.sql
14-
- ./migration/src/refactor_platform_rs.sql:/docker-entrypoint-initdb.d/1-refactor_platform_rs.sql
15-
- ./migration/src/setup_default_user.sql:/docker-entrypoint-initdb.d/2-setup_default_user.sql
14+
- postgres_data:/var/lib/postgresql/data # Persist data
1615
networks:
1716
- backend_network
18-
healthcheck:
17+
healthcheck: # Wait for DB to become ready
1918
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
2019
interval: 5s
2120
timeout: 5s
2221
retries: 5
2322

23+
migrator:
24+
image: ${BACKEND_IMAGE_NAME} # Reuse your backend image
25+
container_name: db-migrator
26+
depends_on:
27+
postgres:
28+
condition: service_healthy # Wait for DB before running
29+
environment:
30+
DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:${POSTGRES_PORT}/${POSTGRES_DB}
31+
restart: "no" # Run once, do not restart
32+
networks:
33+
- backend_network
34+
# No command override — will default to running `migration up` once
35+
2436
rust-app:
25-
image: ${BACKEND_IMAGE_NAME}
37+
image: ${BACKEND_IMAGE_NAME} # Rust backend app
2638
platform: ${PLATFORM}
2739
container_name: ${BACKEND_CONTAINER_NAME}
2840
environment:
@@ -43,13 +55,13 @@ services:
4355
ports:
4456
- "${BACKEND_PORT}:${BACKEND_PORT}"
4557
depends_on:
46-
postgres:
47-
condition: service_healthy
58+
migrator:
59+
condition: service_completed_successfully # App only runs if migrator succeeds
4860
networks:
4961
- backend_network
5062

5163
nextjs-app:
52-
image: ${FRONTEND_IMAGE_NAME}
64+
image: ${FRONTEND_IMAGE_NAME} # Next.js frontend
5365
container_name: ${FRONTEND_CONTAINER_NAME}
5466
environment:
5567
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL: ${BACKEND_SERVICE_PROTOCOL}
@@ -60,10 +72,12 @@ services:
6072
- "${FRONTEND_SERVICE_PORT}:${FRONTEND_SERVICE_PORT}"
6173
depends_on:
6274
- rust-app
75+
networks:
76+
- backend_network
77+
78+
volumes:
79+
postgres_data:
6380

6481
networks:
6582
backend_network:
6683
driver: bridge
67-
68-
volumes:
69-
postgres_data:

0 commit comments

Comments
 (0)