version: '3.8'

services:
  # --- BACKENDS (PHP-FPM) ---
  # Se aade working_dir para que artisan funcione siempre en la raz correcta
  dev-back: &php-base
    build: { context: ./dev/backend-pulsocar, dockerfile: Dockerfile }
    working_dir: /var/www/html
    volumes:
      - ./dev/backend-pulsocar:/var/www/html
    networks: [car-network]

  qa-back:
    <<: *php-base
    build: { context: ./qa/backend-pulsocar, dockerfile: Dockerfile }
    volumes:
      - ./qa/backend-pulsocar:/var/www/html

  pre-back:
    <<: *php-base
    build: { context: ./pre/backend-pulsocar, dockerfile: Dockerfile }
    volumes:
      - ./pre/backend-pulsocar:/var/www/html

  # --- BACKEND PROXIES (NGINX) ---
  dev-back-nginx: &nginx-back-base
    image: nginx:alpine
    ports: ["9000:80"]
    volumes:
      - ./dev/backend-pulsocar:/var/www/html
      - ./nginx-backend-dev.conf:/etc/nginx/conf.d/default.conf:ro
    networks: [car-network]
    depends_on: [dev-back]

  qa-back-nginx:
    <<: *nginx-back-base
    ports: ["9001:80"]
    volumes:
      - ./qa/backend-pulsocar:/var/www/html
      - ./nginx-backend-qa.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on: [qa-back]

  pre-back-nginx:
    <<: *nginx-back-base
    ports: ["9002:80"]
    volumes:
      - ./pre/backend-pulsocar:/var/www/html
      - ./nginx-backend-pre.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on: [pre-back]

  # --- FRONTENDS ---
  dev-front: &front-base
    image: nginx:alpine
    ports: ["8081:80"]
    volumes:
      - ./dev/PulsoCar/dist:/usr/share/nginx/html
      - ./nginx-frontend.conf:/etc/nginx/conf.d/default.conf:ro
    networks: [car-network]

  qa-front:
    <<: *front-base
    ports: ["8082:80"]
    volumes:
      - ./qa/PulsoCar/dist:/usr/share/nginx/html
      - ./nginx-frontend.conf:/etc/nginx/conf.d/default.conf:ro

  pre-front:
    <<: *front-base
    ports: ["8083:80"]
    volumes:
      - ./pre/PulsoCar/dist:/usr/share/nginx/html
      - ./nginx-frontend.conf:/etc/nginx/conf.d/default.conf:ro

networks:
  car-network:
    driver: bridge