# Production compose for CA Lab Studio. # Usage: docker compose -f docker-compose.prod.yml --env-file .env.prod up -d --build # # This stack is independent of gnommoweb. It joins the shared `gnommo` # external network to reach gnommo-db (Postgres) and to be reachable by the # shared nginx (gu_common) which proxies lab.${DOMAIN} → gnommo-lab:3100. # # Required env vars (load via .env.prod on the server): # POSTGRES_USER, POSTGRES_PASSWORD — credentials for gnommo-db (shared) # LAB_DB (optional) — database name within gnommo-db (default: ca_studio) services: # Idempotently ensures the ca_studio database + pgcrypto extension exist on # the shared gnommo-db Postgres before the lab service starts. lab-db-init: image: postgres:16-alpine restart: "no" environment: PGUSER: ${POSTGRES_USER} PGPASSWORD: ${POSTGRES_PASSWORD} PGHOST: gnommo-db PGPORT: "5432" LAB_DB: ${LAB_DB:-ca_studio} entrypoint: > /bin/sh -c " until pg_isready -h gnommo-db -U $${PGUSER}; do echo 'Waiting for gnommo-db...'; sleep 2; done; psql -d postgres -tAc \"SELECT 1 FROM pg_database WHERE datname='$${LAB_DB}'\" | grep -q 1 || psql -d postgres -c \"CREATE DATABASE $${LAB_DB};\"; psql -d $${LAB_DB} -c 'CREATE EXTENSION IF NOT EXISTS pgcrypto;'; echo 'Lab DB: ready.' " networks: - gnommo lab: build: context: . dockerfile: Dockerfile container_name: gnommo-lab restart: unless-stopped environment: NODE_ENV: production PORT: "3100" DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@gnommo-db:5432/${LAB_DB:-ca_studio} # Run pending migrations before starting the server. # The lab's migrate script is idempotent (CREATE TABLE IF NOT EXISTS). command: sh -c "node scripts/migrate.mjs && node dist/server.js" expose: - "3100" depends_on: lab-db-init: condition: service_completed_successfully networks: - default - gnommo networks: default: {} gnommo: external: true