services:
  nginx:
    image: nginx:alpine
    container_name: admision_prod_nginx
    restart: unless-stopped
    ports:
      - "127.0.0.1:${APP_PORT:-8080}:80"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
      - backend_storage:/var/www/html/storage/app/public:ro
    depends_on:
      - backend
      - frontend
    networks:
      - admision_net

  backend:
    image: ghcr.io/${GITHUB_REPO:-usuario/repo}/backend:${IMAGE_TAG:-latest}
    container_name: admision_prod_backend
    restart: unless-stopped
    env_file:
      - .env.prod
    volumes:
      - backend_storage:/var/www/html/storage
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - admision_net

  frontend:
    image: ghcr.io/${GITHUB_REPO:-usuario/repo}/frontend:${IMAGE_TAG:-latest}
    container_name: admision_prod_frontend
    restart: unless-stopped
    networks:
      - admision_net

  mysql:
    image: mysql:8.0
    container_name: admision_prod_db
    restart: unless-stopped
    ports:
      - "127.0.0.1:3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_DATABASE: ${DB_DATABASE:-admision_2026}
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-p${DB_PASSWORD}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - admision_net

volumes:
  mysql_data:
  backend_storage:

networks:
  admision_net:
    driver: bridge
