services:
  postgres:
    image: postgres:15-alpine
    container_name: yotrip-db-prod
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_DB: travel_db
    volumes:
      - pg_data_prod:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d travel_db"]
      interval: 5s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: yotrip-redis-prod
    restart: always

  backend:
    build:
      context: ./backend
      target: production
    container_name: yotrip-backend-prod
    restart: always
    command: >
      sh -c "npx prisma migrate deploy --schema=prisma/schema.prisma && node dist/src/main.js"
    ports:
      - "3001:3001"
    volumes:
      - ./backend/uploads:/usr/src/app/uploads
    environment:
      DATABASE_URL: "postgresql://postgres:password@postgres:5432/travel_db?schema=public"
      REDIS_URL: "redis://redis:6379"
      PORT: 3001
      ADMIN_SECRET_KEY: "${ADMIN_SECRET_KEY}"
      JWT_SECRET: "super-secret"
      FRONTEND_URL: "${FRONTEND_URL}"
      NODE_ENV: production
      SMTP_HOST: "${SMTP_HOST}"
      SMTP_PORT: "${SMTP_PORT}"
      SMTP_SECURE: "${SMTP_SECURE}"
      SMTP_USER: "${SMTP_USER}"
      SMTP_PASS: "${SMTP_PASS}"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started

  frontend:
    build:
      context: ./frontend
      target: production
      args:
        - VITE_GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
    container_name: yotrip-frontend-prod
    restart: always
    ports:
      - "3002:80"
    depends_on:
      - backend

volumes:
  pg_data_prod:
