# Coolify deployment for EagleCast.
#
# In Coolify: create a new resource -> Docker Compose -> point it at this
# repository and set "Docker Compose Location" to /docker-compose.coolify.yml.
# Coolify generates the database password automatically via the
# $SERVICE_PASSWORD_EAGLECASTDB magic variable below. Set the public domain on
# the eaglecast service in Coolify's UI (e.g. https://cast.example.com:9000 —
# the port picks the container port). TLS and the reverse proxy are handled by
# Coolify's own proxy, so no ports are published here.
#
# Optional: set EAGLECAST_ADMIN_USER / EAGLECAST_ADMIN_PASSWORD in the
# Coolify environment variables UI before the first deploy to auto-create the
# Super Admin. Otherwise, visit the app after deploy to create it.
#
# After the first login, set the root URL in Admin -> Settings -> General to
# your public https:// domain so links in e-mails point at the right host.

services:
  eaglecast:
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    environment:
      - EAGLECAST_app__address=0.0.0.0:9000
      - EAGLECAST_db__host=db
      - EAGLECAST_db__port=5432
      - EAGLECAST_db__user=eaglecast
      - EAGLECAST_db__password=$SERVICE_PASSWORD_EAGLECASTDB
      - EAGLECAST_db__database=eaglecast
      - EAGLECAST_db__ssl_mode=disable
      - EAGLECAST_db__max_open=25
      - EAGLECAST_db__max_idle=25
      - EAGLECAST_db__max_lifetime=300s
      - TZ=Etc/UTC
      - EAGLECAST_ADMIN_USER=${EAGLECAST_ADMIN_USER:-}
      - EAGLECAST_ADMIN_PASSWORD=${EAGLECAST_ADMIN_PASSWORD:-}
    command: [sh, -c, "./eaglecast --install --idempotent --yes --config '' && ./eaglecast --upgrade --yes --config '' && ./eaglecast --config ''"]
    depends_on:
      db:
        condition: service_healthy
    volumes:
      - eaglecast-uploads:/eaglecast/uploads
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://127.0.0.1:9000/health"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 30s

  db:
    image: postgres:17-alpine
    restart: unless-stopped
    environment:
      - POSTGRES_USER=eaglecast
      - POSTGRES_PASSWORD=$SERVICE_PASSWORD_EAGLECASTDB
      - POSTGRES_DB=eaglecast
    volumes:
      - eaglecast-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U eaglecast"]
      interval: 10s
      timeout: 5s
      retries: 6

volumes:
  eaglecast-data:
  eaglecast-uploads:
