name: farmers-market-marketplace

services:
  storefront:
    image: ghcr.io/localharvest/storefront:${APP_VERSION:-latest}
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      NODE_ENV: production
      PUBLIC_API_URL: ${PUBLIC_API_URL:-http://api:3000}
      PUBLIC_MARKET_NAME: ${PUBLIC_MARKET_NAME:-Saturday Green Market}
    depends_on:
      api:
        condition: service_healthy

  api:
    image: ghcr.io/localharvest/api:${APP_VERSION:-latest}
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      APP_ENV: production
      DATABASE_URL: postgres://market:${POSTGRES_PASSWORD}@postgres:5432/farmers_market
      REDIS_URL: redis://redis:6379/0
      SEARCH_URL: http://search:7700
      SEARCH_MASTER_KEY: ${SEARCH_MASTER_KEY}
      STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY}
      ORDER_CUTOFF_HOUR: "18"
      PICKUP_TIMEZONE: America/Toronto
      DEFAULT_CURRENCY: USD
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      search:
        condition: service_started
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://localhost:3000/health || exit 1"]
      interval: 15s
      timeout: 5s
      retries: 5

  worker:
    image: ghcr.io/localharvest/api:${APP_VERSION:-latest}
    restart: unless-stopped
    command: ["node", "dist/workers/order-fulfillment.js"]
    environment:
      DATABASE_URL: postgres://market:${POSTGRES_PASSWORD}@postgres:5432/farmers_market
      REDIS_URL: redis://redis:6379/0
      EMAIL_FROM: orders@localharvest.example
      SMTP_HOST: ${SMTP_HOST}
      SMTP_PORT: ${SMTP_PORT:-587}
      SMTP_USER: ${SMTP_USER}
      SMTP_PASSWORD: ${SMTP_PASSWORD}
    depends_on:
      api:
        condition: service_healthy
      redis:
        condition: service_healthy

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

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - redis-data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5

  search:
    image: getmeili/meilisearch:v1.9
    restart: unless-stopped
    environment:
      MEILI_ENV: production
      MEILI_MASTER_KEY: ${SEARCH_MASTER_KEY}
    volumes:
      - search-data:/meili_data

volumes:
  postgres-data:
  redis-data:
  search-data: