services:
  app:
    build:
      context: .
      target: development
    container_name: upweb-app
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
      - upweb-vendor:/var/www/html/vendor
      - upweb-node-modules:/var/www/html/node_modules
      - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini:ro
    env_file:
      - .env
    environment:
      APP_URL: http://localhost:8080
      DB_HOST: db
      DB_PORT: 3306
      DB_DATABASE: website
      DB_USERNAME: upweb
      DB_PASSWORD: secret
    depends_on:
      db:
        condition: service_healthy
    networks:
      - upweb

  web:
    image: nginx:1.27-alpine
    container_name: upweb-web
    restart: unless-stopped
    ports:
      - "${APP_PORT:-8080}:80"
    volumes:
      - .:/var/www/html:ro
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - app
    networks:
      - upweb

  db:
    image: mysql:8.0
    container_name: upweb-db
    restart: unless-stopped
    ports:
      - "${DB_PUBLISH_PORT:-3307}:3306"
    environment:
      MYSQL_DATABASE: website
      MYSQL_USER: upweb
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - upweb-db:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 30s
    networks:
      - upweb

  vite:
    profiles: [dev]
    image: node:22-alpine
    container_name: upweb-vite
    working_dir: /var/www/html
    command: sh -c "npm ci && npm run dev -- --host"
    ports:
      - "${VITE_PORT:-5173}:5173"
    volumes:
      - .:/var/www/html
      - upweb-node-modules:/var/www/html/node_modules
    env_file:
      - .env
    networks:
      - upweb

networks:
  upweb:
    driver: bridge

volumes:
  upweb-db:
  upweb-vendor:
  upweb-node-modules:
