name: farmers-marketplace

services:
  web:
    image: ghcr.io/greenbasket/marketplace-web:${APP_VERSION:-latest}
    ports:
      - "8080:3000"
    environment:
      NODE_ENV: production
      API_BASE_URL: http://api:8080
    depends_on:
      api:
        condition: service_healthy
    restart: unless-stopped

  api:
    image: ghcr.io/greenbasket/marketplace-api:${APP_VERSION:-latest}
    ports:
      - "8081:8080"
    env_file:
      - .env
    environment:
      APP_ENV: production
      DATABASE_URL: postgresql://marketplace:${POSTGRES_PASSWORD}@postgres:5432/marketplace
      REDIS_URL: redis://redis:6379/0
      SEARCH_URL: http://search:7700
      STORAGE_ENDPOINT: http://minio:9000
      STORAGE_BUCKET: vendor-assets
      PAYMENT_PROVIDER: stripe
      ORDER_CUTOFF_TIME: "18:00"
      DEFAULT_MARKET_TIMEZONE: America/Toronto
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      search:
        condition: service_started
      minio:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://localhost:8080/health"]
      interval: 15s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  worker:
    image: ghcr.io/greenbasket/marketplace-api:${APP_VERSION:-latest}
    command: ["bundle", "exec", "sidekiq", "-q", "orders", "-q", "notifications", "-q", "inventory"]
    env_file:
      - .env
    environment:
      DATABASE_URL: postgresql://marketplace:${POSTGRES_PASSWORD}@postgres:5432/marketplace
      REDIS_URL: redis://redis:6379/0
      SEARCH_URL: http://search:7700
    depends_on:
      api:
        condition: service_healthy
    restart: unless-stopped

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: marketplace
      POSTGRES_USER: marketplace
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U marketplace -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
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5
    restart: unless-stopped

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

  minio:
    image: minio/minio:RELEASE.2026-06-02T18-12-32Z
    command: ["server", "/data", "--console-address", ":9001"]
    ports:
      - "9001:9001"
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
    volumes:
      - minio_data:/data
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 15s
      timeout: 5s
      retries: 5
    restart: unless-stopped

volumes:
  postgres_data:
  redis_data:
  search_data:
  minio_data: