Skip to content

Feat: use PostgreSQL for the database backend #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "caltrans/pems",
"dockerComposeFile": ["../compose.yml"],
"service": "dev",
"runServices": ["dev", "pgweb"],
"forwardPorts": ["docs:8000"],
"workspaceFolder": "/caltrans/app",
"postStartCommand": ["/bin/bash", "bin/reset_db.sh"],
Expand Down
8 changes: 8 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ DJANGO_STORAGE_DIR=.
DJANGO_DB_FILE=django.db
DJANGO_DB_FIXTURES="pems/local_fixtures.json"

# PostgreSQL settings
POSTGRES_HOSTNAME=postgres
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres_password
POSTGRES_PORT=5432
PGWEB_PORT=8081

# Streamlit
STREAMLIT_LOCAL_PORT=8501
# options: hidden, sidebar
Expand Down
25 changes: 25 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ services:
- ./:/caltrans/app
- ${HOME}/.aws:/home/caltrans/.aws

postgres:
image: postgres:16
environment:
- POSTGRES_DB
- POSTGRES_USER
- POSTGRES_PASSWORD
ports:
- "${POSTGRES_PORT:-5432}:5432"
volumes:
- pgdata:/var/lib/postgresql/data

pgweb:
container_name: pgweb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you grabbed this as-is from the CDRC work, but I realized there's a conflict.

If both projects have this container_name attribute, then the second one fails to come up:

$ docker compose up pgweb
[+] Running 2/2
 ✔ Container pems-postgres-1  Running                                                                                                             0.0s 
 ✘ Container pgweb            Error response from daemon: Conflict. The container name "/pgweb" is already in use by contain...                   0.0s 
Error response from daemon: Conflict. The container name "/pgweb" is already in use by container "55c3ddad7fe81c74fbbc944894685f33bdf5041399c851e8c6ab62f94ed0f0f6". You have to remove (or rename) that container to be able to reuse that name.

If I remove this line, it comes up just fine. I'll make a ticket to remove it from CDRC as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing this! Removed it in 332fb4a

image: sosedoff/pgweb
ports:
- "${PGWEB_PORT:-8081}:8081"
depends_on:
- postgres
environment:
- PGWEB_DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOSTNAME}:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable

docs:
image: caltrans/pems:dev
entrypoint: mkdocs
Expand All @@ -41,3 +62,7 @@ services:
- "${STREAMLIT_LOCAL_PORT:-8501}:8501"
volumes:
- ./:/caltrans/app

volumes:
pgdata:
driver: local