name: farmers-market

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_REGION: northeast
    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/farmers_market
      REDIS_URL: redis://redis:6379/0
      STORAGE_BUCKET: vendor-product-photos
      PAYMENT_PROVIDER: stripe
      ORDER_CUTOFF_HOUR: "18"
      DELIVERY_ZONES: "downtown,northside,west-end"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:8080/health"]
      interval: 20s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  worker:
    image: ghcr.io/acme/farmers-market-worker:${APP_VERSION:-latest}
    command: ["./bin/worker", "--queues=orders,payments,notifications"]
    environment:
      APP_ENV: production
      DATABASE_URL: postgres://market:${POSTGRES_PASSWORD}@postgres:5432/farmers_market
      REDIS_URL: redis://redis:6379/0
      EMAIL_FROM: receipts@farmersmarket.example
    depends_on:
      api:
        condition: service_healthy
      redis:
        condition: service_started
    restart: unless-stopped

  postgres:
    image: postgres:16-alpine
    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
    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: