services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: colegiovinicius-app:latest
    container_name: cvm_app
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
    expose:
      - "9000"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    env_file:
      - .env
    depends_on:
      redis:
        condition: service_started
    networks:
      - cvm

  queue:
    image: colegiovinicius-app:latest
    container_name: cvm_queue
    restart: unless-stopped
    working_dir: /var/www/html
    user: "www-data"
    volumes:
      - .:/var/www/html
    env_file:
      - .env
    depends_on:
      app:
        condition: service_started
      redis:
        condition: service_started
    command: php artisan queue:work --queue=default,media --sleep=1 --tries=1 --timeout=120
    networks:
      - cvm

  redis:
    image: redis:7-alpine
    container_name: cvm_redis
    restart: unless-stopped
    command: redis-server --appendonly yes
    volumes:
      - redis_data:/data
    expose:
      - "6379"
    networks:
      - cvm

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

  node:
    image: node:22-alpine
    container_name: cvm_node
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
    ports:
      - "${VITE_PORT:-5173}:5173"
    command: sh -c "if [ ! -d node_modules ]; then npm install; fi && npm run dev -- --host 0.0.0.0"
    stdin_open: true
    tty: true
    networks:
      - cvm

  node-build:
    image: node:22-alpine
    profiles:
      - build
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
    command: sh -c "npm ci && npm run build"
    networks:
      - cvm

networks:
  cvm:
    driver: bridge

volumes:
  redis_data:
