Skip to content

Commit f2b03f7

Browse files
authored
Feat: define postgres, pgweb Compose services (#3496)
2 parents 450caaf + d43d5af commit f2b03f7

3 files changed

Lines changed: 65 additions & 0 deletions

File tree

.env.sample

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ DJANGO_DB_FILE=django.db
1010
DJANGO_DB_FIXTURES="benefits/core/migrations/local_fixtures.json"
1111
# DJANGO_LOCAL_PORT=
1212

13+
# Postgres
14+
POSTGRES_HOSTNAME=postgres
15+
POSTGRES_DB=postgres
16+
POSTGRES_USER=postgres
17+
POSTGRES_PASSWORD=postgres
18+
POSTGRES_PORT=5432
19+
20+
PGWEB_PORT=8081
21+
1322
# Email sending
1423
AZURE_COMMUNICATION_CONNECTION_STRING=
1524
DEFAULT_FROM_EMAIL=noreply@example.calitp.org

compose.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,28 @@ services:
5252
- ./tests/playwright:/playwright
5353
- /tmp/.X11-unix:/tmp/.X11-unix
5454
command: ./run.sh
55+
56+
postgres:
57+
image: postgres:16
58+
environment:
59+
- POSTGRES_DB
60+
- POSTGRES_USER
61+
- POSTGRES_PASSWORD
62+
ports:
63+
- "${POSTGRES_PORT:-5432}:5432"
64+
volumes:
65+
- pgdata:/var/lib/postgresql/data
66+
67+
pgweb:
68+
container_name: pgweb
69+
image: sosedoff/pgweb
70+
ports:
71+
- "${PGWEB_PORT:-8081}:8081"
72+
depends_on:
73+
- postgres
74+
environment:
75+
- PGWEB_DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOSTNAME}:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable
76+
77+
volumes:
78+
pgdata:
79+
driver: local

docs/reference/environment-variables.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,36 @@ Comma-separated list of URIs. Configures the [`script-src`][mdn-csp-script-src]
310310

311311
Comma-separated list of URIs. Configures the [`style-src`][mdn-csp-style-src] Content Security Policy directive.
312312

313+
## PostgreSQL
314+
315+
!!! tldr "`postgres` Docker image docs"
316+
317+
The official PostgreSQL Docker image has more on available [`postgres` environment variables][postgres]
318+
319+
### `PGWEB_PORT`
320+
321+
The port to serve a (local only) [`pgweb`](https://sosedoff.github.io/pgweb/) service on.
322+
323+
### `POSTGRES_DB`
324+
325+
Used to define a different name for the default database that is created when the image is first started. If it is not specified, then the value of [`POSTGRES_USER`](#postgres_user) will be used.
326+
327+
### `POSTGRES_HOSTNAME`
328+
329+
The hostname of the (local) PostgreSQL Docker service, which is usually just the name of the service itself (`postgres`). Used by e.g. `pgweb` to establish a connection. Or the hostname of a cloud-based PostgreSQL service for e.g. Django to establish a connection.
330+
331+
### `POSTGRES_PASSWORD`
332+
333+
Required to use the (local) PostgreSQL Docker service. It must not be empty or undefined. This environment variable sets the superuser password for PostgreSQL.
334+
335+
### `POSTGRES_PORT`
336+
337+
The port exposed by the (local) PostgreSQL Docker service. Or the port on which to connect to a cloud-based PostgreSQL service.
338+
339+
### `POSTGRES_USER`
340+
341+
Used in conjunction with [`POSTGRES_PASSWORD`](#postgres_password) to set a user and its password. This variable will create the specified user with superuser power.
342+
313343
## reCAPTCHA
314344

315345
!!! tldr "reCAPTCHA docs"
@@ -413,6 +443,7 @@ The default is `0.0` (i.e. no transactions are tracked).
413443
[mdn-csp-frame-src]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-src
414444
[mdn-csp-script-src]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
415445
[mdn-csp-style-src]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src
446+
[postgres]: https://hub.docker.com/_/postgres/#environment-variables
416447
[recaptcha]: https://developers.google.com/recaptcha
417448
[recaptcha-intro]: https://developers.google.com/recaptcha/intro
418449
[recaptcha-verify]: https://developers.google.com/recaptcha/docs/verify

0 commit comments

Comments
 (0)