name: farmers-marketplace

services:
  web:
    image: ghcr.io/acme/farmers-market-web:${APP_VERSION:-latest}
    ports:
      - "8080:3000"
    environment:
      NODE_ENV: production
      API_BASE_URL: http://api:8080
      MARKET_NAME: "Riverbend Farmers Market"
    depends_on:
      api:
        condition: service_healthy
    restart: unless-stopped

  api:
    image: ghcr.io/acme/farmers-market-api:${APP_VERSION:-latest}
    ports:
      - "8081:8080"
    environment:
      APP_ENV: production
      DATABASE_URL: postgres://market:${POSTGRES_PASSWORD}@postgres:5432/marketplace
      REDIS_URL: redis://redis:6379/0
      ENABLE_VENDOR_APPROVALS: "true"
      ORDER_PICKUP_WINDOW_MINUTES: "30"
      PAYMENT_PROVIDER: stripe
      STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 20s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  worker:
    image: ghcr.io/acme/farmers-market-api:${APP_VERSION:-latest}
    command: ["node", "dist/jobs/worker.js"]
    environment:
      APP_ENV: production
      DATABASE_URL: postgres://market:${POSTGRES_PASSWORD}@postgres:5432/marketplace
      REDIS_URL: redis://redis:6379/0
      NOTIFICATION_FROM: orders@riverbendmarket.example
    depends_on:
      api:
        condition: service_healthy
    restart: unless-stopped

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

  redis:
    image: redis:7-alpine
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - redis_data:/data
    restart: unless-stopped

volumes:
  postgres_data:
  redis_data: