# Docker Compose setup for integration tests.
# Each vitest worker gets its own dedicated database service.
# Adjust the number of database-N services to match VITEST_WORKERS.

x-database: &database
  image: postgres:17-alpine
  environment:
    POSTGRES_PASSWORD: postgres
    POSTGRES_DB: songwhip_presaves
  healthcheck:
    test: ["CMD-SHELL", "pg_isready -U postgres"]
    interval: 2s
    timeout: 5s
    retries: 10

services:
  database-1:
    <<: *database

  database-2:
    <<: *database

  database-3:
    <<: *database

  database-4:
    <<: *database

  test-runner:
    build:
      context: ../..
      target: development
      secrets:
        - GITHUB_NPM_TOKEN
    depends_on:
      database-1:
        condition: service_healthy
      database-2:
        condition: service_healthy
      database-3:
        condition: service_healthy
      database-4:
        condition: service_healthy
    environment:
      - VITEST_WORKERS=4
      - VITEST_RETRY=1
      - COMPOSE_MODE=true
      # Overrides from .env.test that need different values in compose
      - PRESAVES_DB_USER=postgres
      - PRESAVES_DB_PASSWORD=postgres
      - PRESAVES_DB_NAME=songwhip_presaves
      - PRESAVES_DB_SSL=false
    env_file:
      - .env.test
    command: ["pnpm", "test:integration"]

secrets:
  GITHUB_NPM_TOKEN:
    environment: GITHUB_NPM_TOKEN
