services:
  api-prod:
    build: .
    restart: unless-stopped
    container_name: rhythm-api-prod
    ports:
      - "8080:8080"
    environment:
      DB_HOST: db-prod
    env_file:
      - ".env"
    depends_on:
      db-prod:
        condition: service_healthy
    profiles:
      - prod

  db-prod:
    image: postgres:18.0-alpine
    restart: unless-stopped
    container_name: rhythm-db-prod
    ports:
      - "${DB_PORT_PROD:-5433}:5432"
    environment:
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: ${DB_NAME}
    volumes:
      - ./.data/postgres-prod:/var/lib/postgresql/data
    profiles:
      - prod
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME} -d ${DB_NAME}"]
      interval: 5s
      timeout: 3s
      retries: 10

  db-dev:
    image: postgres:18.0-alpine
    restart: unless-stopped
    container_name: rhythm-db-dev
    ports:
      - "${DB_PORT}:5432"
    environment:
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: ${DB_NAME}
    profiles:
      - dev
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME} -d ${DB_NAME}"]
      interval: 5s
      timeout: 3s
      retries: 10

volumes:
  postgres_data:
