name: sharelens

x-sharelens: &sharelens
  image: ${APP_IMAGE:-ghcr.io/ulooocom/sharelens:v11}
  pull_policy: ${PULL_POLICY:-missing}
  restart: unless-stopped
  env_file: .env
  volumes:
    - ./app_storage:/var/www/html/storage
    - ./logs/app:/var/www/html/storage/logs
    - ./logs/nginx:/var/log/nginx
    - ./backups:/var/www/html/storage/app/private/backups
    - ./uploads:/var/www/html/storage/app/public

services:
  mysql:
    image: ${MYSQL_IMAGE:-ghcr.io/ulooocom/sharelens:mysql-8.4}
    pull_policy: ${PULL_POLICY:-missing}
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE:-sharelens}
      MYSQL_USER: ${DB_USERNAME:-sharelens}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - ./mysql_data:/var/lib/mysql
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --disable-log-bin
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -uroot -p\"$$MYSQL_ROOT_PASSWORD\" || exit 1"]
      interval: 5s
      timeout: 5s
      retries: 20
      start_period: 20s

  redis:
    image: ${REDIS_IMAGE:-ghcr.io/ulooocom/sharelens:redis-7.4}
    pull_policy: ${PULL_POLICY:-missing}
    restart: unless-stopped
    command: redis-server --appendonly no --save ""
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 10
      start_period: 5s

  app:
    <<: *sharelens
    environment:
      RUN_MIGRATIONS: "true"
    ports:
      - "${APP_PORT:-8080}:80"
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy

  queue:
    <<: *sharelens
    environment:
      RUN_MIGRATIONS: "false"
    command: php artisan queue:work redis --sleep=1 --tries=3 --timeout=120 --max-time=3600
    healthcheck:
      test: ["CMD-SHELL", "pgrep -f 'artisan queue:work' >/dev/null || exit 1"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 20s
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
      app:
        condition: service_healthy

  scheduler:
    <<: *sharelens
    environment:
      RUN_MIGRATIONS: "false"
    command: php artisan schedule:work
    healthcheck:
      test: ["CMD-SHELL", "pgrep -f 'artisan schedule:work' >/dev/null || exit 1"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 20s
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
      app:
        condition: service_healthy
