services:
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    container_name: saladdin_app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - storage_data:/var/www/storage
      - storage_public:/var/www/storage/app/public
    env_file:
      - ./.env
    environment:
      APP_ENV: local
      PHP_MEMORY_LIMIT: 512M
    depends_on:
      db:
        condition: service_healthy
    networks:
      - saladdin_net

  web:
    image: nginx:1.27-alpine
    container_name: lms_saladdin
    restart: unless-stopped
    ports:
      - "8001:80"
    volumes:
      - storage_public:/var/www/public/storage
      - ./public/:/var/www/public
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - app
    networks:
      - saladdin_net

  db:
    image: mysql:8.0
    container_name: saladdin_db
    restart: unless-stopped
    ports:
      - "3308:3306"
    environment:
      MYSQL_DATABASE: lms_saladdin_db
      MYSQL_USER: saladdin_user
      MYSQL_PASSWORD: saladdin_pass
      MYSQL_ROOT_PASSWORD: root_pass
    volumes:
      - db_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot_pass"]
      interval: 5s
      timeout: 3s
      retries: 30
    networks:
      - saladdin_net

networks:
  saladdin_net:

volumes:
  db_data:
  storage_data:
  storage_public: