Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

14.7 KB
Raw Blame
###
# Worktree-isolated dev stack. Boot via `npm run dev:up` (see packages/dev/src/cli.ts).
# COMPOSE_PROJECT_NAME=carbon-<slug> namespaces every container, network, volume.
# Required env (provided by .env via --env-file): PORT_*, SUPABASE_JWT_SECRET,
# SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY, plus user secrets passed through.
###

# `restart: on-failure` on every service: a crashed container comes back, but
# the stack does NOT restart with the Docker daemon. A stack is only useful
# with its `crbn up` running, and `unless-stopped` brought every stack whose
# terminal had died back to life on each Docker start.
services:
  postgres:
    image: supabase/postgres:15.14.1.112
    restart: on-failure
    deploy:
      resources:
        limits:
          # Defaults are sized so one stack runs smoothly while a machine can
          # host several worktree stacks at once (limits are ceilings, not
          # reservations — idle usage is far below them). Override any of these
          # per worktree via MEM_*/CPU_* in that worktree's .env.
          memory: ${MEM_POSTGRES:-1g}
          cpus: ${CPU_POSTGRES:-2}
    networks:
      default:
        aliases:
          - db
    ports:
      - "${PORT_DB}:5432"
    environment:
      TZ: UTC
      POSTGRES_HOST: /var/run/postgresql
      POSTGRES_PORT: 5432
      PGPORT: 5432
      POSTGRES_DB: postgres
      PGDATABASE: postgres
      POSTGRES_PASSWORD: postgres
      PGPASSWORD: postgres
      JWT_SECRET: ${SUPABASE_JWT_SECRET}
      JWT_EXP: 3600
    volumes:
      - pgdata:/var/lib/postgresql/data
      - pgconfig:/etc/postgresql-custom
      - ./packages/dev/docker/init.sql:/docker-entrypoint-initdb.d/zz-carbon-roles.sql:ro
    command:
      - postgres
      - -c
      - config_file=/etc/postgresql/postgresql.conf
      - -c
      - log_min_messages=fatal
      - -c
      - shared_buffers=${PG_SHARED_BUFFERS:-128MB}
      - -c
      - effective_cache_size=${PG_EFFECTIVE_CACHE_SIZE:-256MB}
      - -c
      - work_mem=${PG_WORK_MEM:-4MB}
      - -c
      - maintenance_work_mem=${PG_MAINTENANCE_WORK_MEM:-64MB}
      - -c
      - max_connections=${PG_MAX_CONNECTIONS:-100}
      - -c
      - fsync=off
      - -c
      - synchronous_commit=off
      - -c
      - full_page_writes=off
      - -c
      - max_wal_size=256MB
      - -c
      - jit=off
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres", "-h", "localhost"]
      interval: 5s
      timeout: 5s
      retries: 20

  gotrue:
    image: supabase/gotrue:v2.189.0
    restart: on-failure
    deploy:
      resources:
        limits:
          memory: ${MEM_GOTRUE:-96m}
          cpus: ${CPU_GOTRUE:-0.25}
    environment:
      GOTRUE_API_HOST: 0.0.0.0
      GOTRUE_API_PORT: 9999
      API_EXTERNAL_URL: ${SUPABASE_URL}
      GOTRUE_DB_DRIVER: postgres
      GOTRUE_DB_DATABASE_URL: postgres://supabase_auth_admin:postgres@postgres:5432/postgres
      GOTRUE_SITE_URL: ${ERP_URL}
      # `/**` so a callback carrying `?redirectTo=` still matches — an exact
      # entry does not, and GoTrue then falls back to GOTRUE_SITE_URL (the
      # ERP). localhost:4000 is the starter (`pnpm dev:starter`).
      GOTRUE_URI_ALLOW_LIST: ${ERP_URL},${ERP_URL}/**,${MES_URL},${MES_URL}/**,${GTM_URL},http://localhost:4000,http://localhost:4000/**
      GOTRUE_DISABLE_SIGNUP: ${GOTRUE_DISABLE_SIGNUP:-false}
      GOTRUE_JWT_SECRET: ${SUPABASE_JWT_SECRET}
      GOTRUE_JWT_EXP: 3600
      GOTRUE_SECURITY_REFRESH_TOKEN_REUSE_INTERVAL: 10
      GOTRUE_JWT_DEFAULT_GROUP_NAME: authenticated
      GOTRUE_JWT_ADMIN_ROLES: service_role
      GOTRUE_JWT_AUD: authenticated
      GOTRUE_EXTERNAL_EMAIL_ENABLED: "true"
      GOTRUE_MAILER_AUTOCONFIRM: "true"
      GOTRUE_SMTP_HOST: ${GOTRUE_SMTP_HOST:-inbucket}
      GOTRUE_SMTP_PORT: ${GOTRUE_SMTP_PORT:-2500}
      GOTRUE_SMTP_USER: ${GOTRUE_SMTP_USER:-}
      GOTRUE_SMTP_PASS: ${GOTRUE_SMTP_PASS:-}
      GOTRUE_SMTP_ADMIN_EMAIL: ${GOTRUE_SMTP_ADMIN_EMAIL:[email protected]}
      GOTRUE_SMTP_SENDER_NAME: Carbon
      GOTRUE_EXTERNAL_GOOGLE_ENABLED: "true"
      GOTRUE_EXTERNAL_GOOGLE_CLIENT_ID: ${SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID:-}
      GOTRUE_EXTERNAL_GOOGLE_SECRET: ${SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_SECRET:-}
      GOTRUE_EXTERNAL_GOOGLE_REDIRECT_URI: ${SUPABASE_AUTH_EXTERNAL_GOOGLE_REDIRECT_URI}
      GOTRUE_EXTERNAL_AZURE_ENABLED: "true"
      GOTRUE_EXTERNAL_AZURE_CLIENT_ID: ${SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_ID:-}
      GOTRUE_EXTERNAL_AZURE_SECRET: ${SUPABASE_AUTH_EXTERNAL_AZURE_CLIENT_SECRET:-}
      GOTRUE_EXTERNAL_AZURE_REDIRECT_URI: ${SUPABASE_AUTH_EXTERNAL_AZURE_REDIRECT_URI}
      GOTRUE_MAILER_TEMPLATES_MAGIC_LINK: ${ERP_URL}/templates/magic-link.html
      GOTRUE_MAILER_TEMPLATES_INVITE: ${ERP_URL}/templates/invite.html
      GOTRUE_MFA_TOTP_ENROLL_ENABLED: "true"
      GOTRUE_MFA_TOTP_VERIFY_ENABLED: "true"
      GOTRUE_MFA_MAX_ENROLLED_FACTORS: 10
      GOTRUE_SAML_ENABLED: ${SAML_ENABLED:-false}
      GOTRUE_SAML_PRIVATE_KEY: ${SAML_PRIVATE_KEY:-}
      SSL_CERT_FILE: /etc/ssl/certs/portless-ca.pem
    extra_hosts:
      - "host.docker.internal:host-gateway"
      - "${DOMAIN}:host-gateway"
    volumes:
      - ${HOME}/.portless/ca.pem:/etc/ssl/certs/portless-ca.pem:ro
    depends_on:
      postgres:
        condition: service_healthy

  postgrest:
    image: postgrest/postgrest:v13.0.8
    restart: on-failure
    deploy:
      resources:
        limits:
          memory: ${MEM_POSTGREST:-256m}
          cpus: ${CPU_POSTGREST:-1}
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      PGRST_DB_URI: postgres://authenticator:postgres@postgres:5432/postgres
      PGRST_DB_SCHEMAS: public,storage,graphql_public
      PGRST_DB_ANON_ROLE: anon
      PGRST_JWT_SECRET: ${SUPABASE_JWT_SECRET}
      # Pool default is 10 — a burst of concurrent authed queries (the /x loader
      # alone fires ~16) plus any aborted-mid-transaction requests exhausts it and
      # every subsequent query blocks. Bigger pool + a bounded acquisition timeout
      # so a saturated pool fails fast instead of hanging the request forever.
      PGRST_DB_POOL: ${PGRST_DB_POOL:-25}
      PGRST_DB_POOL_ACQUISITION_TIMEOUT: ${PGRST_DB_POOL_ACQUISITION_TIMEOUT:-10}
      PGRST_DB_USE_LEGACY_GUCS: "false"
      PGRST_APP_SETTINGS_JWT_SECRET: ${SUPABASE_JWT_SECRET}
      PGRST_APP_SETTINGS_JWT_EXP: 3600

  realtime:
    image: supabase/realtime:v2.89.0
    restart: on-failure
    deploy:
      resources:
        limits:
          memory: ${MEM_REALTIME:-384m}
          cpus: ${CPU_REALTIME:-0.5}
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      default:
        aliases:
          - realtime-dev
    environment:
      PORT: 4000
      DB_HOST: postgres
      DB_PORT: 5432
      DB_USER: supabase_admin
      DB_PASSWORD: postgres
      DB_NAME: postgres
      DB_AFTER_CONNECT_QUERY: "SET search_path TO _realtime"
      DB_ENC_KEY: supabaserealtime
      API_JWT_SECRET: ${SUPABASE_JWT_SECRET}
      METRICS_JWT_SECRET: ${SUPABASE_JWT_SECRET}
      SECRET_KEY_BASE: UpNVntn3cDxHJpq99YMc1T1AQgQpc8kfYTuRgBiYa15BLrx8etQoXz3gZv1/u2oq
      APP_NAME: realtime
      ERL_AFLAGS: -proto_dist inet_tcp
      DNS_NODES: "''"
      RLIMIT_NOFILE: "10000"
      SEED_SELF_HOST: "true"
      RUN_JANITOR: "true"
      DISABLE_HEALTHCHECK_LOGGING: "true"

  storage:
    image: supabase/storage-api:v1.58.4
    restart: on-failure
    deploy:
      resources:
        limits:
          # GB-scale CAD: temp-staging allows 2.5 GB objects. Serving a 1.85 GB
          # object, storage-api is CPU-bound (reads/hashes the whole file before
          # streaming) — at the old 0.25-core limit it never produced a byte
          # before the client timed out. Give it real cores + headroom RAM. Limits
          # are ceilings (idle ~160 MB / ~0%), only used when serving a big file.
          # Paired with kong `proxy_buffering off` so the response streams.
          memory: ${MEM_STORAGE:-2g}
          cpus: ${CPU_STORAGE:-2}
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      ANON_KEY: ${SUPABASE_ANON_KEY}
      SERVICE_KEY: ${SUPABASE_SERVICE_ROLE_KEY}
      POSTGREST_URL: http://postgrest:3000
      PGRST_JWT_SECRET: ${SUPABASE_JWT_SECRET}
      DATABASE_URL: postgres://supabase_storage_admin:postgres@postgres:5432/postgres
      # 2.5 GB global storage ceiling (must be >= the largest per-bucket limit;
      # effective per-bucket = min(this, bucket limit)). Per-bucket limits then
      # differentiate: `private` = 50 MB (served artifacts), `temp-staging` =
      # 2.5 GB (raw CAD). Keep in sync with config.toml [storage].
      FILE_SIZE_LIMIT: 2500000000
      STORAGE_BACKEND: file
      FILE_STORAGE_BACKEND_PATH: /var/lib/storage
      TENANT_ID: stub
      REGION: stub
      GLOBAL_S3_BUCKET: stub
      ENABLE_IMAGE_TRANSFORMATION: "true"
      IMGPROXY_URL: http://imgproxy:5001
    volumes:
      - storage:/var/lib/storage:z

  # Image transformations (resize + HEIC→JPEG decode) for the storage API.
  # Internal only — never publish a port: direct imgproxy access reads the
  # storage volume with no RLS.
  imgproxy:
    image: darthsim/imgproxy:v3.8.0
    restart: on-failure
    profiles: ["full"]
    deploy:
      resources:
        limits:
          memory: ${MEM_IMGPROXY:-512m}
          cpus: ${CPU_IMGPROXY:-1}
    environment:
      IMGPROXY_BIND: ":5001"
      IMGPROXY_LOCAL_FILESYSTEM_ROOT: /
      IMGPROXY_USE_ETAG: "true"
      # Default is 16.8Mpx, which rejects 48MP iPhone photos.
      IMGPROXY_MAX_SRC_RESOLUTION: "60"
    healthcheck:
      test: ["CMD", "imgproxy", "health"]
      interval: 5s
      timeout: 5s
      retries: 30
    volumes:
      - storage:/var/lib/storage:z

  meta:
    image: supabase/postgres-meta:v0.96.5
    restart: on-failure
    deploy:
      resources:
        limits:
          memory: ${MEM_META:-128m}
          cpus: ${CPU_META:-0.25}
    profiles: ["full", "studio"]
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      PG_META_PORT: 8080
      PG_META_DB_HOST: postgres
      PG_META_DB_PORT: 5432
      PG_META_DB_NAME: postgres
      PG_META_DB_USER: supabase_admin
      PG_META_DB_PASSWORD: postgres

  studio:
    image: supabase/studio:2026.04.28-sha-89d08a2
    restart: on-failure
    deploy:
      resources:
        limits:
          memory: ${MEM_STUDIO:-384m}
          cpus: ${CPU_STUDIO:-0.5}
    profiles: ["full", "studio"]
    depends_on:
      meta:
        condition: service_started
    ports:
      - "${PORT_STUDIO}:3000"
    environment:
      STUDIO_PG_META_URL: http://meta:8080
      POSTGRES_PASSWORD: postgres
      DEFAULT_ORGANIZATION_NAME: Carbon
      DEFAULT_PROJECT_NAME: carbon-${CARBON_WORKTREE}
      SUPABASE_URL: http://kong:8000
      SUPABASE_PUBLIC_URL: ${SUPABASE_URL}
      SUPABASE_ANON_KEY: ${SUPABASE_ANON_KEY}
      SUPABASE_SERVICE_KEY: ${SUPABASE_SERVICE_ROLE_KEY}
      # Studio's SQL-editor snippets are read from a directory on disk; with the
      # var unset it throws "SNIPPETS_MANAGEMENT_FOLDER env var is not set" on
      # the SQL editor page. Studio creates the folder itself if missing. Not a
      # mounted volume on purpose — snippets are scratch SQL, not project state.
      SNIPPETS_MANAGEMENT_FOLDER: /app/snippets

  inbucket:
    image: inbucket/inbucket:3.1.1
    restart: on-failure
    deploy:
      resources:
        limits:
          memory: ${MEM_INBUCKET:-64m}
          cpus: ${CPU_INBUCKET:-0.25}
    profiles: ["mail"]
    ports:
      - "${PORT_INBUCKET}:9000"
    # The image declares /config and /storage as volumes; left unmounted, each
    # `down` strands two anonymous volumes. /config is empty in the image.
    tmpfs:
      - /config
    volumes:
      - inbucket:/storage

  edge-runtime:
    image: supabase/edge-runtime:v1.74.0
    restart: on-failure
    profiles: ["full"]
    deploy:
      resources:
        limits:
          # The edge runtime compiles each function's TS module graph on worker
          # boot. Starved of CPU, worker boot outlives the isolate CPU budget
          # and requests hang mid-kill.
          memory: ${MEM_EDGE:-1g}
          cpus: ${CPU_EDGE:-3}
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      TZ: UTC
      JWT_SECRET: ${SUPABASE_JWT_SECRET}
      SUPABASE_URL: http://kong:8000
      SUPABASE_ANON_KEY: ${SUPABASE_ANON_KEY}
      SUPABASE_SERVICE_ROLE_KEY: ${SUPABASE_SERVICE_ROLE_KEY}
      VERIFY_JWT: "false"
    volumes:
      - ./packages/database/supabase/functions:/home/deno/functions:ro
      # Dev-only dispatcher; lives outside supabase/functions/ so prod
      # `supabase functions deploy --all` can't pick it up.
      - ./packages/dev/docker/edge-main:/home/deno/main:ro
    command:
      - start
      - --main-service
      - /home/deno/main

  kong:
    image: kong:2.8.1
    restart: on-failure
    deploy:
      resources:
        limits:
          memory: ${MEM_KONG:-256m}
          cpus: ${CPU_KONG:-0.5}
    depends_on:
      gotrue:
        condition: service_started
      postgrest:
        condition: service_started
      realtime:
        condition: service_started
      storage:
        condition: service_started
      meta:
        condition: service_started
        required: false
      edge-runtime:
        condition: service_started
        required: false
    ports:
      - "${PORT_API}:8000"
    environment:
      KONG_DATABASE: "off"
      KONG_DECLARATIVE_CONFIG: /home/kong/kong.yml
      KONG_DNS_ORDER: LAST,A,CNAME
      KONG_PLUGINS: request-transformer,cors,key-auth,acl,basic-auth
      KONG_NGINX_WORKER_PROCESSES: ${KONG_WORKERS:-1}
      # Stream proxied responses instead of buffering them. Default nginx
      # `proxy_buffering on` buffers the whole upstream response (to RAM then a
      # temp file capped at 1 GB) before sending — so a >1 GB storage download
      # (2.5 GB temp-staging cap) stalls/aborts. `off` streams upstream→client.
      KONG_NGINX_PROXY_PROXY_BUFFERING: "off"
    volumes:
      - ./packages/dev/docker/kong.yml:/home/kong/kong.yml:ro

  # Redis is shared across worktrees — booted directly as the `carbon-redis`
  # container by the dev CLI (packages/dev/src/services/compose.ts), not here.
  # Each worktree gets its own logical DB index (0-15) via REDIS_URL.

  inngest:
    image: inngest/inngest:v1.19.4
    restart: on-failure
    deploy:
      resources:
        limits:
          memory: ${MEM_INNGEST:-1g}
          cpus: ${CPU_INNGEST:-0.5}
    ports:
      - "${PORT_INNGEST}:8288"
    command:
      - inngest
      - dev
      - --sdk-url=${ERP_URL}/api/inngest
    environment:
      SSL_CERT_FILE: /etc/ssl/certs/portless-ca.pem
    extra_hosts:
      - "host.docker.internal:host-gateway"
      - "${INNGEST_TLS_HOST}:host-gateway"
    volumes:
      - inngest:/data
      - ${HOME}/.portless/ca.pem:/etc/ssl/certs/portless-ca.pem:ro

volumes:
  pgdata:
  pgconfig:
  storage:
  inngest:
  inbucket: