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.

build: update healthchecks

Brad Barbinf278b69b2125
diff --git a/llm/cache/sst-deployment-infrastructure.md b/llm/cache/sst-deployment-infrastructure.md
index 559c95cbf8..e7efd964de 100644
--- a/llm/cache/sst-deployment-infrastructure.md
+++ b/llm/cache/sst-deployment-infrastructure.md
@@ -13,31 +13,36 @@ Carbon uses SST (Serverless Stack) for AWS infrastructure deployment and managem
The SST configuration deploys Carbon as containerized services on AWS using:
- **App Name**: `carbon`
- **Cloud Provider**: AWS (`home: "aws"`)
-- **Region**: `us-gov-east-1` (AWS GovCloud)
+- **Region**: Configured via `process.env.AWS_REGION` (typically `us-gov-east-1` for AWS GovCloud)
- **Removal Policy**: `retain` for production, `remove` for other stages
### Infrastructure Components
#### VPC and Cluster
-- **VPC**: `CarbonVpc` - Virtual Private Cloud for the application
-- **Cluster**: `CarbonCluster` - ECS cluster running on the VPC
+- **VPC**: `CarbonVpc2` - Virtual Private Cloud for the application
+- **Cluster**: `CarbonCluster` - ECS cluster running on the VPC with `forceUpgrade: "v2"`
#### Services
1. **CarbonERPService**
- - **Port Mapping**: External port 80 → Internal port 3000
- - **Dockerfile**: `apps/erp/Dockerfile`
- - **Context**: Root directory (`./`)
+ - **Image**: Pulls from ECR: `{AWS_ACCOUNT_ID}.dkr.ecr.us-gov-east-1.amazonaws.com/carbon/erp:latest`
+ - **Domain**: `itar.carbon.ms`
+ - **Port Mapping**: External port 443/HTTPS → Internal port 3000/HTTP (with 80→443 redirect)
+ - **Certificate**: Configured via `process.env.CERT_ARN_ERP`
+ - **Scaling**: Min 1, Max 10 tasks, 70% CPU / 80% memory utilization targets
2. **CarbonMESService**
- - **Port Mapping**: External port 80 → Internal port 3001
- - **Dockerfile**: `apps/mes/Dockerfile`
- - **Context**: Root directory (`./`)
+ - **Image**: Pulls from ECR: `{AWS_ACCOUNT_ID}.dkr.ecr.us-gov-east-1.amazonaws.com/carbon/mes:latest`
+ - **Domain**: `mes.itar.carbon.ms`
+ - **Port Mapping**: External port 443/HTTPS → Internal port 3000/HTTP (with 80→443 redirect)
+ - **Certificate**: Configured via `process.env.CERT_ARN_MES`
+ - **Scaling**: Min 1, Max 10 tasks, 70% CPU / 80% memory utilization targets
#### Security - Web Application Firewall (WAF)
-- **Rate Limiting**: 200 requests per IP
+- **Rate Limiting**: 1000 requests per IP (updated from 200)
- **AWS Managed Rules**: Uses `AWSManagedRulesCommonRuleSet`
- **Scope**: Regional (ALB protection)
- **Metrics**: CloudWatch monitoring enabled
+- **Configuration**: WAF ACL created but needs manual association with load balancer
### Environment Variables
@@ -69,16 +74,22 @@ Both ERP and MES services receive identical environment variable configurations
## Container Configuration
### ERP Application (`apps/erp/Dockerfile`)
-- **Base Image**: `node:20-alpine`
-- **Build Process**: Multi-stage build
-- **Port**: 3000
-- **Build Command**: `npx turbo run build --filter=./apps/erp`
+- **Base Image**: `node:20` (not alpine)
+- **Build Process**: Multi-stage build with 3 stages (deps, build, production)
+- **Port**: 3000 (exposed and used)
+- **Build Command**: `npx [email protected] run build --filter=./apps/erp`
+- **Working Directory**: `/repo/apps/erp`
+- **Start Command**: `npm run start`
+- **Environment**: `NODE_ENV=production`, `PORT=3000`
### MES Application (`apps/mes/Dockerfile`)
-- **Base Image**: `node:20-alpine`
-- **Build Process**: Multi-stage build
-- **Port**: 3001 (note: Dockerfile shows 3001 expose but ENV shows 3000)
-- **Build Command**: `npx turbo run build --filter=./apps/mes`
+- **Base Image**: `node:20` (not alpine)
+- **Build Process**: Multi-stage build with 3 stages (deps, build, production)
+- **Port**: 3001 exposed, but ENV PORT=3000 (actual runtime uses 3000)
+- **Build Command**: `npx [email protected] run build --filter=./apps/mes`
+- **Working Directory**: `/repo/apps/mes`
+- **Start Command**: `npm run start`
+- **Environment**: `NODE_ENV=production`, `PORT=3000`
## Generated Files
@@ -101,9 +112,59 @@ declare module "sst" {
- **SST Version**: `3.17.14` (listed in root `package.json`)
- **Deployment Scripts**: `turbo run deploy` command available
-## Current Branch Status
+## CI/CD Deployment Process
-The project is currently on branch `feat/sst-cluster` which suggests active development of the SST cluster infrastructure.
+### GitHub Actions Workflow
+
+**Location**: `.github/workflows/deploy.yml`
+
+The deployment process consists of two jobs:
+
+#### 1. Build Job
+- Runs in parallel for both `erp` and `mes` apps (matrix strategy)
+- Builds Docker images and pushes to Amazon ECR
+- Tags images with both `:latest` and `:{git-sha}`
+- Uses Docker BuildKit with GitHub Actions cache
+- Platform: `linux/amd64`
+
+#### 2. Deploy Job
+- Runs after build job completes
+- Installs dependencies in both root and `ci/` workspace
+- Executes: `npm run -w ci ci:deploy`
+- Runs `/ci/src/deploy.ts` which:
+ - Fetches workspace configurations from Supabase
+ - Sets up environment variables for each workspace
+ - Runs `npx --yes sst deploy --stage prod` for each workspace
+ - Skips the `app` workspace slug
+
+### Workspace-Based Deployment
+
+The deployment system supports multi-tenant deployments by:
+- Storing workspace configurations in a `workspaces` table in Supabase
+- Each workspace has its own AWS account, region, domain, certificates, and service credentials
+- The CI deployment script (`ci/src/deploy.ts`) iterates through active workspaces and deploys to each
+
+### Health Checks
+
+**Location**:
+- `/apps/erp/app/routes/_public+/health.tsx`
+- `/apps/mes/app/routes/_public+/health.tsx`
+
+Both apps have identical health check endpoints at `/health`:
+
+**Features**:
+- 5-second timeout protection
+- Lightweight database connectivity check (queries `attributeDataType` table with limit 1)
+- Returns JSON response with status, timestamp, and response time
+- Returns 200 OK on success, 500 on error
+- Used by ECS for container health checks
+
+**Recent Changes** (commit `14de78719`):
+- Added timeout protection to prevent health checks from hanging
+- Changed from selecting all columns to just `id` with `limit(1).single()`
+- Added JSON response format with timestamps and response times
+- Added auto-scaling configuration to SST services
+- Increased WAF rate limit from 200 to 1000 requests per IP
## Deploy Command
@@ -117,4 +178,7 @@ npm run deploy # Runs turbo run deploy
- The deployment targets AWS GovCloud (us-gov-east-1), indicating potential government/federal compliance requirements
- Both applications share the same environment variables, suggesting a shared configuration approach
- WAF protection is configured with rate limiting and AWS managed security rules
-- The infrastructure uses container-based deployment rather than serverless functions
\ No newline at end of file
+- The infrastructure uses container-based deployment rather than serverless functions
+- Docker images are built in CI and pushed to ECR, then SST deploys ECS services using those images
+- The system supports multi-workspace deployments for different tenants/environments
+- Autodesk integration variables are still present in config but the Autodesk code has been removed (see commits `f72d910ed`, `0186a54d2`)
\ No newline at end of file
diff --git a/sst.config.ts b/sst.config.ts
index 40c2d6ac11..1b4a5d9591 100644
--- a/sst.config.ts
+++ b/sst.config.ts
@@ -27,6 +27,26 @@ export default $config({
{ listen: "80/http", redirect: "443/https" },
{ listen: "443/https", forward: "3000/http" },
],
+ health: {
+ "3000/http": {
+ path: "/health",
+ healthyThreshold: 2,
+ unhealthyThreshold: 2,
+ timeout: "5 seconds",
+ interval: "10 seconds",
+ successCodes: "200",
+ },
+ },
+ },
+ health: {
+ command: [
+ "CMD-SHELL",
+ "curl -f http://localhost:3000/health || exit 1",
+ ],
+ interval: "10 seconds",
+ timeout: "5 seconds",
+ startPeriod: "60 seconds",
+ retries: 2,
},
scaling: {
min: 1,
@@ -90,6 +110,26 @@ export default $config({
{ listen: "80/http", redirect: "443/https" },
{ listen: "443/https", forward: "3000/http" },
],
+ health: {
+ "3000/http": {
+ path: "/health",
+ healthyThreshold: 2,
+ unhealthyThreshold: 2,
+ timeout: "5 seconds",
+ interval: "10 seconds",
+ successCodes: "200",
+ },
+ },
+ },
+ health: {
+ command: [
+ "CMD-SHELL",
+ "curl -f http://localhost:3000/health || exit 1",
+ ],
+ interval: "10 seconds",
+ timeout: "5 seconds",
+ startPeriod: "60 seconds",
+ retries: 2,
},
scaling: {
min: 1,