version: '3.8'

services:
  app:
    build:
      context: ./docker/php
      dockerfile: Dockerfile
      args:
        user: tailoruser
        uid: 1000
    container_name: tailor-app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - ./:/var/www
      - composer_cache:/home/tailoruser/.composer
    networks:
      - tailor-network
    depends_on:
      db:
        condition: service_healthy

  webserver:
    image: nginx:alpine
    container_name: tailor-webserver
    restart: unless-stopped
    ports:
      - "8000:80"
    volumes:
      - ./:/var/www
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    networks:
      - tailor-network
    depends_on:
      - app

  db:
    image: mysql:8.0
    container_name: tailor-db
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: tailor_db
      MYSQL_USER: tailor_user
      MYSQL_PASSWORD: tailor_secret
      MYSQL_ROOT_PASSWORD: rootsecret
    ports:
      - "3306:3306"
    volumes:
      - tailor_mysql_data:/var/lib/mysql
    networks:
      - tailor-network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-prootsecret"]
      interval: 10s
      timeout: 5s
      retries: 5

  node:
    image: node:22-alpine
    container_name: tailor-node
    working_dir: /var/www/tailor-frontend
    volumes:
      - ./:/var/www
    ports:
      - "5173:5173"
    networks:
      - tailor-network
    tty: true
    stdin_open: true
    command: sh -c "npm install && npm run dev -- --host 0.0.0.0"

networks:
  tailor-network:
    driver: bridge

volumes:
  tailor_mysql_data:
    driver: local
  composer_cache:
    driver: local
