Skip to content

Commit

Permalink
backend/docker-compose: add pg dependency, optional persistence
Browse files Browse the repository at this point in the history
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 <thilofromm@microsoft.com>
  • Loading branch information
t-lo committed Nov 24, 2022
1 parent 0fc8c4b commit 2bc1261
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
*.swp
*sublime*
backend/__postgres_testing_volume/
8 changes: 8 additions & 0 deletions backend/docker-compose.pg-persist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Persistent postgres storage drop-in for interactive testing.
# This drop-in will persist postgres data in $(pwd)/__postgres_testing_volume
# across restarts of docker-compose.

services:
postgres:
volumes:
- ./__postgres_testing_volume:/var/lib/postgresql/data
14 changes: 14 additions & 0 deletions backend/docker-compose.test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Docker-compose file for interactive and for automated testing.
#
# Build docker image from local sources:
# docker-compose --file docker-compose.test.yaml build
#
# Run:
# docker-compose --file docker-compose.test.yaml run
# Run with persistent storage:
# docker-compose --file docker-compose.test.yaml --file docker-compose.test-db-persist.yaml up
#
# See docker-compose.pg-persist.yaml for more informatino on persistent storage.

version: "3.9"

services:
Expand All @@ -21,6 +33,8 @@ services:
context: ../
dockerfile: Dockerfile
network: host
depends_on:
- postgres
ports:
- "8002:8000"
depends_on:
Expand Down

0 comments on commit 2bc1261

Please sign in to comment.