services:
  app:
    build:
      context: .
      dockerfile: ./docker/php/Dockerfile
    container_name: unioil-app
    restart: unless-stopped
    volumes:
      - .:/var/www/html
      - ./storage:/var/www/html/storage
      - ./bootstrap/cache:/var/www/html/bootstrap/cache
    depends_on:
      db_mysql:
        condition: service_healthy
    command: 
      [ "sh", "-c", "/var/www/html/docker/php/entrypoint.sh" ]
    healthcheck:
      test: ["CMD", "pgrep", "php-fpm"]
      interval: 30s
      timeout: 10s
      retries: 10
    networks:
      - unioil-network


  db_mysql:
    image: mysql:8.2
    container_name: unioil-db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: laravel
      MYSQL_DATABASE: unioil_cms
      MYSQL_USER: admin_erish
      MYSQL_PASSWORD: Laravel@123
    volumes:
      - mysql-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 30s
      timeout: 10s
      retries: 5
    networks:
      - unioil-network

  nginx:
    image: nginx:alpine
    container_name: unioil-nginx
    restart: unless-stopped
    ports:
      - "8000:81"
    volumes:
      - .:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      app:
        condition: service_healthy
    networks:
      - unioil-network

volumes:
  mysql-data:
  storage-volume:
    driver: local

networks:
  unioil-network:
    driver: bridge