# Docker Compose for CI / local E2E testing.
# Provides the minimum set of services required to run the full E2E suite.
#
# Default ports are offset from dev defaults to avoid conflicts with
# existing development containers. Override via environment or .env.ci.
#
# Usage (local):
#   docker compose --env-file .env.ci -f docker-compose.ci.yml up -d --wait
#   source .env.test   # load matching env vars
#   pnpm db:generate && pnpm db:migrate:deploy && pnpm db:seed
#   pnpm test:e2e
#   docker compose --env-file .env.ci -f docker-compose.ci.yml down -v
#
# Usage (GitHub Actions):
#   Services are defined inline in .github/workflows/e2e.yml using
#   standard GH Actions service containers (ports 5432/6379/8108/9000).

services:
  postgres:
    image: postgis/postgis:16-3.4
    container_name: goodgo-ci-postgres
    ports:
      - '${DB_PORT:-5433}:5432'
    environment:
      POSTGRES_DB: goodgo_test
      POSTGRES_USER: goodgo
      POSTGRES_PASSWORD: goodgo_test_secret
    tmpfs:
      - /var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U goodgo -d goodgo_test']
      interval: 5s
      timeout: 3s
      retries: 10
      start_period: 10s
    networks:
      - goodgo-ci

  redis:
    image: redis:7-alpine
    container_name: goodgo-ci-redis
    ports:
      - '${REDIS_PORT:-6380}:6379'
    command: redis-server --save "" --appendonly no
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 5s
      timeout: 3s
      retries: 10
    networks:
      - goodgo-ci

  typesense:
    image: typesense/typesense:27.1
    container_name: goodgo-ci-typesense
    ports:
      - '${TYPESENSE_PORT:-8109}:8108'
    environment:
      TYPESENSE_API_KEY: ts_ci_key
      TYPESENSE_DATA_DIR: /data
    tmpfs:
      - /data
    healthcheck:
      test: ['CMD-SHELL', 'bash -c "echo > /dev/tcp/localhost/8108"']
      interval: 5s
      timeout: 3s
      retries: 10
      start_period: 10s
    networks:
      - goodgo-ci

  minio:
    image: minio/minio:latest
    container_name: goodgo-ci-minio
    ports:
      - '${MINIO_PORT:-9002}:9000'
    command: server /data
    environment:
      MINIO_ROOT_USER: ci_minio_user
      MINIO_ROOT_PASSWORD: ci_minio_secret_key_32chars!!
    tmpfs:
      - /data
    healthcheck:
      test: ['CMD', 'curl', '-sf', 'http://localhost:9000/minio/health/live']
      interval: 5s
      timeout: 3s
      retries: 10
      start_period: 5s
    networks:
      - goodgo-ci

networks:
  goodgo-ci:
    driver: bridge
    name: goodgo-ci
