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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
ci(assembler): deploy per workspace via ci/src/assembler.ts
Sidwebworks0851a6fa3c7b
diff --git a/.github/workflows/assembler.yml b/.github/workflows/assembler.ymlindex c3f78cf45a..a0fbe663e0 100644--- a/.github/workflows/assembler.yml+++ b/.github/workflows/assembler.yml@@ -4,7 +4,9 @@ name: Assembler Image# assembler image (and vice versa — erp/mes pushes never rebuild this).# Builds carbon/assembler:${sha} from apps/assembler/Dockerfile, which links the# prebuilt carbon/occt base (built here on demand — it's a ~30 min OCCT compile,-# so it is NOT part of every run). The Lambda/ECS *deploy* is separate (P2/P3).+# so it is NOT part of every run). The deploy job runs ci/src/assembler.ts+# (same pattern as deploy.yml -> ci/src/deploy.ts) against the standalone+# apps/assembler/sst.config.ts stack.## Prereq: ECR repos carbon/assembler + carbon/occt exist (created out-of-band).@@ -53,7 +55,21 @@ jobs:- name: Set up Docker Buildxuses: docker/setup-buildx-action@v3+ # The 8.0.0-p1 tag is immutable (OCCT version + patch level) — if it's+ # already in ECR, the ~30 min compile is pointless; skip it.+ - name: Check if OCCT base already exists+ id: occt-exists+ run: |+ if aws ecr describe-images --repository-name carbon/occt \+ --image-ids imageTag=8.0.0-p1 >/dev/null 2>&1; then+ echo "exists=true" >> "$GITHUB_OUTPUT"+ echo "carbon/occt:8.0.0-p1 already in ECR — skipping build"+ else+ echo "exists=false" >> "$GITHUB_OUTPUT"+ fi+- name: Build and push OCCT base+ if: steps.occt-exists.outputs.exists != 'true'uses: docker/build-push-action@v5with:context: apps/assembler@@ -63,6 +79,10 @@ jobs:cache-from: type=ghacache-to: type=gha,mode=maxplatforms: linux/amd64+ # Lambda rejects OCI image indexes — attestations turn the pushed+ # manifest into one, so both must stay off.+ provenance: false+ sbom: falsebuild:name: Build assembler image@@ -71,7 +91,12 @@ jobs:# ECR repos + AWS secrets exist in the CI account, an automatic build on a# main merge would just fail red. Manual workflow_dispatch always works —# running it by hand is intentional.- if: github.event_name == 'workflow_dispatch' || vars.ASSEMBLER_CI_ENABLED == 'true'+ #+ # `needs: occt-base` so a dispatch that (re)builds the base finishes it+ # BEFORE this job pulls it. When occt-base is skipped (the normal case),+ # `!failure()` lets this job run anyway — `needs` alone would skip it too.+ needs: occt-base+ if: ${{ !failure() && !cancelled() && (github.event_name == 'workflow_dispatch' || vars.ASSEMBLER_CI_ENABLED == 'true') }}runs-on: ubuntu-lateststeps:- name: Checkout code@@ -108,6 +133,10 @@ jobs:cache-from: type=ghacache-to: type=gha,mode=maxplatforms: linux/amd64+ # Lambda rejects OCI image indexes — attestations turn the pushed+ # manifest into one, so both must stay off.+ provenance: false+ sbom: false# Report-only for now (exit-code 0). Flip to '1' to fail the build on# CRITICAL/HIGH once the base image's findings are triaged.@@ -119,19 +148,24 @@ jobs:ignore-unfixed: trueexit-code: "0"- # P2/P3 deploy — MANUAL ONLY, never auto-fires. Gated on the explicit `deploy`- # dispatch input so a main push only builds the image (above); the Lambda/ECS- # rollout happens when a human triggers it AFTER filling the DECISION: env in- # apps/assembler/sst.config.ts and adding the deploy secrets. This is an- # UNVALIDATED scaffold (see the sst.config.ts header) — validate against a- # throwaway stage first.+ # MANUAL ONLY — gated on the explicit `deploy` dispatch input, so a main push+ # only builds the image (above); a human triggers the rollout. Runs+ # ci/src/assembler.ts, which fans out over the workspaces table (same as+ # deploy.yml -> ci/src/deploy.ts): each workspace with `assembler = true`+ # gets the image pushed by `build` (carbon/assembler:${github.sha}) deployed+ # to its own AWS account. All per-workspace config (account, region, redis,+ # api key, cert, domain) comes from the workspaces row — no per-value secrets.deploy:- name: Deploy assembler (Lambda + optional ECS service)- if: ${{ github.event_name == 'workflow_dispatch' && inputs.deploy }}+ name: Deploy assembler+ # A custom `if` replaces the implicit success() — keep the explicit result+ # check so a failed image build never deploys.+ if: ${{ needs.build.result == 'success' && github.event_name == 'workflow_dispatch' && inputs.deploy }}needs: buildruns-on: ubuntu-latestenv:- IMAGE_TAG: ${{ github.sha }}+ SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}+ SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}+ SUPABASE_URL: ${{ secrets.SUPABASE_URL }}steps:- uses: actions/checkout@v4@@ -157,24 +191,8 @@ jobs:- name: Install dependenciesrun: pnpm install --frozen-lockfile- # Deploys apps/assembler/sst.config.ts. The image was pushed by `build`- # above (carbon/assembler:${github.sha}); IMAGE_TAG points the Lambda + ECS- # task at it. Consumers' ASSEMBLER_SERVICE_URL / ASSEMBLER_ECS_SERVICE_URL /- # ASSEMBLER_SYNC_ENABLED are wired from the stack outputs after this runs.- - name: Deploy (sst)- working-directory: apps/assembler+ - name: Deployenv:- AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}- AWS_REGION: ${{ secrets.AWS_REGION }}- ASSEMBLER_SERVICE_API_KEY: ${{ secrets.ASSEMBLER_SERVICE_API_KEY }}- # DECISION: fill the rest from secrets before enabling —- # ASSEMBLER_ALLOWED_URL_HOSTS, ASSEMBLER_REDIS_URL,- # ASSEMBLER_ECS_ENABLED (default off), ASSEMBLER_SERVICE_HOSTNAME,- # ASSEMBLER_SERVICE_CERT_ARN, ASSEMBLER_ECS_MIN/MAX.- # TODO(P2/P3): the standalone SST app needs an sst toolchain in- # apps/assembler (or run via the root's sst). Wire the actual command once- # the toolchain + stage naming are settled.- run: |- echo "TODO: npx sst deploy --stage ${{ inputs.stage }}"- echo "Scaffold only — filling DECISION env + sst toolchain is the human deploy step."- exit 1+ IMAGE_TAG: ${{ github.sha }}+ STAGE: ${{ inputs.stage }}+ run: pnpm --filter ci ci:assemblerdiff --git a/ci/package.json b/ci/package.jsonindex 71e077d29c..f59898a4e0 100644--- a/ci/package.json+++ b/ci/package.json@@ -12,6 +12,7 @@"scripts": {"ci:migrations": "tsx src/migrations.ts","ci:deploy": "tsx src/deploy.ts",+ "ci:assembler": "tsx src/assembler.ts","ci:jobs": "tsx src/jobs.ts","ci:upload-backup-templates": "tsx src/upload-backup-templates.ts","test": "echo \"no tests\""diff --git a/ci/src/assembler.ts b/ci/src/assembler.tsnew file mode 100644index 0000000000..583eab401c--- /dev/null+++ b/ci/src/assembler.ts@@ -0,0 +1,115 @@+import { $ } from "execa";++import { client } from "./client";+import type { Workspace } from "./deploy";++// Deploys the assembler stack (apps/assembler/sst.config.ts) per workspace:+// one Lambda + API Gateway (plus optional ECS overflow) in each workspace's+// AWS account. Gated on the `assembler` column ALONE — independent of `aws`+// (which means "deploy ERP/MES via SST/ECS", i.e. GovCloud/ITAR). The main+// carbon.ms cloud runs its apps on Vercel (aws unset) but still wants the+// assembler in AWS, so the assembler must not depend on the `aws` flag. A row+// opts in by setting `assembler = true` plus its own aws_account_id / aws_region+// / redis_url — without turning on `aws`.++async function deploy(): Promise<void> {+ console.log("✅ 🌱 Starting assembler deployment");++ const imageTag = process.env.IMAGE_TAG;+ if (!imageTag) {+ console.error("🔴 🍳 Missing IMAGE_TAG environment variable");+ process.exit(1);+ }+ console.log(`✅ 🏷️ Using image tag: ${imageTag}`);++ const stage = process.env.STAGE ?? "prod";++ const { data: workspaces, error } = await client+ .from("workspaces")+ .select("*");++ if (error) {+ console.error("🔴 🍳 Failed to fetch workspaces", error);+ process.exit(1);+ }++ let hasErrors = false;++ for await (const workspace of workspaces as Workspace[]) {+ const {+ id,+ assembler,+ aws_account_id,+ aws_region,+ assembler_api_key,+ cert_arn_assembler,+ assembler_domain,+ redis_url,+ } = workspace;++ if (!assembler) {+ continue;+ }++ if (!aws_account_id) {+ console.log(`🔴 🍳 Missing AWS account id for ${id}`);+ continue;+ }+ if (!aws_region) {+ console.log(`🔴 🍳 Missing AWS region for ${id}`);+ continue;+ }+ if (!assembler_api_key) {+ console.log(`🔴 🍳 Missing assembler API key for ${id}`);+ continue;+ }++ // Reuses the workspace app redis as the assembler job store — must be+ // reachable from Lambda over the public internet.+ if (!redis_url) {+ console.log(`🔴 🍳 Missing Redis URL for ${id}`);+ continue;+ }++ console.log(`✅ 🔑 Setting up assembler environment for ${id}`);++ const $$ = $({+ // @ts-ignore+ env: {+ AWS_ACCOUNT_ID: aws_account_id,+ AWS_REGION: aws_region,+ IMAGE_TAG: imageTag,+ ASSEMBLER_SERVICE_API_KEY: assembler_api_key,+ REDIS_URL: redis_url,+ // Optional — enables the custom domain when set (else the raw+ // execute-api URL; sst.config.ts defaults the host to assembler.carbon.ms).+ ASSEMBLER_CERT_ARN: cert_arn_assembler ?? undefined,+ ASSEMBLER_DOMAIN: assembler_domain ?? undefined,+ },+ // Run SST from the assembler app where its sst.config.ts is located+ cwd: "../apps/assembler",+ stdio: "inherit",+ });++ try {+ console.log(`🚀 🐓 Deploying assembler for ${id} with SST`);+ await $$`npx --yes [email protected] deploy --stage ${stage}`;+ console.log(`✅ 🍗 Successfully deployed assembler for ${id}`);+ } catch (error) {+ console.error(`🔴 🍳 Failed to deploy assembler for ${id}`, error);+ hasErrors = true;+ }+ }++ if (hasErrors) {+ console.error("🔴 Assembler deployment completed with errors");+ process.exit(1);+ }++ console.log("✅ All assembler deployments completed successfully");+}++deploy().catch((error) => {+ console.error("🔴 Unexpected error during assembler deployment", error);+ process.exit(1);+});diff --git a/ci/src/deploy.ts b/ci/src/deploy.tsindex aa14204742..1532a0c56e 100644--- a/ci/src/deploy.ts+++ b/ci/src/deploy.ts@@ -14,6 +14,13 @@ export type Workspace = {aws_account_id: string | null;aws_region: string | null;+ // Assembler (CAD -> GLB) Configuration — deployed separately by+ // ci/src/assembler.ts, gated on `assembler`.+ assembler: boolean;+ assembler_api_key: string | null;+ cert_arn_assembler: string | null;+ assembler_domain: string | null;+// Domain Configurationdomain_name: string | null;cert_arn_erp: string | null;