services:
  app:
    build:
      context: .
      args:
        VITE_REVERB_APP_KEY: ${REVERB_APP_KEY}
        VITE_REVERB_HOST: ${VITE_REVERB_HOST}
        VITE_REVERB_PORT: ${VITE_REVERB_PORT}
        VITE_REVERB_SCHEME: ${VITE_REVERB_SCHEME}
    ports:
      - "80"
    environment:
      APP_ENV: production
      APP_DEBUG: "false"
      APP_KEY: ${APP_KEY}
      APP_URL: ${APP_URL}
      DB_HOST: db
      DB_PORT: "3306"
      DB_DATABASE: ${DB_DATABASE}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
      BROADCAST_CONNECTION: reverb
      REVERB_APP_ID: ${REVERB_APP_ID}
      REVERB_APP_KEY: ${REVERB_APP_KEY}
      REVERB_APP_SECRET: ${REVERB_APP_SECRET}
      REVERB_HOST: 0.0.0.0
      REVERB_PORT: "8080"
      REVERB_SCHEME: http
      SESSION_DRIVER: database
      SESSION_LIFETIME: "120"
      QUEUE_CONNECTION: database
      STRAVA_CLIENT_ID: ${STRAVA_CLIENT_ID}
      STRAVA_CLIENT_SECRET: ${STRAVA_CLIENT_SECRET}
      STRAVA_REDIRECT_URI: ${APP_URL}/strava/callback
    depends_on:
      db:
        condition: service_healthy
    volumes:
      - aigo-storage:/var/www/aigo/storage

  reverb:
    build:
      context: .
      args:
        VITE_REVERB_APP_KEY: ${REVERB_APP_KEY}
        VITE_REVERB_HOST: ${VITE_REVERB_HOST}
        VITE_REVERB_PORT: ${VITE_REVERB_PORT}
        VITE_REVERB_SCHEME: ${VITE_REVERB_SCHEME}
    ports:
      - "8080"
    environment:
      APP_ENV: production
      APP_DEBUG: "false"
      APP_KEY: ${APP_KEY}
      APP_URL: ${APP_URL}
      DB_HOST: db
      DB_PORT: "3306"
      DB_DATABASE: ${DB_DATABASE}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
      BROADCAST_CONNECTION: reverb
      REVERB_APP_ID: ${REVERB_APP_ID}
      REVERB_APP_KEY: ${REVERB_APP_KEY}
      REVERB_APP_SECRET: ${REVERB_APP_SECRET}
      REVERB_HOST: 0.0.0.0
      REVERB_PORT: "8080"
      REVERB_SCHEME: http
      SESSION_DRIVER: database
      QUEUE_CONNECTION: database
    command: php artisan reverb:start --host=0.0.0.0 --port=8080
    depends_on:
      db:
        condition: service_healthy
    volumes:
      - aigo-storage:/var/www/aigo/storage

  queue:
    build:
      context: .
      args:
        VITE_REVERB_APP_KEY: ${REVERB_APP_KEY}
        VITE_REVERB_HOST: ${VITE_REVERB_HOST}
        VITE_REVERB_PORT: ${VITE_REVERB_PORT}
        VITE_REVERB_SCHEME: ${VITE_REVERB_SCHEME}
    environment:
      APP_ENV: production
      APP_DEBUG: "false"
      APP_KEY: ${APP_KEY}
      APP_URL: ${APP_URL}
      DB_HOST: db
      DB_PORT: "3306"
      DB_DATABASE: ${DB_DATABASE}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
      BROADCAST_CONNECTION: reverb
      REVERB_APP_ID: ${REVERB_APP_ID}
      REVERB_APP_KEY: ${REVERB_APP_KEY}
      REVERB_APP_SECRET: ${REVERB_APP_SECRET}
      REVERB_HOST: 0.0.0.0
      REVERB_PORT: "8080"
      REVERB_SCHEME: http
      SESSION_DRIVER: database
      QUEUE_CONNECTION: database
    command: php artisan queue:work
    depends_on:
      db:
        condition: service_healthy
    volumes:
      - aigo-storage:/var/www/aigo/storage

  db:
    image: mysql:8.0
    ports:
      - "3306"
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    volumes:
      - dbdata:/var/lib/mysql
      - ./humicpro_aigo.sql:/docker-entrypoint-initdb.d/01-import.sql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 5s
      timeout: 3s
      retries: 10
      start_period: 30s

volumes:
  dbdata:
  aigo-storage:
