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.

ci: sst deploy

Brad Barbin72c82ef1d20c
diff --git a/ci/src/deploy.ts b/ci/src/deploy.ts
index bd54a4286e..ba928b01b2 100644
--- a/ci/src/deploy.ts
+++ b/ci/src/deploy.ts
@@ -8,14 +8,15 @@ export type Workspace = {
slug: string;
active: boolean;
seeded: boolean;
+
// AWS Configuration
aws_account_id: string | null;
aws_region: string | null;
-
+
// Domain Configuration
domain_name: string | null;
domain_cert_arn: string | null;
-
+
// Database Configuration
connection_string: string | null;
database_url: string | null;
@@ -25,11 +26,6 @@ export type Workspace = {
database_password: string | null;
jwt_key: string | null;
service_role_key: string | null;
-
- // Application Environment Variables
- autodesk_bucket_name: string | null;
- autodesk_client_id: string | null;
- autodesk_client_secret: string | null;
carbon_edition: string | null;
cloudflare_turnstile_secret_key: string | null;
cloudflare_turnstile_site_key: string | null;
@@ -42,14 +38,25 @@ export type Workspace = {
posthog_project_public_key: string | null;
resend_api_key: string | null;
session_secret: string | null;
+ slack_bot_token: string | null;
+ slack_client_id: string | null;
+ slack_client_secret: string | null;
+ slack_oauth_redirect_url: string | null;
+ slack_signing_secret: string | null;
+ slack_state_secret: string | null;
+ stripe_bypass_company_ids: string | null;
+ stripe_secret_key: string | null;
+ stripe_webhook_secret: string | null;
trigger_api_url: string | null;
trigger_project_id: string | null;
trigger_secret_key: string | null;
upstash_redis_rest_token: string | null;
upstash_redis_rest_url: string | null;
+ vercel_env: string | null;
+ vercel_url: string | null;
};
-async function migrate(): Promise<void> {
+async function deploy(): Promise<void> {
console.log("✅ 🌱 Starting deployment");
const { data: workspaces, error } = await client
@@ -63,9 +70,6 @@ async function migrate(): Promise<void> {
console.log("✅ 🛩️ Successfully retreived workspaces");
- console.log("👯‍♀️ Copying supabase folder");
- await $`cp -r ../packages/database/supabase .`;
-
for await (const workspace of workspaces as Workspace[]) {
try {
console.log(`✅ 🥚 Migrating ${workspace.id}`);
@@ -80,9 +84,6 @@ async function migrate(): Promise<void> {
access_token,
anon_key,
service_role_key,
- autodesk_bucket_name,
- autodesk_client_id,
- autodesk_client_secret,
carbon_edition,
cloudflare_turnstile_secret_key,
cloudflare_turnstile_site_key,
@@ -96,8 +97,8 @@ async function migrate(): Promise<void> {
resend_api_key,
session_secret,
slack_bot_token,
- slack_client_id,
slack_client_secret,
+ slack_client_id,
slack_oauth_redirect_url,
slack_signing_secret,
slack_state_secret,
@@ -111,7 +112,6 @@ async function migrate(): Promise<void> {
upstash_redis_rest_url,
vercel_env,
vercel_url,
-
} = workspace;
if (!aws_account_id) {
@@ -164,36 +164,15 @@ async function migrate(): Promise<void> {
continue;
}
- if (!autodesk_bucket_name) {
- console.log(`🔴🍳 Missing autodesk bucket name for ${workspace.id}`);
- continue;
- }
-
- if (!autodesk_client_id) {
- console.log(`🔴🍳 Missing autodesk client id for ${workspace.id}`);
- continue;
- }
-
- if (!autodesk_client_secret) {
- console.log(`🔴🍳 Missing autodesk client secret for ${workspace.id}`);
- continue;
- }
-
- if (!carbon_edition) {
-
- if (!cloudflare_turnstile_secret_key) {
- console.log(`🔴🍳 Missing cloudflare turnstile secret key for ${workspace.id}`);
- continue;
- }
-
- if (!cloudflare_turnstile_site_key) {
-
if (!controlled_environment) {
console.log(`🔴🍳 Missing controlled environment for ${workspace.id}`);
continue;
}
if (!exchange_rates_api_key) {
+ console.log(`🔴🍳 Missing exchange rates api key for ${workspace.id}`);
+ continue;
+ }
if (!novu_application_id) {
console.log(`🔴🍳 Missing novu application id for ${workspace.id}`);
@@ -201,19 +180,24 @@ async function migrate(): Promise<void> {
}
if (!novu_secret_key) {
+ console.log(`🔴🍳 Missing novu secret key for ${workspace.id}`);
+ continue;
+ }
if (!openai_api_key) {
console.log(`🔴🍳 Missing openai api key for ${workspace.id}`);
continue;
}
- if (!posthog_api_host) {
+ if (!posthog_api_host) {
console.log(`🔴🍳 Missing posthog api host for ${workspace.id}`);
continue;
}
if (!posthog_project_public_key) {
- console.log(`🔴🍳 Missing posthog project public key for ${workspace.id}`);
+ console.log(
+ `🔴🍳 Missing posthog project public key for ${workspace.id}`
+ );
continue;
}
@@ -227,111 +211,96 @@ async function migrate(): Promise<void> {
continue;
}
- if (!slack_bot_token) {
- console.log(`🔴🍳 Missing slack bot token for ${workspace.id}`);
- continue;
- }
-
- if (!slack_client_id) {
- console.log(`🔴🍳 Missing slack client id for ${workspace.id}`);
- continue;
- }
-
- if (!slack_client_secret) {
- console.log(`🔴🍳 Missing slack client secret for ${workspace.id}`);
- continue;
- }
-
- if (!slack_oauth_redirect_url) {
- console.log(`🔴🍳 Missing slack oauth redirect url for ${workspace.id}`);
+ if (!trigger_api_url) {
+ console.log(`🔴🍳 Missing trigger api url for ${workspace.id}`);
continue;
}
- if (!slack_signing_secret) {
- console.log(`🔴🍳 Missing slack signing secret for ${workspace.id}`);
+ if (!trigger_project_id) {
+ console.log(`🔴🍳 Missing trigger project id for ${workspace.id}`);
continue;
}
- if (!slack_state_secret) {
- console.log(`🔴🍳 Missing slack state secret for ${workspace.id}`);
+ if (!trigger_secret_key) {
+ console.log(`🔴🍳 Missing trigger secret key for ${workspace.id}`);
continue;
}
- if (!stripe_bypass_company_ids) {
- console.log(`🔴🍳 Missing stripe bypass company ids for ${workspace.id}`);
+ if (!upstash_redis_rest_token) {
+ console.log(
+ `🔴🍳 Missing upstash redis rest token for ${workspace.id}`
+ );
continue;
}
- if (!stripe_secret_key) {
- console.log(`🔴🍳 Missing stripe secret key for ${workspace.id}`);
+ if (!upstash_redis_rest_url) {
+ console.log(`🔴🍳 Missing upstash redis rest url for ${workspace.id}`);
continue;
}
- if (!stripe_webhook_secret) {
- console.log(`🔴🍳 Missing stripe webhook secret for ${workspace.id}`);
+ if (!vercel_url) {
+ console.log(`🔴🍳 Missing vercel url for ${workspace.id}`);
continue;
}
- if (!trigger_api_url) {
-
console.log(`✅ 🔑 Setting up environment for ${workspace.id}`);
- let $$ = $({
+ const $$ = $({
+ // @ts-ignore
env: {
- SUPABASE_ACCESS_TOKEN:
- access_token === null ? SUPABASE_ACCESS_TOKEN : access_token,
- SUPABASE_URL: database_url ?? undefined,
- SUPABASE_DB_PASSWORD: database_password ?? undefined,
- SUPABASE_PROJECT_ID: project_id ?? undefined,
- SUPABASE_ANON_KEY: anon_key ?? undefined,
- SUPABASE_SERVICE_ROLE_KEY: service_role_key ?? undefined,
- SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_ID,
- SUPABASE_AUTH_EXTERNAL_GOOGLE_CLIENT_SECRET,
- SUPABASE_AUTH_EXTERNAL_GOOGLE_REDIRECT_URI,
+ AWS_ACCOUNT_ID: aws_account_id,
+ AWS_REGION: aws_region,
+ CARBON_EDITION: carbon_edition ?? "enterprise",
+ CLOUDFLARE_TURNSTILE_SECRET_KEY: cloudflare_turnstile_secret_key,
+ CLOUDFLARE_TURNSTILE_SITE_KEY: cloudflare_turnstile_site_key,
+ CONTROLLED_ENVIRONMENT: controlled_environment,
+ DOMAIN: domain_name,
+ EXCHANGE_RATES_API_KEY: exchange_rates_api_key,
+ NOVU_APPLICATION_ID: novu_application_id,
+ NOVU_SECRET_KEY: novu_secret_key,
+ OPENAI_API_KEY: openai_api_key,
+ POSTHOG_API_HOST: posthog_api_host,
+ POSTHOG_PROJECT_PUBLIC_KEY: posthog_project_public_key,
+ RESEND_API_KEY: resend_api_key,
+ SESSION_SECRET: session_secret,
+ SLACK_BOT_TOKEN: slack_bot_token,
+ SLACK_CLIENT_ID: slack_client_id,
+ SLACK_CLIENT_SECRET: slack_client_secret,
+ SLACK_OAUTH_REDIRECT_URL: slack_oauth_redirect_url,
+ SLACK_SIGNING_SECRET: slack_signing_secret,
+ SLACK_STATE_SECRET: slack_state_secret,
+ STRIPE_BYPASS_COMPANY_IDS: stripe_bypass_company_ids,
+ STRIPE_SECRET_KEY: stripe_secret_key,
+ STRIPE_WEBHOOK_SECRET: stripe_webhook_secret,
+ SUPABASE_ANON_KEY: anon_key,
+ SUPABASE_ANON_PUBLIC: anon_key,
+ SUPABASE_API_URL: database_url,
+ SUPABASE_SERVICE_ROLE: service_role_key,
+ SUPABASE_SERVICE_ROLE_KEY: service_role_key,
+ SUPABASE_URL: database_url,
+ TRIGGER_API_URL: trigger_api_url,
+ TRIGGER_PROJECT_ID: trigger_project_id,
+ TRIGGER_SECRET_KEY: trigger_secret_key,
+ UPSTASH_REDIS_REST_TOKEN: upstash_redis_rest_token,
+ UPSTASH_REDIS_REST_URL: upstash_redis_rest_url,
+ VERCEL_ENV: vercel_env ?? "production",
+ VERCEL_URL: vercel_url,
},
- cwd: "supabase",
+ // Run SST from the repository root where sst.config.ts is located
+ cwd: "..",
});
- if (project_id) {
- await $$`supabase link`;
- }
-
- console.log(`✅ 🐣 Starting migrations for ${workspace.id}`);
+ console.log(
+ `🚀 🧰 Deploying infrastructure for ${workspace.id} with SST`
+ );
- if (connection_string && connection_string.startsWith("postgresql://")) {
- await $$`supabase db push --db-url ${connection_string} --include-all`;
- } else {
- await $$`supabase db push --include-all`;
- console.log(`✅ 🐣 Starting deployments for ${workspace.id}`);
- await $$`supabase functions deploy`;
- }
-
- if (!workspace.seeded) {
- try {
- console.log(`✅ 🌱 Seeding ${workspace.id}`);
- await $$`tsx ../../packages/database/src/seed.ts`;
- const { error } = await client
- .from("workspaces")
- .update({ seeded: true })
- .eq("id", workspace.id);
-
- if (error) {
- throw new Error(
- `🔴 🍳 Failed to mark ${workspace.id} as seeded: ${error.message}`
- );
- }
-
- // TODO: run the seed.sql file
- } catch (e) {
- console.error(`🔴 🍳 Failed to seed ${workspace.id}`, e);
- }
- }
+ await $$`npx --yes sst deploy --stage prod`;
- console.log(`✅ 🐓 Successfully migrated ${workspace.id}`);
+ console.log(`✅ 🐓 Successfully deployed ${workspace.id}`);
} catch (error) {
- console.error(`🔴 🍳 Failed to migrate ${workspace.id}`, error);
+ console.error(`🔴 🍳 Failed to deploy ${workspace.id}`, error);
}
}
}
-migrate();
+deploy();
diff --git a/ci/src/migrations.ts b/ci/src/migrations.ts
index 1dd8c0d293..ca7d4e9e80 100644
--- a/ci/src/migrations.ts
+++ b/ci/src/migrations.ts
@@ -61,6 +61,7 @@ async function migrate(): Promise<void> {
console.log(`✅ 🔑 Setting up environment for ${workspace.id}`);
let $$ = $({
+ // @ts-ignore
env: {
SUPABASE_ACCESS_TOKEN:
access_token === null ? SUPABASE_ACCESS_TOKEN : access_token,