services:
  votc:
    build: .
    container_name: votc
    restart: unless-stopped
    environment:
      - DATABASE_URL=postgresql://votc:${POSTGRES_PASSWORD}@votc-db:5432/votc
      - INFISICAL_CLIENT_ID=${INFISICAL_CLIENT_ID}
      - INFISICAL_CLIENT_SECRET=${INFISICAL_CLIENT_SECRET}
      - INFISICAL_PROJECT_SLUG=valley-commons
      - LISTMONK_DB_HOST=listmonk-db
      - LISTMONK_DB_PORT=5432
      - LISTMONK_DB_NAME=listmonk
      - LISTMONK_DB_USER=listmonk
      - LISTMONK_DB_PASS=${LISTMONK_DB_PASS:-listmonk_secure_2025}
      - LISTMONK_LIST_ID=24
      - MOLLIE_API_KEY=${MOLLIE_API_KEY}
      - SMTP_HOST=mail.rmail.online
      - SMTP_PORT=587
      - SMTP_USER=contact@valleyofthecommons.com
      - SMTP_PASS=${SMTP_PASS}
      - EMAIL_FROM=Valley of the Commons <contact@valleyofthecommons.com>
    depends_on:
      votc-db:
        condition: service_healthy
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.votc.rule=Host(`valleyofthecommons.com`) || Host(`www.valleyofthecommons.com`) || Host(`votc.jeffemmett.com`)"
      - "traefik.http.services.votc.loadbalancer.server.port=3000"
    networks:
      - traefik-public
      - listmonk-internal

  votc-sponsorship-staging:
    build: ./staging/sponsorships
    container_name: votc-sponsorship-staging
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.votc-sponsorship-staging.rule=Host(`votc-sponsorship-staging.jeffemmett.com`)"
      - "traefik.http.services.votc-sponsorship-staging.loadbalancer.server.port=80"
    networks:
      - traefik-public

  votc-db:
    image: postgres:16-alpine
    container_name: votc-db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=votc
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=votc
    volumes:
      - votc-postgres-data:/var/lib/postgresql/data
      - ./db/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U votc"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - traefik-public

volumes:
  votc-postgres-data:

networks:
  traefik-public:
    external: true
  listmonk-internal:
    external:
      name: listmonk_listmonk-internal
