-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
79 lines (79 loc) · 3.45 KB
/
Copy pathdocker-compose.yml
File metadata and controls
79 lines (79 loc) · 3.45 KB
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
services:
db:
image: "${POSTGRES_IMAGE:-postgres}" # Can be set in rebuildanddeploy.sh, or defaults to: https://hub.docker.com/_/postgres
restart: always
ports:
- '127.0.0.1:8623:5432'
environment:
- POSTGRES_DB=makeability
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=password
volumes:
- db-data:/var/lib/postgresql/data
# Consistent daily pg_dump into the postgres data volume (#1443). CSE IT's
# ZFS snapshots capture the raw volume, which is only *probably* restorable
# for a live database; this writes a guaranteed-consistent restore point
# inside that same volume so every snapshot carries one. See docs/BACKUPS.md.
#
# Uses the same image as `db` so pg_dump's version always matches the server.
# `entrypoint` MUST stay overridden: the postgres image's own entrypoint would
# otherwise try to bring up a second server on this PGDATA.
#
# The scheduling loop lives here rather than inside pg_backup.sh on purpose —
# `docker compose up -d` only recreates a container whose config changed, so a
# loop inside the bind-mounted script would keep running the old code forever
# after a deploy. Re-invoking the script each pass makes logic changes deploy.
#
# The `sleep ... & wait $!` (rather than a plain foreground `sleep`) and the
# leading `trap` are so `docker compose stop`/`down` return promptly: bash
# only acts on a trapped signal between foreground commands, so with a plain
# `sleep 3600` a SIGTERM sent while idle would sit unhandled for up to an
# hour and this container would always eat the full stop grace period before
# Docker escalates to SIGKILL. Backgrounding the sleep and `wait`-ing on it
# makes the trap run immediately instead.
db-backup:
image: "${POSTGRES_IMAGE:-postgres}"
restart: always
environment:
- PGHOST=db
- PGUSER=admin
- PGPASSWORD=password
- PGDATABASE=makeability
- BACKUP_RETENTION_DAYS=${BACKUP_RETENTION_DAYS:-14}
- BACKUP_POLL_SECONDS=${BACKUP_POLL_SECONDS:-3600}
- BACKUP_RETRY_SECONDS=${BACKUP_RETRY_SECONDS:-300}
volumes:
- db-data:/var/lib/postgresql/data
- backup-status:/var/backup-status
- ./scripts:/backup-scripts:ro
entrypoint: ["/bin/bash", "-c", "trap 'exit 0' TERM INT; while true; do if bash /backup-scripts/pg_backup.sh; then sleep \"$${BACKUP_POLL_SECONDS}\" & wait $!; else sleep \"$${BACKUP_RETRY_SECONDS}\" & wait $!; fi; done"]
depends_on:
- db
website:
environment:
- DJANGO_ENV=${DJANGO_ENV:-TEST}
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- '127.0.0.1:8571:8000'
volumes:
- .:/code
- ${MEDIA_PATH:-./media}:/code/media
- ${CONFIG_PATH:-./config-dev.ini}:/code/config.ini # for loading vars into ConfigParser in Django
- backup-status:/var/backup-status:ro # read-only: Django reports backup health (#1443)
depends_on:
- db
command: ["./docker-entrypoint.sh", "db", "python", "manage.py"]
links:
- "db:database"
volumes:
db-data:
external: true
name: "makeabilitylabcswashingtonedu_${POSTGRES_VOLUME:-postgres-data}"
# Holds only the backup status.json that Django reads to report backup health.
# Intentionally NOT external and NOT something CSE IT needs to back up: it is
# disposable state, regenerated on the next backup pass. The dumps themselves
# live in db-data above, which is the volume that gets snapshotted.
backup-status: