From 4886516aa3b85b8875945219d28bb6d2927ca162 Mon Sep 17 00:00:00 2001 From: bisco Date: Wed, 24 Jun 2026 09:10:18 +0200 Subject: [PATCH] chore: rename postgres service to db --- .env.example | 2 +- README.md | 10 +++++++--- docker-compose.yml | 10 +++++++--- docs/deployment.md | 4 ++++ docs/operations.md | 4 ++-- docs/runbook.md | 2 +- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index fd2cb7f..b7e8a4d 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,7 @@ POSTGRES_DB=theatre_lab POSTGRES_USER=theatre_lab POSTGRES_PASSWORD=replace-with-a-local-password -DATABASE_URL=postgresql://theatre_lab:replace-with-a-local-password@postgres:5432/theatre_lab +DATABASE_URL=postgresql://theatre_lab:replace-with-a-local-password@db:5432/theatre_lab DJANGO_SECRET_KEY=replace-with-a-long-random-development-key DJANGO_DEBUG=true DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1,backend,azionelab.org diff --git a/README.md b/README.md index 38d2bab..056d0d6 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ stores content, and Docker Compose supplies a reproducible local environment. Italian fallback content for development when the CMS is unavailable. - `nginx/`: reverse-proxy virtual host for `azionelab.org`, routing public requests to Astro or Wagtail. -- `postgres`: persistent CMS database. +- `db`: persistent PostgreSQL database. - Docker volumes: `postgres_data` for the database and `media_data` for uploads. See [the architecture document](docs/architecture.md), @@ -91,11 +91,15 @@ The frontend reads `PUBLIC_CMS_API_URL`; inside Compose it defaults to public reverse-proxy address. Change both values for another environment. The standard published-page endpoint is also available at `/api/v2/pages/`. +The PostgreSQL service is named `db`. Existing `.env` files should replace `@postgres:` +with `@db:` in `DATABASE_URL`; a compatibility network alias keeps older local values +working during the transition. + ## Useful commands ```bash # Follow application logs -docker compose logs -f postgres backend frontend proxy +docker compose logs -f db backend frontend proxy # Run database migrations docker compose exec backend python manage.py migrate @@ -137,7 +141,7 @@ Database rows and uploaded files must be backed up together: ```bash mkdir -p backups/media docker compose stop frontend backend -docker compose exec -T postgres sh -c 'pg_dump -U "$POSTGRES_USER" "$POSTGRES_DB"' > backups/database.sql +docker compose exec -T db sh -c 'pg_dump -U "$POSTGRES_USER" "$POSTGRES_DB"' > backups/database.sql docker compose cp backend:/app/media/. backups/media/ docker compose start backend frontend ``` diff --git a/docker-compose.yml b/docker-compose.yml index 9c71e03..854d6af 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ services: - postgres: + db: image: postgres:16.9-alpine restart: unless-stopped init: true @@ -9,6 +9,10 @@ services: POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-replace-with-a-local-password} volumes: - postgres_data:/var/lib/postgresql/data + networks: + default: + aliases: + - postgres healthcheck: test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] interval: 5s @@ -24,7 +28,7 @@ services: restart: unless-stopped init: true environment: - DATABASE_URL: ${DATABASE_URL:-postgresql://theatre_lab:replace-with-a-local-password@postgres:5432/theatre_lab} + DATABASE_URL: ${DATABASE_URL:-postgresql://theatre_lab:replace-with-a-local-password@db:5432/theatre_lab} DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY:-replace-with-a-long-random-development-key} DJANGO_DEBUG: ${DJANGO_DEBUG:-true} DJANGO_ALLOWED_HOSTS: ${DJANGO_ALLOWED_HOSTS:-localhost,127.0.0.1,backend,azionelab.org} @@ -34,7 +38,7 @@ services: ports: - "127.0.0.1:8000:8000" depends_on: - postgres: + db: condition: service_healthy healthcheck: test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health/', timeout=2)"] diff --git a/docs/deployment.md b/docs/deployment.md index 2eb8273..e081b3c 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -33,6 +33,10 @@ development. `PUBLIC_CMS_API_URL` must be reachable by Astro; within Compose it is `http://backend:8000`. +The PostgreSQL Compose service is `db`, so new `DATABASE_URL` values use `db:5432`. +The internal `postgres` alias is retained only for compatibility with existing local +`.env` files and should not be used in new configuration. + The local virtual host is HTTP-only. Production must publish NGINX through the intended network interface, configure DNS for `azionelab.org`, terminate TLS, and prevent direct external access to application ports. diff --git a/docs/operations.md b/docs/operations.md index 47138d0..adff6c1 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -5,7 +5,7 @@ ```bash docker compose up --build -d docker compose ps -docker compose logs -f proxy backend frontend postgres +docker compose logs -f proxy backend frontend db docker compose down ``` @@ -33,7 +33,7 @@ Back up the database and media at the same logical point in time: ```bash mkdir -p backups/media docker compose stop frontend backend -docker compose exec -T postgres sh -c 'pg_dump -U "$POSTGRES_USER" "$POSTGRES_DB"' > backups/database.sql +docker compose exec -T db sh -c 'pg_dump -U "$POSTGRES_USER" "$POSTGRES_DB"' > backups/database.sql docker compose cp backend:/app/media/. backups/media/ docker compose start backend frontend ``` diff --git a/docs/runbook.md b/docs/runbook.md index dd626bd..3c321ba 100644 --- a/docs/runbook.md +++ b/docs/runbook.md @@ -4,7 +4,7 @@ 1. Check `docker compose ps` and the backend health status. 2. Request `http://azionelab.org:8080/api/site/home/` through NGINX. -3. Inspect `docker compose logs backend postgres`. +3. Inspect `docker compose logs backend db`. 4. Verify `PUBLIC_CMS_API_URL` resolves from the frontend container. 5. Restart the frontend after recovery so its static page is rebuilt from CMS data.