services:
  redis:
    image: redis:alpine
    restart: unless-stopped

  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: farmafinder
      POSTGRES_USER: farmafinder
      POSTGRES_PASSWORD: ${PG_PASSWORD:-change-me-in-production}
    volumes:
      - postgres_data:/var/lib/postgresql/data

  backend:
    image: git.hacecalor.net/ichitux/farmafinder-backend:latest
    build:
      context: .
      dockerfile: apps/backend/Dockerfile
    restart: unless-stopped
    env_file:
      - ./apps/backend/.env
    ports:
      - "3001:3001"
    environment:
      PORT: "3001"
      NODE_ENV: production
      SESSION_SECRET: ${SESSION_SECRET:-change-me-in-production}
      CORS_ORIGIN: http://localhost:4000
      REDIS_HOST: redis
      REDIS_PORT: "6379"
      REDIS_PASSWORD: ${REDIS_PASSWORD:-}
      DATABASE_PATH: /app/data/database.sqlite
      FARMACIAS_WEBHOOK_URL: ${FARMACIAS_WEBHOOK_URL:-}
      PG_URL: postgresql://farmafinder:${PG_PASSWORD:-change-me-in-production}@postgres:5432/farmafinder
      # OpenTelemetry — exported via OTLP gRPC to the shared Alloy collector
      OTEL_SERVICE_NAME: farmafinder-backend
      OTEL_EXPORTER_OTLP_ENDPOINT: http://host.docker.internal:4317
      OTEL_TRACES_EXPORTER: otlp
      OTEL_LOGS_EXPORTER: otlp
      OTEL_RESOURCE_ATTRIBUTES: service.namespace=farmafinder
    volumes:
      - backend_data:/app/data
    depends_on:
      - redis
      - postgres

  frontend:
    image: git.hacecalor.net/ichitux/farmafinder-frontend:latest
    build:
      context: ./apps/frontend
      args:
        VITE_FARO_ENDPOINT: ${VITE_FARO_ENDPOINT:-http://localhost:4318}
        VITE_FARO_APP_NAME: ${VITE_FARO_APP_NAME:-farmafinder-frontend}
        VITE_FARO_ENV: ${VITE_FARO_ENV:-production}
        VITE_FARO_APP_VERSION: ${VITE_FARO_APP_VERSION:-1.0.0}
    restart: unless-stopped
    ports:
      - "4000:80"
    depends_on:
      - backend

volumes:
  backend_data:
  postgres_data:
