services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: matematikanusantara:latest
    container_name: matematika-app
    restart: unless-stopped
    ports:
      - "${APP_PORT:-8080}:80"
    environment:
      - APP_ENV=production
      - APP_DEBUG=false
      - APP_KEY=base64:LPDhKMFYDTCnURcHGHup2RTemplqq8FVqLFsOhVhXlQ=
      - APP_URL=http://localhost:8080
      - DB_HOST=matematika-mysql
      - DB_PORT=3306
      - DB_DATABASE=laravel
      - DB_USERNAME=laravel
      - DB_PASSWORD=password
      - REDIS_HOST=matematika-redis
      - REDIS_PORT=6379
      - REDIS_PASSWORD=password
      - CACHE_DRIVER=file
      - SESSION_DRIVER=file
      - QUEUE_CONNECTION=database
      - MAINTENANCE_DRIVER=cache
      - MAINTENANCE_STORE=redis
      - GOOGLE_CLIENT_ID=657584587617-6t62s46tflsdivfh16ruk2d9lcsebkc4.apps.googleusercontent.com
      - GOOGLE_CLIENT_SECRET=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
      - GOOGLE_REDIRECT_URI=http://localhost:8080/auth/google/callback
    volumes:
      - ./storage:/var/www/html/storage
      - app-cache:/var/www/html/bootstrap/cache
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - app-network
    healthcheck:
      test: ["CMD", "php", "artisan", "schedule:list"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  mysql:
    image: mysql:8.0
    container_name: matematika-mysql
    restart: unless-stopped
    ports:
      - "${DB_PORT:-3306}:3306"
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: laravel
      MYSQL_USER: laravel
      MYSQL_PASSWORD: password
    volumes:
      - mysql-data:/var/lib/mysql
    command: --default-authentication-plugin=mysql_native_password
    networks:
      - app-network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${DB_ROOT_PASSWORD:-rootpassword}"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: matematika-redis
    restart: unless-stopped
    ports:
      - "${REDIS_PORT:-6379}:6379"
    volumes:
      - redis-data:/data
    command: redis-server --appendonly yes --requirepass password
    networks:
      - app-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5

networks:
  app-network:
    driver: bridge

volumes:
  mysql-data:
    driver: local
  redis-data:
    driver: local
  app-cache:
    driver: local
