# All EAGLECAST_* env variables also support the EAGLECAST_*_FILE pattern for loading secrets from files with Docker secrets and Podman
# eg: EAGLECAST_ADMIN_USER -> EAGLECAST_ADMIN_USER_FILE=/path/to/file_with_value

x-db-credentials: &db-credentials                             # Use the default POSTGRES_ credentials if they're available or simply default to "eaglecast"
  POSTGRES_USER: &db-user eaglecast                            # for database user, password, and database name
  POSTGRES_PASSWORD: &db-password eaglecast
  POSTGRES_DB: &db-name eaglecast

services:
  # eaglecast app
  app:
    image: eaglecast:latest
    container_name: eaglecast_app
    restart: unless-stopped
    ports:
      - "9000:9000"                                           # To change the externally exposed port, change to: $custom_port:9000
    networks:
      - eaglecast
    hostname: eaglecast.example.com                            # Recommend using FQDN for hostname
    depends_on:
      - db
    command: [sh, -c, "./eaglecast --install --idempotent --yes --config '' && ./eaglecast --upgrade --yes --config '' && ./eaglecast --config ''"]
                                                              # --config (file) param is set to empty so that eaglecast only uses the env vars (below) for config.
                                                              # --install --idempotent ensures that DB installation happens only once on an empty DB, on the first ever start.
                                                              # --upgrade automatically runs any DB migrations when a new image is pulled.

    environment:                                              # The same params as in config.toml are passed as env vars here.
      EAGLECAST_app__address: 0.0.0.0:9000
      EAGLECAST_db__user: *db-user
      EAGLECAST_db__password: *db-password
      EAGLECAST_db__database: *db-name
      EAGLECAST_db__host: db
      EAGLECAST_db__port: 5432
      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:-}           # If these (optional) are set during the first `docker compose up`, then the Super Admin user is automatically created.
      EAGLECAST_ADMIN_PASSWORD: ${EAGLECAST_ADMIN_PASSWORD:-}   # Otherwise, the user can be setup on the web app after the first visit to http://localhost:9000
    volumes:
      - ./uploads:/eaglecast/uploads:rw                        # Mount an uploads directory on the host to /eaglecast/uploads inside the container.
                                                              # To use this, change directory path in Admin -> Settings -> Media to /eaglecast/uploads

  # Postgres database
  db:
    image: postgres:17-alpine
    container_name: eaglecast_db
    restart: unless-stopped
    ports:
      - "127.0.0.1:5432:5432"                                 # Only bind on the local interface. To connect to Postgres externally, change this to 0.0.0.0
    networks:
      - eaglecast
    environment:
      <<: *db-credentials
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U eaglecast"]
      interval: 10s
      timeout: 5s
      retries: 6
    volumes:
      - type: volume
        source: eaglecast-data
        target: /var/lib/postgresql/data

networks:
  eaglecast:

volumes:
  eaglecast-data:
