name: roasterly-local

x-api-env: &api_env
  NODE_ENV: development
  PORT: 8080
  DATABASE_URL: postgres://roasterly:roasterly@postgres:5432/roasterly
  REDIS_URL: redis://redis:6379/0
  STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET}
  INVENTORY_SYNC_CRON: "*/15 * * * *"
  DEFAULT_ROAST_DAYS: "MONDAY,WEDNESDAY"
  CUSTOMER_TIMEZONE: America/New_York

services:
  api:
    image: roasterly/api:dev
    build:
      context: .
      dockerfile: Dockerfile.api
    environment:
      <<: *api_env
    ports:
      - "8080:8080"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started

  worker:
    image: roasterly/api:dev
    command: npm run worker:subscriptions
    environment:
      <<: *api_env
      QUEUES: renewals,shipment_labels,email_receipts
    depends_on:
      - api
      - redis

  storefront:
    image: roasterly/storefront:dev
    build:
      context: ./storefront
    environment:
      NEXT_PUBLIC_API_URL: http://localhost:8080
      NEXT_PUBLIC_BRAND_NAME: Roasterly
    ports:
      - "3000:3000"
    depends_on:
      - api

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: roasterly
      POSTGRES_USER: roasterly
      POSTGRES_PASSWORD: roasterly
    volumes:
      - roasterly-postgres:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U roasterly -d roasterly"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    command: redis-server --appendonly yes
    volumes:
      - roasterly-redis:/data

volumes:
  roasterly-postgres:
  roasterly-redis: