services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: laravel-app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - storage-data:/var/www/storage
    networks:
      - app-network
    depends_on:
      db:
        condition: service_healthy
    environment:
      - DB_CONNECTION=mysql
      - DB_HOST=db
      - DB_PORT=3306
      - DB_DATABASE=e_commerce_mid
      - DB_USERNAME=laravel
      - DB_PASSWORD=laravel_secret
      - MIDTRANS_IS_PRODUCTION=${MIDTRANS_IS_PRODUCTION:-false}
      - MIDTRANS_MERCHANT_ID=${MIDTRANS_MERCHANT_ID:-G974346280}
      - MIDTRANS_CLIENT_KEY=${MIDTRANS_CLIENT_KEY:-Mid-client-YSIWmfBYxmNRUxXd}
      - MIDTRANS_SERVER_KEY=${MIDTRANS_SERVER_KEY:-Mid-server-4OInwKCMavUFW6tE_82G3O2Z}

  web:
    image: nginx:alpine
    container_name: laravel-web
    restart: unless-stopped
    ports:
      - "${APP_PORT:-8000}:80"
    volumes:
      - ./:/var/www
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    networks:
      - app-network
    depends_on:
      - app

  db:
    image: mariadb:10.11
    container_name: laravel-db
    restart: unless-stopped
    environment:
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-root_secret}
      MARIADB_DATABASE: e_commerce_mid
      MARIADB_USER: laravel
      MARIADB_PASSWORD: ${DB_PASSWORD:-laravel_secret}
    ports:
      - "${DB_PORT:-3307}:3306"
    volumes:
      - db-data:/var/lib/mysql
    networks:
      - app-network
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  db-data:
  storage-data:

networks:
  app-network:
    driver: bridge
