# Ductape platform — Docker Hub release compose
# Written by `ductape install` to ~/.ductape/platform/docker-compose.yml
# Run `ductape start` to bring the stack up.

name: ductape-platform

x-api-image: &api-image
  image: ductape/platform-api:latest
  restart: unless-stopped
  depends_on:
    mongo:
      condition: service_healthy
    kafka:
      condition: service_started
  networks:
    - platform

x-api-env: &api-env
  NODE_ENV: production
  DB_HOST: mongodb://mongo:27017/ductape
  KAFKA_BROKERS: kafka:29092
  KAFKA_TOPIC_PREFIX: ductape
  USE_KAFKA: "true"
  KAFKA_RPC_TIMEOUT_MS: "15000"
  EMAIL_SERVICE: http://emails:8003
  USER_SERVICE: http://users:8002
  WORKSPACE_SERVICE: http://workspaces:8001
  PRICING_SERVICE: http://pricing:8011
  NOTIFICATION_SERVICE: http://notifications:8013
  ADMIN_SERVICE: http://admins:8018
  APPS_SERVICE: http://apps:8004
  DEFAULT_ADMIN_ROLE_ID: ${DEFAULT_ADMIN_ROLE_ID:-}
  CORS_ORIGINS: http://localhost:4310,http://127.0.0.1:4310,http://localhost:4320,http://127.0.0.1:4320,http://localhost:3000,http://localhost
  AWS_ACCOUNT_ID: ${AWS_ACCOUNT_ID:-480358138685}
  AWS_DUCTAPE_ACCOUNT_ID: ${AWS_DUCTAPE_ACCOUNT_ID:-${AWS_ACCOUNT_ID:-480358138685}}

services:
  mongo:
    image: mongo:7
    restart: unless-stopped
    ports:
      - "27017:27017"
    volumes:
      - mongo_data:/data/db
    healthcheck:
      test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - platform

  zookeeper:
    image: confluentinc/cp-zookeeper:7.6.1
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    ports:
      - "2181:2181"
    networks:
      - platform

  kafka:
    image: confluentinc/cp-kafka:7.6.1
    depends_on:
      - zookeeper
    ports:
      - "9092:9092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
    networks:
      - platform

  api-gateway:
    image: nginx:1.27-alpine
    restart: unless-stopped
    ports:
      - "4311:8000"
    volumes:
      - ./api-gateway.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - users
      - workspaces
      - apps
      - proxy
    networks:
      - platform

  users:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: users
      PORT: "8002"
    ports:
      - "8002:8002"

  workspaces:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: workspaces
      PORT: "8001"
    ports:
      - "8001:8001"

  emails:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: emails
      PORT: "8003"
    ports:
      - "8003:8003"

  apps:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: apps
      PORT: "8004"
    ports:
      - "8004:8004"

  integrations:
    <<: *api-image
    env_file:
      - .env
    environment:
      <<: *api-env
      NEST_APP: integrations
      PORT: "8009"
      AWS_REGION: ${AWS_REGION:-us-east-1}
      AWS_SDK_LOAD_CONFIG: ${AWS_SDK_LOAD_CONFIG:-1}
      AWS_PROFILE: ${AWS_PROFILE:-}
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-}
      AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN:-}
    volumes:
      - ${HOME}/.aws:/root/.aws:ro
    ports:
      - "8009:8009"

  pricing:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: pricing
      PORT: "8011"
    ports:
      - "8011:8011"

  logs:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: logs
      PORT: "8008"
    ports:
      - "8008:8008"

  proxy:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: proxy
      PORT: "8020"
      DUCTAPE_API_BASE_URL: http://api-gateway:8000
    ports:
      - "8020:8020"

  admins:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: admins
      PORT: "8018"
    ports:
      - "8018:8018"

  notifications:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: notifications
      PORT: "8013"
    ports:
      - "8013:8013"

  webhooks:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: webhooks
      PORT: "8012"
    ports:
      - "8012:8012"

  jobs:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: jobs
      PORT: "8015"
    ports:
      - "8015:8015"

  marketplace:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: marketplace
      PORT: "8007"
    ports:
      - "8007:8007"

  partnerships:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: partnerships
      PORT: "8014"
    ports:
      - "8014:8014"

  tickets:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: tickets
      PORT: "9002"
    ports:
      - "9002:9002"

  realtime:
    <<: *api-image
    environment:
      <<: *api-env
      NEST_APP: realtime
      PORT: "3030"
    ports:
      - "3030:3030"

  workbench:
    image: ductape/platform-workbench:latest
    restart: unless-stopped
    ports:
      - "4310:80"
    networks:
      - platform

networks:
  platform:
    driver: bridge

volumes:
  mongo_data:
