id: postgres
category: service
displayName: PostgreSQL
description: 'Relational database with seeded dev credentials and a readiness healthcheck. Reachable in-container as host `postgres`.'
service:
  image: postgres:18
  defaultPort: 5432
  dataMount: /var/lib/postgresql
  healthcheck:
    test: [CMD, pg_isready, -U, '${POSTGRES_USER}', -d, '${POSTGRES_DB}']
    interval: 10s
    timeout: 5s
    retries: 5
  vscodeExtensions: [cweijan.vscode-database-client2]
  client:
    apt: [postgresql-client]
  connectionEnv:
    URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${host}:${port}/${POSTGRES_DB}
    HOST: ${host}
    PORT: ${port}
    USER: ${POSTGRES_USER}
    PASSWORD: ${POSTGRES_PASSWORD}
    DB: ${POSTGRES_DB}
options:
  POSTGRES_USER:
    type: string
    default: monoceros
    surface: env
  POSTGRES_PASSWORD:
    type: string
    default: monoceros
    surface: env
  POSTGRES_DB:
    type: string
    default: monoceros
    surface: env
# The service block for the project's pipeline compose file, verbatim.
deploy:
  compose: |-
    image: postgres:18
    environment:
      POSTGRES_USER: ${POSTGRES_USER:?set it as a pipeline secret}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set it as a pipeline secret}
      POSTGRES_DB: ${POSTGRES_DB:?set it as a pipeline secret}
    healthcheck:
      # -h checks over TCP; on the unix socket pg_isready answers during init.
      test: [CMD, pg_isready, -h, 127.0.0.1, -U, "${POSTGRES_USER}", -d, "${POSTGRES_DB}"]
      interval: 5s
      timeout: 5s
      retries: 20
    # No volume: each run starts empty, the schema comes from the project's migrations.
