# This file is used for local development
# see the docs/examples directory for production examples
services:
  caddy:
    image: caddy:2.9.1
    restart: unless-stopped
    tty: true
    cap_add:
      - NET_ADMIN
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - $PWD/bash/caddy:/etc/caddy
      - $PWD/bash/certs:/etc/ssl


  app:
    build: .
    restart: unless-stopped
    volumes:
      - $PWD:/app
      - $PWD/var/download:/var/download
      - mercure_data:/data
      - mercure_config:/config
    tty: true
    environment:
      TZ: America/Chicago
      MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
      MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
    depends_on:
      database:
        condition: service_healthy


  worker:
    build:
      dockerfile: docker/Dockerfile.worker
      context: .
    restart: unless-stopped
    volumes:
      - $PWD:/app
      - $PWD/var/download:/var/download
    tty: true
    environment:
      TZ: America/Chicago


  scheduler:
    build:
      dockerfile: docker/Dockerfile.scheduler
      context: .
    restart: unless-stopped
    volumes:
      - $PWD:/app
      - $PWD/var/download:/var/download
    tty: true
    environment:
      TZ: America/Chicago
      WORKER_MONITOR: 2


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


  database:
    image: mariadb:10.11.2
    ports:
      - "3306:3306"
    volumes:
      - mysql:/var/lib/mysql
    environment:
      TZ: America/Chicago
      MYSQL_DATABASE: app
      MYSQL_USER: app
      MYSQL_PASSWORD: password
      MYSQL_RANDOM_ROOT_PASSWORD: true
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
      interval: 5s
      timeout: 5s
      retries: 10


  adminer:
    image: adminer
    ports:
      - "8081:8080"
    environment:
      ADMINER_DEFAULT_SERVER: database


volumes:
  mysql:
  mercure_data:
  mercure_config:
  redis_data:
