# compose.yml
# Compose base 
name: ${COMPOSE_PROJECT_NAME:-suitecoffee}

services:

  app:
    depends_on:
      db:
        condition: service_healthy
      tenants:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://localhost:${APP_DOCKER_PORT}/health || exit 1"]
      interval: 10s
      timeout: 3s
      retries: 10
      start_period: 20s
    restart: unless-stopped

  auth:
    depends_on:
      db:
        condition: service_healthy
      authentik:
        condition: service_started
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://localhost:${AUTH_DOCKER_PORT}/health || exit 1"]
      interval: 10s
      timeout: 3s
      retries: 10
      start_period: 15s
    restart: unless-stopped

  db:
    image: postgres:16
    environment:
      TZ: America/Montevideo
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
      interval: 5s
      timeout: 3s
      retries: 20
      start_period: 10s
    restart: unless-stopped

  tenants:
    image: postgres:16
    environment:
      TZ: America/Montevideo
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${TENANTS_DB_USER} -d ${TENANTS_DB_NAME}"]
      interval: 5s
      timeout: 3s
      retries: 20
      start_period: 10s
    restart: unless-stopped

  authentik-db:
    image: postgres:16-alpine
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U authentik -d authentik"]
      interval: 5s
      timeout: 3s
      retries: 20
    restart: unless-stopped

  authentik-redis:
    image: redis:7-alpine
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 20
    restart: unless-stopped

  authentik:
    image: ghcr.io/goauthentik/server:latest
    depends_on:
      authentik-db:    { condition: service_healthy }
      authentik-redis: { condition: service_healthy }
    restart: unless-stopped

  authentik-worker:
    image: ghcr.io/goauthentik/server:latest
    restart: unless-stopped
    