Skip to content

Commit f1f0704

Browse files
committed
backend/docker-compose: add pg dependency, optional persistence
This change adds a dependency to the (nebraska) "server" service on the "postgres" service in docker-compose.test.yaml. Motivation of the change is to prevent a race condition where the "server" container starts faster than "postgres", fails to connect to the database, and shuts down. Additionally, an optional persistent storage for postgres is added. DB contents can be persisted across docker-compose runs to aid manual, interactive testing. Usage instructions have been added to the YAML files as comments. The local directory used for persiting postgres data has been added to .gitignore to prevent accidental commits. Signed-off-by: Thilo Fromm <[email protected]>
1 parent 0fc8c4b commit f1f0704

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
*.swp
33
*sublime*
4+
backend/__postgres_testing_volume/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Persistent postgres storage drop-in for interactive testing.
2+
# This drop-in will persist postgres data in $(pwd)/__postgres_testing_volume
3+
# across restarts of docker-compose.
4+
5+
services:
6+
postgres:
7+
volumes:
8+
- ./__postgres_testing_volume:/var/lib/postgresql/data

backend/docker-compose.test.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# Docker-compose file for interactive and for automated testing.
2+
#
3+
# Build docker image from local sources:
4+
# docker-compose --file docker-compose.test.yaml build
5+
#
6+
# Run:
7+
# docker-compose --file docker-compose.test.yaml run
8+
# Run with persistent storage:
9+
# docker-compose --file docker-compose.test.yaml --file docker-compose.test-db-persist.yaml up
10+
#
11+
# See docker-compose.pg-persist.yaml for more informatino on persistent storage.
12+
113
version: "3.9"
214

315
services:
@@ -23,6 +35,10 @@ services:
2335
network: host
2436
ports:
2537
- "8002:8000"
38+
# The "long form" depends_on silently fails in some scenarios (we've seen this with podman)
39+
# so the short form is added for compatibility.
40+
depends_on:
41+
- postgres
2642
depends_on:
2743
postgres:
2844
condition: service_healthy

0 commit comments

Comments
 (0)