version: "3.9"

services:
  marketplace:
    image: ghcr.io/example/harvest-marketplace:1.8.2
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      APP_ENV: production
      PORT: "8080"
      DATABASE_URL: postgresql://marketplace:${POSTGRES_PASSWORD}@database:5432/farmers_market
      REDIS_URL: redis://cache:6379/0
      SESSION_SECRET: ${SESSION_SECRET}
      PUBLIC_URL: https://market.example.com
      DEFAULT_CURRENCY: CAD
      ORDER_CUTOFF_TIME: "18:00"
      PICKUP_TIMEZONE: America/Toronto
      ENABLE_VENDOR_REGISTRATION: "true"
      ENABLE_ONLINE_PAYMENTS: "true"
    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:
      - market

  worker:
    image: ghcr.io/example/harvest-marketplace:1.8.2
    restart: unless-stopped
    command: ["./marketplace", "worker"]
    environment:
      APP_ENV: production
      DATABASE_URL: postgresql://marketplace:${POSTGRES_PASSWORD}@database:5432/farmers_market
      REDIS_URL: redis://cache:6379/0
      PAYMENT_PROVIDER_KEY: ${PAYMENT_PROVIDER_KEY}
      EMAIL_PROVIDER_KEY: ${EMAIL_PROVIDER_KEY}
      PICKUP_TIMEZONE: America/Toronto
    depends_on:
      database:
        condition: service_healthy
      cache:
        condition: service_healthy
    networks:
      - market

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

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

volumes:
  marketplace_data:
  cache_data:

networks:
  market:
    driver: bridge