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
perf(deploy): the deploy uses the images build-images.yml publishes
Sidwebworks094d6d0df459
diff --git a/.claude/rules/sst-deployment-infrastructure.md b/.claude/rules/sst-deployment-infrastructure.mdindex 869e307b90..f73c04f648 100644--- a/.claude/rules/sst-deployment-infrastructure.md+++ b/.claude/rules/sst-deployment-infrastructure.md@@ -25,7 +25,7 @@ alternative deployment, not a replacement. Both build from the same root `Docker`forceUpgrade: "v2"`).- Two Fargate services on the cluster, each 2 vCPU / 4 GB:- **`CarbonERPService`** — image- `${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/carbon/erp:${IMAGE_TAG}`,+ `${IMAGE_REGISTRY}/carbon/erp:${IMAGE_TAG}` (see Images below),domain `process.env.URL_ERP ?? "itar.carbon.ms"`, cert `CERT_ARN_ERP`.- **`CarbonMESService`** — same shape, `carbon/mes` image, domain`process.env.URL_MES ?? "mes.itar.carbon.ms"`, cert `CERT_ARN_MES`.@@ -47,20 +47,19 @@ alternative deployment, not a replacement. Both build from the same root `Docker- `sst-env.d.ts` files (repo root, `ci/`, per app/package) are SST-generated typestubs; do not hand-edit.-## Build → push (`.github/workflows/deploy.yml`, job `build`)-Triggers on push to `main` touching `apps/erp/**`, `apps/mes/**`, `packages/**`-(or manual `workflow_dispatch`). Matrix over `[erp, mes]`:-- `aws-actions/configure-aws-credentials` + `amazon-ecr-login`.-- `docker/build-push-action` builds the **single root `Dockerfile`** with- `--build-arg APP=<erp|mes>` (the old per-app `apps/{erp,mes}/Dockerfile` claim is- stale — there is now ONE Dockerfile: `deps`→`build` (`pnpm run build:${APP}`)→- `runner` on `node:22-slim`).-- Pushes `carbon/<app>:latest` **and** `carbon/<app>:${{ github.sha }}` to ECR,- `platforms: linux/amd64`. No layer cache: this workflow only runs when- `apps/` or `packages/` changed, which invalidates every layer after the base, so- exporting one cost about two minutes a job and was never read back.--## Deploy (job `deploy`, needs `build`)+## Images (`.github/workflows/deploy.yml`, job `images`)+Triggers on push to `main` touching `apps/erp/**`, `apps/mes/**`, `packages/**`,+`docs/content/**` (or manual `workflow_dispatch`).+- `deploy.yml` builds nothing. `build-images.yml` runs on the same push and+ publishes `carbon/erp` and `carbon/mes` tagged with the commit sha to+ `vars.IMAGE_REGISTRY`; the `images` job polls until both tags exist (30 minute+ limit), so a failed image build fails the deploy.+- The services pull `${IMAGE_REGISTRY}/carbon/<app>:${IMAGE_TAG}`. With+ `IMAGE_REGISTRY` unset `sst.config.ts` falls back to the workspace account's+ private ECR (`${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com`), which is+ what a deployment that builds its own images uses.++## Deploy (job `deploy`, needs `images`)- Sets `IMAGE_TAG: ${{ github.sha }}` (this is what `sst.config.ts` interpolatesinto the ECR image ref — so prod runs the exact SHA, not `:latest`).- Installs Pulumi `3.212.0` (SST v3 uses Pulumi under the hood), `pnpm installdiff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.ymlindex b37fa06b98..fb78b487cc 100644--- a/.github/workflows/deploy.yml+++ b/.github/workflows/deploy.yml@@ -11,53 +11,35 @@ on:- "docs/content/**"workflow_dispatch:jobs:- build:- name: Build+ # The images come from build-images.yml, which runs on the same push. This+ # waits for it rather than building them a second time.+ images:+ name: Wait for imagesruns-on: ubuntu-latest- strategy:- matrix:- app: [erp, mes]-+ timeout-minutes: 30steps:- - name: Checkout code- uses: actions/checkout@v4-- - name: Configure AWS credentials- uses: aws-actions/configure-aws-credentials@v4- with:- aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}- aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}- aws-region: ${{ secrets.AWS_REGION }}-- - name: Login to Amazon ECR- id: login-ecr- uses: aws-actions/amazon-ecr-login@v2+ - uses: docker/setup-buildx-action@v3- - name: Set up Docker Buildx- uses: docker/setup-buildx-action@v3-- - name: Build and push Docker image- uses: docker/build-push-action@v5+ - name: Wait for carbon/erp and carbon/mesenv:- AWS_REGION: ${{ secrets.AWS_REGION }}- with:- build-args: |- APP=${{ matrix.app }}- NODE_OPTIONS=--max-old-space-size=4096- context: .- file: ./Dockerfile- push: true- tags: |- ${{ steps.login-ecr.outputs.registry }}/carbon/${{ matrix.app }}:latest- ${{ steps.login-ecr.outputs.registry }}/carbon/${{ matrix.app }}:${{ github.sha }}- platforms: linux/amd64+ REGISTRY: ${{ vars.IMAGE_REGISTRY }}+ SHA: ${{ github.sha }}+ run: |+ [ -n "$REGISTRY" ] || { echo "vars.IMAGE_REGISTRY is not set" >&2; exit 1; }+ for app in erp mes; do+ until docker buildx imagetools inspect "$REGISTRY/carbon/$app:$SHA" >/dev/null 2>&1; do+ echo "waiting for $REGISTRY/carbon/$app:$SHA"+ sleep 15+ done+ donedeploy:name: Deployruns-on: ubuntu-latest- needs: build+ needs: imagesenv:+ IMAGE_REGISTRY: ${{ vars.IMAGE_REGISTRY }}IMAGE_TAG: ${{ github.sha }}SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}diff --git a/sst.config.ts b/sst.config.tsindex c58feab8d7..34ce032192 100644--- a/sst.config.ts+++ b/sst.config.ts@@ -15,6 +15,10 @@ export default $config({};},async run() {+ // Where build-images.yml publishes; unset, the account's own private ECR.+ const imageRegistry =+ process.env.IMAGE_REGISTRY ||+ `${process.env.AWS_ACCOUNT_ID}.dkr.ecr.${process.env.AWS_REGION}.amazonaws.com`;const vpc = new sst.aws.Vpc("CarbonVpc2");const cluster = new sst.aws.Cluster("CarbonCluster", {vpc,@@ -23,7 +27,7 @@ export default $config({const erp = cluster.addService("CarbonERPService", {cpu: "2 vCPU",memory: "4 GB",- image: `${process.env.AWS_ACCOUNT_ID}.dkr.ecr.${process.env.AWS_REGION}.amazonaws.com/carbon/erp:${process.env.IMAGE_TAG}`,+ image: `${imageRegistry}/carbon/erp:${process.env.IMAGE_TAG}`,loadBalancer: {domain: {name: process.env.URL_ERP ?? "itar.carbon.ms",@@ -135,7 +139,7 @@ export default $config({const mes = cluster.addService("CarbonMESService", {cpu: "2 vCPU",memory: "4 GB",- image: `${process.env.AWS_ACCOUNT_ID}.dkr.ecr.${process.env.AWS_REGION}.amazonaws.com/carbon/mes:${process.env.IMAGE_TAG}`,+ image: `${imageRegistry}/carbon/mes:${process.env.IMAGE_TAG}`,loadBalancer: {domain: {name: process.env.URL_MES ?? "mes.itar.carbon.ms",