services:
  app:
    build:
      context: .
      target: app
    image: hoshpoint-backend-app:production
    restart: unless-stopped
    env_file:
      - ${APP_ENV_FILE:-.env.production}
    environment:
      APP_ENV: production
      APP_DEBUG: "false"
      LOG_CHANNEL: stderr
      DB_HOST: mariadb
      DB_PORT: 3306
    depends_on:
      mariadb:
        condition: service_healthy
    volumes:
      - app-storage:/var/www/html/storage
    networks:
      - hoshpoint

  nginx:
    build:
      context: .
      target: nginx
    image: hoshpoint-backend-nginx:production
    restart: unless-stopped
    depends_on:
      - app
    ports:
      - "${HTTP_PORT:-8080}:80"
    volumes:
      - app-storage:/var/www/html/storage:ro
    networks:
      - hoshpoint

  queue:
    image: hoshpoint-backend-app:production
    restart: unless-stopped
    env_file:
      - ${APP_ENV_FILE:-.env.production}
    environment:
      APP_ENV: production
      APP_DEBUG: "false"
      LOG_CHANNEL: stderr
      DB_HOST: mariadb
      DB_PORT: 3306
    command: php artisan queue:work database --sleep=3 --tries=3 --timeout=90
    depends_on:
      - app
      - mariadb
    volumes:
      - app-storage:/var/www/html/storage
    networks:
      - hoshpoint

  scheduler:
    image: hoshpoint-backend-app:production
    restart: unless-stopped
    env_file:
      - ${APP_ENV_FILE:-.env.production}
    environment:
      APP_ENV: production
      APP_DEBUG: "false"
      LOG_CHANNEL: stderr
      DB_HOST: mariadb
      DB_PORT: 3306
    command: sh -c "while true; do php artisan schedule:run --no-interaction; sleep 60; done"
    depends_on:
      - app
      - mariadb
    volumes:
      - app-storage:/var/www/html/storage
    networks:
      - hoshpoint

  mariadb:
    image: docker.arvancloud.ir/mariadb:11.4
    restart: unless-stopped
    env_file:
      - ${APP_ENV_FILE:-.env.production}
    volumes:
      - mariadb-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - hoshpoint

volumes:
  app-storage:
  mariadb-data:

networks:
  hoshpoint:
    driver: bridge
