services:
  # The "entrypoint" into the application. This reverse proxy
  # proxies traffic back to their respective services. If not
  # running behind a reverse proxy inject your SSL certificates
  # into this container.
  # This container runs the actual web app in a php:8.4-fpm
  # base container.
  app:
    image: code.caldwell.digital/home/torsearch-app:latest
    ports:
      - '8006:80'
    env_file:
      - .env
    depends_on:
      database:
        condition: service_healthy

  # Downloads happen in this container. Replicate this
  # container to run multiple downloads simultaneously.
  # Map your "movies" folder to /var/download/movies
  # Map your "TV shows" folder to /var/download/tvshows
  # If your folders are on another machine, use an NFS volume.
  # This container runs a Symfony worker process.
  # See: https://symfony.com/doc/current/messenger.html
  worker:
    image: code.caldwell.digital/home/torsearch-worker:latest
    volumes:
      - /mnt/media/downloads/movies:/var/download/movies
      - /mnt/media/downloads/tvshows:/var/download/tvshows
    command: -vvv
    env_file:
      - .env
    restart: always
    depends_on:
      app:
        condition: service_healthy

  # This container handles the monitoring for new media. When new
  # monitors are added, jobs are periodically dispatched to this
  # container, and the desired media is searched for and downloaded.
  # This container runs a Symfony worker process.
  # See: https://symfony.com/doc/current/messenger.html
  scheduler:
    image: code.caldwell.digital/home/torsearch-scheduler:latest
    volumes:
      - ./downloads:/var/download
    env_file:
      - .env
    restart: always
    depends_on:
      app:
        condition: service_healthy

  # This container facilitates viewing the progress of downloads
  # in realtime. It also handles sending alerts and notifications.
  # The MERCURE_PUBLISHER_JWT key & MERCURE_SUBSCRIBER_JWT_KEY should
  # match the MERCURE_JWT_SECRET environment variable.
  mercure:
    image: dunglas/mercure
    restart: unless-stopped
    ports:
      - "3001:80"
    environment:
      SERVER_NAME: ':80'
      MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
      MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
      MERCURE_EXTRA_DIRECTIVES: |
        cors_origins *
        anonymous
    command: /usr/bin/caddy run --config /etc/caddy/dev.Caddyfile
    volumes:
      - mercure_data:/data
      - mercure_config:/config

  database:
    image: mariadb:10.11.2
    volumes:
      - mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: app
      MYSQL_USERNAME: app
      MYSQL_PASSWORD: password
      MYSQL_ROOT_PASSWORD: password
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
      interval: 5s
      timeout: 5s
      retries: 10

  redis:
    image: redis:latest
    volumes:
      - redis_data:/data
    command: redis-server --maxmemory 512MB
    restart: unless-stopped

  # **Optional**
  # Provides a simple method of viewing the database
  adminer:
    image: adminer
    ports:
      - "8081:8080"

volumes:
  mysql:
  mercure_config:
  mercure_data:
  redis_data:
