version: "3.9"

services:
  marketplace-api:
    image: ghcr.io/harvest-hub/marketplace-api:2.4.1
    restart: unless-stopped
    environment:
      NODE_ENV: production
      PORT: "8080"
      DATABASE_URL: postgresql://marketplace:${POSTGRES_PASSWORD}@database:5432/marketplace
      REDIS_URL: redis://cache:6379/0
      PUBLIC_URL: https://market.harvesthub.example
      DEFAULT_CURRENCY: CAD
      ORDER_CUTOFF_HOUR: "18"
      LOG_LEVEL: info
    ports:
      - "8080:8080"
    depends_on:
      database:
        condition: service_healthy
      cache:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "--quiet", "--spider", "http://localhost:8080/health"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 20s
    networks:
      - marketplace
    volumes:
      - product-images:/app/uploads

  order-worker:
    image: ghcr.io/harvest-hub/marketplace-api:2.4.1
    restart: unless-stopped
    command: ["npm", "run", "worker"]
    environment:
      NODE_ENV: production
      DATABASE_URL: postgresql://marketplace:${POSTGRES_PASSWORD}@database:5432/marketplace
      REDIS_URL: redis://cache:6379/0
      PAYMENT_PROVIDER: stripe
      STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY}
      EMAIL_FROM: orders@harvesthub.example
    depends_on:
      marketplace-api:
        condition: service_healthy
    networks:
      - marketplace

  database:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: marketplace
      POSTGRES_USER: marketplace
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - database-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U marketplace -d marketplace"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - marketplace

  cache:
    image: redis:7.2-alpine
    restart: unless-stopped
    command: ["redis-server", "--appendonly", "yes", "--maxmemory", "256mb"]
    volumes:
      - cache-data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5
    networks:
      - marketplace

volumes:
  database-data:
  cache-data:
  product-images:

networks:
  marketplace:
    driver: bridge