@mycompbox/compbox-mcp 1.21.7 → 1.21.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +317 -24
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -212,6 +212,15 @@ var init_deployment = __esm({
212
212
  }
213
213
  });
214
214
 
215
+ // ../shared/dist/types/database.js
216
+ var CLOUD_SQL_MONTHLY_ESTIMATE_USD;
217
+ var init_database = __esm({
218
+ "../shared/dist/types/database.js"() {
219
+ "use strict";
220
+ CLOUD_SQL_MONTHLY_ESTIMATE_USD = 10;
221
+ }
222
+ });
223
+
215
224
  // ../shared/dist/types/index.js
216
225
  var init_types = __esm({
217
226
  "../shared/dist/types/index.js"() {
@@ -228,6 +237,7 @@ var init_types = __esm({
228
237
  init_cloud();
229
238
  init_stack();
230
239
  init_deployment();
240
+ init_database();
231
241
  }
232
242
  });
233
243
 
@@ -548,6 +558,12 @@ var init_pxpipe = __esm({
548
558
  });
549
559
 
550
560
  // ../shared/dist/interview-definition.js
561
+ function normalizeDatabaseChoice(raw) {
562
+ if (typeof raw !== "string")
563
+ return void 0;
564
+ const candidate = raw.trim().toLowerCase().replace(/[\s-]+/g, "_");
565
+ return DATABASE_CHOICE_VALUES.includes(candidate) ? candidate : void 0;
566
+ }
551
567
  function interviewSectionKeys() {
552
568
  return INTERVIEW_DEFINITION.map((s) => s.key);
553
569
  }
@@ -568,7 +584,7 @@ function buildInterviewSystemPrompt(definition = INTERVIEW_DEFINITION, seedConte
568
584
  const requiredSections = definition.filter((s) => s.required);
569
585
  const optionalSections = definition.filter((s) => !s.required);
570
586
  const renderSection2 = (s) => {
571
- const tag = s.required ? "REQUIRED" : "OPTIONAL \u2014 ask, but the user may decline";
587
+ const tag = s.required ? "REQUIRED" : s.askOnlyWhen ? `OPTIONAL \u2014 ask ONLY if ${s.askOnlyWhen}` : "OPTIONAL \u2014 ask, but the user may decline";
572
588
  const followUps = s.followUps.map((q) => ` - ${q}`).join("\n");
573
589
  return `- ${s.title} (${tag}) [json keys: ${s.fields.join(", ")}]
574
590
  ${s.purpose}
@@ -582,7 +598,7 @@ ${followUps}`;
582
598
  const completionShape = completionKeys.map((k) => `"${k}": "..."`).join(", ");
583
599
  const base = `You are the CompBox request-formulator, interviewing an employee to turn their idea into a well-formed Epic Request. Ask exactly ONE short, focused question at a time \u2014 never multiple questions in one message, never preamble or explanation.
584
600
 
585
- Work through these interview sections in order. Cover EVERY required section; for optional sections, ask about them too, but if the employee has nothing to add or declines, move on and leave that field out (never invent or pad it):
601
+ Work through these interview sections in order. Cover EVERY required section; for optional sections, ask about them too, but if the employee has nothing to add or declines, move on and leave that field out (never invent or pad it). A section marked "ask ONLY if" is conditional: when its condition does not hold, skip it without asking and leave its fields out:
586
602
 
587
603
  REQUIRED sections (an Epic Request cannot omit these):
588
604
  ${requiredSections.map(renderSection2).join("\n")}
@@ -637,10 +653,11 @@ function interviewFieldKeysFor(definition) {
637
653
  }
638
654
  return out;
639
655
  }
640
- var INTERVIEW_DEFINITION, INTERVIEW_FIELD_MIN_WORDS;
656
+ var DATABASE_CHOICE_VALUES, INTERVIEW_DEFINITION, INTERVIEW_FIELD_MIN_WORDS;
641
657
  var init_interview_definition = __esm({
642
658
  "../shared/dist/interview-definition.js"() {
643
659
  "use strict";
660
+ DATABASE_CHOICE_VALUES = ["free_hosted", "cloud_paid", "existing", "none"];
644
661
  INTERVIEW_DEFINITION = [
645
662
  {
646
663
  key: "problemStatement",
@@ -727,6 +744,17 @@ var init_interview_definition = __esm({
727
744
  "Why were those alternatives not chosen?"
728
745
  ],
729
746
  fields: ["alternatives"]
747
+ },
748
+ {
749
+ key: "database",
750
+ title: "Database",
751
+ purpose: "Record what kind of database the work should use, as databaseChoice set to exactly one of: free_hosted, cloud_paid, existing, none. Put any extra detail the employee gives in databaseNote. Never ask for, suggest, or record credentials, connection strings, or a specific vendor.",
752
+ required: false,
753
+ followUps: [
754
+ "Will this need a database: a free hosted one, a paid cloud one, an existing one your team already has, or none?"
755
+ ],
756
+ fields: ["databaseChoice", "databaseNote"],
757
+ askOnlyWhen: "the idea involves storing or persisting data. Ask this at most once, and skip it entirely for ideas that store nothing"
730
758
  }
731
759
  ];
732
760
  INTERVIEW_FIELD_MIN_WORDS = {
@@ -826,6 +854,9 @@ function toDraft(parsed) {
826
854
  draft[key] = raw;
827
855
  }
828
856
  }
857
+ const databaseChoice = normalizeDatabaseChoice(parsed.databaseChoice);
858
+ if (databaseChoice)
859
+ draft.databaseChoice = databaseChoice;
829
860
  return draft;
830
861
  }
831
862
  function extractCompletionJson(text) {
@@ -856,13 +887,15 @@ var TARGET_COMPLIANCE_TIER, OPTIONAL_DRAFT_KEYS, COMPLETION_REPAIR_INSTRUCTION;
856
887
  var init_interview_completion = __esm({
857
888
  "../shared/dist/interview-completion.js"() {
858
889
  "use strict";
890
+ init_interview_definition();
859
891
  TARGET_COMPLIANCE_TIER = "pass";
860
892
  OPTIONAL_DRAFT_KEYS = [
861
893
  "successMetrics",
862
894
  "targetAudience",
863
895
  "alternatives",
864
896
  "dependencies",
865
- "estimatedEffort"
897
+ "estimatedEffort",
898
+ "databaseNote"
866
899
  ];
867
900
  COMPLETION_REPAIR_INSTRUCTION = 'Your last message looked like a completion but I could NOT parse it as a valid JSON object with all required fields. Re-emit ONLY a single valid JSON object inside a ```json code fence \u2014 no other text \u2014 with every string value properly escaped (escape any internal double-quotes as \\" and any line breaks as \\n), and make sure title, problemStatement, proposedSolution, impactAssessment, and description are all present and non-empty:\n```json\n{"done": true, "title": "...", "problemStatement": "...", "proposedSolution": "...", "impactAssessment": "...", "description": "..."}\n```';
868
901
  }
@@ -1153,8 +1186,7 @@ REGION=${input.region}
1153
1186
  SA=${gcpServiceAccountEmail(input.projectId)}
1154
1187
 
1155
1188
  gcloud config set project "$PROJECT"
1156
- gcloud services enable run.googleapis.com artifactregistry.googleapis.com iam.googleapis.com \\
1157
- iamcredentials.googleapis.com sts.googleapis.com cloudresourcemanager.googleapis.com
1189
+ gcloud services enable ${GCP_SERVICES.join(" ")}
1158
1190
  NUMBER=$(gcloud projects describe "$PROJECT" --format='value(projectNumber)')
1159
1191
 
1160
1192
  # The account deploys run as.
@@ -1163,6 +1195,16 @@ gcloud iam service-accounts describe "$SA" >/dev/null 2>&1 || \\
1163
1195
  for ROLE in ${GCP_DEPLOY_ROLES.join(" ")}; do
1164
1196
  gcloud projects add-iam-policy-binding "$PROJECT" --member="serviceAccount:$SA" --role="$ROLE" --condition=None --quiet >/dev/null
1165
1197
  done
1198
+ # Lets deploys grant Cloud SQL Client to an environment's runtime account, and nothing else.
1199
+ CONDITION=$(mktemp)
1200
+ cat > "$CONDITION" <<'EOF'
1201
+ title: ${GCP_DEPLOY_CONDITIONAL_ROLE.condition.title}
1202
+ description: ${GCP_DEPLOY_CONDITIONAL_ROLE.condition.description}
1203
+ expression: "${GCP_DEPLOY_CONDITIONAL_ROLE.condition.expression}"
1204
+ EOF
1205
+ gcloud projects add-iam-policy-binding "$PROJECT" --member="serviceAccount:$SA" \\
1206
+ --role="${GCP_DEPLOY_CONDITIONAL_ROLE.role}" --condition-from-file="$CONDITION" --quiet >/dev/null
1207
+ rm -f "$CONDITION"
1166
1208
 
1167
1209
  # Trust GitHub Actions from your GitHub only: ${owners.join(", ")}.
1168
1210
  gcloud iam workload-identity-pools describe ${GCP_IDENTITY_POOL} --location=global >/dev/null 2>&1 || \\
@@ -1186,7 +1228,7 @@ echo "Done. Your project number is: $NUMBER"
1186
1228
  echo "Paste it into CompBox to finish."
1187
1229
  `;
1188
1230
  }
1189
- var GCP_REGIONS, GCP_DEPLOY_ACCOUNT, GCP_IDENTITY_POOL, GCP_IDENTITY_PROVIDER, GCP_DEPLOY_ROLES, PROJECT_ID, PROJECT_NUMBER, GITHUB_LOGIN, GCP_CONNECT_STEPS, GCP_CONNECT_STEP_LABELS;
1231
+ var GCP_REGIONS, GCP_DEPLOY_ACCOUNT, GCP_IDENTITY_POOL, GCP_IDENTITY_PROVIDER, GCP_DEPLOY_ROLES, GCP_SERVICES, GCP_DEPLOY_CONDITIONAL_ROLE, PROJECT_ID, PROJECT_NUMBER, GITHUB_LOGIN, GCP_CONNECT_STEPS, GCP_CONNECT_STEP_LABELS;
1190
1232
  var init_cloud_setup = __esm({
1191
1233
  "../shared/dist/cloud-setup.js"() {
1192
1234
  "use strict";
@@ -1215,8 +1257,31 @@ var init_cloud_setup = __esm({
1215
1257
  "roles/iam.serviceAccountUser",
1216
1258
  "roles/iam.serviceAccountAdmin",
1217
1259
  "roles/storage.admin",
1218
- "roles/serviceusage.serviceUsageConsumer"
1260
+ "roles/serviceusage.serviceUsageConsumer",
1261
+ // Keeps each environment's DATABASE_URL in Secret Manager and lets its runtime account read it.
1262
+ "roles/secretmanager.admin",
1263
+ // Creates each environment's Cloud SQL database (ENG-316) and connects the migrate job to it.
1264
+ "roles/cloudsql.admin"
1219
1265
  ];
1266
+ GCP_SERVICES = [
1267
+ "run.googleapis.com",
1268
+ "artifactregistry.googleapis.com",
1269
+ "iam.googleapis.com",
1270
+ "iamcredentials.googleapis.com",
1271
+ "sts.googleapis.com",
1272
+ "cloudresourcemanager.googleapis.com",
1273
+ "storage.googleapis.com",
1274
+ "secretmanager.googleapis.com",
1275
+ "sqladmin.googleapis.com"
1276
+ ];
1277
+ GCP_DEPLOY_CONDITIONAL_ROLE = {
1278
+ role: "roles/resourcemanager.projectIamAdmin",
1279
+ condition: {
1280
+ title: "compbox-cloudsql-client-only",
1281
+ description: "CompBox deploys may only grant Cloud SQL Client.",
1282
+ expression: "api.getAttribute('iam.googleapis.com/modifiedGrantsByRole', []).hasOnly(['roles/cloudsql.client'])"
1283
+ }
1284
+ };
1220
1285
  PROJECT_ID = /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/;
1221
1286
  PROJECT_NUMBER = /^\d{6,20}$/;
1222
1287
  GITHUB_LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;
@@ -1655,11 +1720,21 @@ function stackAppName(repoName) {
1655
1720
  slug = `app${slug}`.slice(0, 20);
1656
1721
  return slug;
1657
1722
  }
1723
+ function cloudSqlInstanceName(app, environment) {
1724
+ return `${app}-${environment}-db`;
1725
+ }
1726
+ function databaseSecretName(app, environment, database) {
1727
+ return `${app}-${environment}-${database === "cloudsql" ? "cloudsql-url" : "database-url"}`;
1728
+ }
1658
1729
  function envSettings(env) {
1659
1730
  return env === "prod" ? { min: 0, max: 10 } : { min: 0, max: 2 };
1660
1731
  }
1661
1732
  function buildStackFiles(input) {
1662
1733
  const { tier, app, defaultBranch, cloud } = input;
1734
+ const cloudSql = input.database === "cloudsql";
1735
+ if (input.database != null && !cloudSql)
1736
+ throw new Error("Not a supported database.");
1737
+ const secretSuffix = cloudSql ? "cloudsql-url" : "database-url";
1663
1738
  if (!APP.test(app))
1664
1739
  throw new Error("Not a valid app name.");
1665
1740
  if (!BRANCH.test(defaultBranch))
@@ -1676,7 +1751,11 @@ terraform {
1676
1751
  google = {
1677
1752
  source = "hashicorp/google"
1678
1753
  version = "~> 6.0"
1679
- }
1754
+ }${cloudSql ? `
1755
+ random = {
1756
+ source = "hashicorp/random"
1757
+ version = "~> 3.6"
1758
+ }` : ""}
1680
1759
  }
1681
1760
  # Bucket and prefix are passed by the deploy workflow.
1682
1761
  backend "gcs" {}
@@ -1760,10 +1839,20 @@ resource "google_cloud_run_v2_service" "app" {
1760
1839
  }
1761
1840
  }
1762
1841
 
1763
- # Deploys change the image; Terraform owns everything else.
1842
+ ${cloudSql ? ` # Deploys set the image, DATABASE_URL and the Cloud SQL connection; Terraform owns everything else.
1843
+ lifecycle {
1844
+ ignore_changes = [
1845
+ template[0].containers[0].image,
1846
+ template[0].containers[0].env,
1847
+ template[0].containers[0].volume_mounts,
1848
+ template[0].volumes,
1849
+ client,
1850
+ client_version,
1851
+ ]
1852
+ }` : ` # Deploys change the image; Terraform owns everything else.
1764
1853
  lifecycle {
1765
1854
  ignore_changes = [template[0].containers[0].image, client, client_version]
1766
- }
1855
+ }`}
1767
1856
  }
1768
1857
 
1769
1858
  # Anyone with the link can open it. Remove this to keep the app private.
@@ -1779,6 +1868,86 @@ output "url" {
1779
1868
  }
1780
1869
  `
1781
1870
  });
1871
+ if (cloudSql) {
1872
+ files.push({
1873
+ path: "infra/database.tf",
1874
+ content: `# Managed by CompBox: a Cloud SQL for PostgreSQL database for this environment.
1875
+ # Estimated cost: a db-f1-micro instance with 10 GB of SSD, per environment.
1876
+ # The password is generated here and kept only in Terraform state and Secret Manager.
1877
+ resource "google_sql_database_instance" "db" {
1878
+ name = "\${local.service}-db"
1879
+ database_version = "POSTGRES_16"
1880
+ region = var.region
1881
+ # Terraform refuses to delete it; turn this off first if you really mean to.
1882
+ deletion_protection = true
1883
+
1884
+ settings {
1885
+ edition = "ENTERPRISE"
1886
+ tier = "db-f1-micro"
1887
+ availability_type = "ZONAL"
1888
+ disk_type = "PD_SSD"
1889
+ disk_size = 10
1890
+ deletion_protection_enabled = true
1891
+
1892
+ backup_configuration {
1893
+ enabled = true
1894
+ }
1895
+
1896
+ # A public IP with no authorized networks: only IAM-authorized connectors
1897
+ # (Cloud Run's Cloud SQL connection, the Cloud SQL Auth Proxy) can reach it.
1898
+ ip_configuration {
1899
+ ipv4_enabled = true
1900
+ }
1901
+ }
1902
+ }
1903
+
1904
+ resource "google_sql_database" "app" {
1905
+ name = var.app
1906
+ instance = google_sql_database_instance.db.name
1907
+ }
1908
+
1909
+ resource "random_password" "db" {
1910
+ length = 32
1911
+ special = false
1912
+ }
1913
+
1914
+ resource "google_sql_user" "app" {
1915
+ name = var.app
1916
+ instance = google_sql_database_instance.db.name
1917
+ password = random_password.db.result
1918
+ }
1919
+
1920
+ # Cloud Run (and the migrate job's proxy) reach the database over a Unix socket in /cloudsql.
1921
+ resource "google_secret_manager_secret" "database_url" {
1922
+ secret_id = "\${local.service}-${secretSuffix}"
1923
+ replication {
1924
+ auto {}
1925
+ }
1926
+ }
1927
+
1928
+ resource "google_secret_manager_secret_version" "database_url" {
1929
+ secret = google_secret_manager_secret.database_url.id
1930
+ secret_data = "postgresql://\${google_sql_user.app.name}:\${random_password.db.result}@localhost/\${google_sql_database.app.name}?host=/cloudsql/\${google_sql_database_instance.db.connection_name}"
1931
+ }
1932
+
1933
+ resource "google_secret_manager_secret_iam_member" "runtime" {
1934
+ secret_id = google_secret_manager_secret.database_url.id
1935
+ role = "roles/secretmanager.secretAccessor"
1936
+ member = "serviceAccount:\${google_service_account.runtime.email}"
1937
+ }
1938
+
1939
+ resource "google_project_iam_member" "runtime_cloudsql" {
1940
+ project = var.project_id
1941
+ role = "roles/cloudsql.client"
1942
+ member = "serviceAccount:\${google_service_account.runtime.email}"
1943
+ }
1944
+
1945
+ output "database_instance" {
1946
+ value = google_sql_database_instance.db.connection_name
1947
+ }
1948
+ `
1949
+ });
1950
+ }
1782
1951
  for (const env of envs) {
1783
1952
  const s = envSettings(env);
1784
1953
  files.push({
@@ -1820,11 +1989,19 @@ jobs:
1820
1989
  uses: ./.github/workflows/compbox-deploy.yml
1821
1990
  with:
1822
1991
  environment: \${{ inputs.environment || 'dev' }}
1992
+ secrets: inherit
1823
1993
  `
1824
1994
  });
1825
1995
  files.push({
1826
1996
  path: ".github/workflows/compbox-deploy.yml",
1827
1997
  content: `# Managed by CompBox. Signs in to Google Cloud without stored keys (Workload Identity).
1998
+ #
1999
+ # 1. build \u2014 runs in the environment (prod waits for its approval): applies the
2000
+ # Terraform, ${cloudSql ? "including the Cloud SQL database and its DATABASE_URL" : "keeps DATABASE_URL in Secret Manager"}, builds the image.
2001
+ # 2. migrate \u2014 only when the environment has a DATABASE_URL: runs the app's own
2002
+ # "db:migrate" (or "migrate") script. It runs in the "<environment>-migrations"
2003
+ # GitHub environment, so you can require an approval before migrations.
2004
+ # 3. release \u2014 deploys the image to Cloud Run once migrations have succeeded.
1828
2005
  name: CompBox deploy
1829
2006
 
1830
2007
  on:
@@ -1842,19 +2019,22 @@ concurrency:
1842
2019
  group: compbox-\${{ inputs.environment }}
1843
2020
  cancel-in-progress: false
1844
2021
 
2022
+ env:
2023
+ ENVIRONMENT: \${{ inputs.environment }}
2024
+ PROJECT_ID: ${cloud.projectId}
2025
+ REGION: ${cloud.region}
2026
+ APP: ${app}
2027
+ IMAGE: ${registry}/app:\${{ github.sha }}
2028
+ STATE_BUCKET: ${gcpStateBucket(cloud.projectId)}
2029
+
1845
2030
  jobs:
1846
- deploy:
2031
+ build:
1847
2032
  runs-on: ubuntu-latest
1848
- environment:
1849
- name: \${{ inputs.environment }}
1850
- url: \${{ steps.deploy.outputs.url }}
2033
+ environment: \${{ inputs.environment }}
2034
+ outputs:
2035
+ database: \${{ steps.database.outputs.configured }}
1851
2036
  env:
1852
- ENVIRONMENT: \${{ inputs.environment }}
1853
- PROJECT_ID: ${cloud.projectId}
1854
- REGION: ${cloud.region}
1855
- APP: ${app}
1856
- IMAGE: ${registry}/app:\${{ github.sha }}
1857
- STATE_BUCKET: ${gcpStateBucket(cloud.projectId)}
2037
+ HAS_DATABASE_URL: \${{ secrets.DATABASE_URL != '' }}
1858
2038
  steps:
1859
2039
  - uses: actions/checkout@v4
1860
2040
 
@@ -1873,6 +2053,31 @@ jobs:
1873
2053
  terraform init -input=false -backend-config="bucket=$STATE_BUCKET" -backend-config="prefix=$APP/$ENVIRONMENT"
1874
2054
  terraform apply -input=false -auto-approve -var-file="envs/$ENVIRONMENT.tfvars"
1875
2055
 
2056
+ ${cloudSql ? ` - name: Database secret
2057
+ id: database
2058
+ # Terraform created the Cloud SQL database and keeps its DATABASE_URL.
2059
+ run: echo "configured=true" >> "$GITHUB_OUTPUT"
2060
+ ` : ` - name: Database secret
2061
+ id: database
2062
+ env:
2063
+ DATABASE_URL: \${{ secrets.DATABASE_URL }}
2064
+ run: |
2065
+ if [ "$HAS_DATABASE_URL" != "true" ]; then
2066
+ echo "configured=false" >> "$GITHUB_OUTPUT"
2067
+ exit 0
2068
+ fi
2069
+ SECRET="$APP-$ENVIRONMENT-database-url"
2070
+ RUNTIME="serviceAccount:$APP-$ENVIRONMENT@$PROJECT_ID.iam.gserviceaccount.com"
2071
+ gcloud secrets describe "$SECRET" --project "$PROJECT_ID" >/dev/null 2>&1 || \\
2072
+ gcloud secrets create "$SECRET" --project "$PROJECT_ID" --replication-policy=automatic --quiet
2073
+ CURRENT=$(gcloud secrets versions access latest --secret "$SECRET" --project "$PROJECT_ID" 2>/dev/null || true)
2074
+ if [ "$CURRENT" != "$DATABASE_URL" ]; then
2075
+ printf '%s' "$DATABASE_URL" | gcloud secrets versions add "$SECRET" --project "$PROJECT_ID" --data-file=- --quiet
2076
+ fi
2077
+ gcloud secrets add-iam-policy-binding "$SECRET" --project "$PROJECT_ID" --member="$RUNTIME" \\
2078
+ --role=roles/secretmanager.secretAccessor --condition=None --quiet >/dev/null
2079
+ echo "configured=true" >> "$GITHUB_OUTPUT"
2080
+ `}
1876
2081
  - name: Build
1877
2082
  run: |
1878
2083
  if [ ! -f Dockerfile ]; then
@@ -1883,11 +2088,89 @@ jobs:
1883
2088
  docker build -t "$IMAGE" .
1884
2089
  docker push "$IMAGE"
1885
2090
 
2091
+ migrate:
2092
+ needs: build
2093
+ if: needs.build.outputs.database == 'true'
2094
+ runs-on: ubuntu-latest
2095
+ environment: \${{ inputs.environment }}-migrations
2096
+ steps:
2097
+ - uses: actions/checkout@v4
2098
+
2099
+ - uses: google-github-actions/auth@v2
2100
+ with:
2101
+ workload_identity_provider: ${cloud.workloadProvider}
2102
+ service_account: ${cloud.serviceAccountEmail}
2103
+
2104
+ - uses: google-github-actions/setup-gcloud@v2
2105
+
2106
+ - uses: actions/setup-node@v4
2107
+ with:
2108
+ node-version: lts/*
2109
+
2110
+ - name: Migrate
2111
+ run: |
2112
+ if [ ! -f package.json ]; then
2113
+ echo "::notice::No package.json, so there is no migrate script to run. Skipping migrations."
2114
+ exit 0
2115
+ fi
2116
+ SCRIPT=$(node -e 'const s = require("./package.json").scripts || {}; process.stdout.write(s["db:migrate"] ? "db:migrate" : s.migrate ? "migrate" : "")')
2117
+ if [ -z "$SCRIPT" ]; then
2118
+ echo "::notice::package.json has no \\"db:migrate\\" or \\"migrate\\" script. Skipping migrations."
2119
+ exit 0
2120
+ fi
2121
+ DATABASE_URL=$(gcloud secrets versions access latest --secret "$APP-$ENVIRONMENT-${secretSuffix}" --project "$PROJECT_ID")
2122
+ echo "::add-mask::$DATABASE_URL"
2123
+ export DATABASE_URL${cloudSql ? `
2124
+ # Reach the Cloud SQL database through the Cloud SQL Auth Proxy, on the same /cloudsql socket Cloud Run uses.
2125
+ curl -fsSL -o cloud-sql-proxy "https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/${CLOUD_SQL_PROXY_VERSION}/cloud-sql-proxy.linux.amd64"
2126
+ chmod +x cloud-sql-proxy
2127
+ sudo mkdir -p /cloudsql && sudo chown "$(id -u)" /cloudsql
2128
+ INSTANCE="$PROJECT_ID:$REGION:$APP-$ENVIRONMENT-db"
2129
+ ./cloud-sql-proxy --unix-socket /cloudsql "$INSTANCE" &
2130
+ for _ in $(seq 1 30); do
2131
+ [ -S "/cloudsql/$INSTANCE/.s.PGSQL.5432" ] && break
2132
+ sleep 1
2133
+ done
2134
+ if [ ! -S "/cloudsql/$INSTANCE/.s.PGSQL.5432" ]; then
2135
+ echo "::error::Couldn't reach the Cloud SQL database $INSTANCE."
2136
+ exit 1
2137
+ fi` : ""}
2138
+ if [ -f pnpm-lock.yaml ]; then
2139
+ corepack enable
2140
+ pnpm install --frozen-lockfile
2141
+ pnpm run "$SCRIPT"
2142
+ elif [ -f yarn.lock ]; then
2143
+ corepack enable
2144
+ yarn install --immutable || yarn install --frozen-lockfile
2145
+ yarn run "$SCRIPT"
2146
+ else
2147
+ if [ -f package-lock.json ]; then npm ci; else npm install; fi
2148
+ npm run "$SCRIPT"
2149
+ fi
2150
+
2151
+ release:
2152
+ needs: [build, migrate]
2153
+ if: \${{ !cancelled() && needs.build.result == 'success' && (needs.migrate.result == 'success' || needs.migrate.result == 'skipped') }}
2154
+ runs-on: ubuntu-latest
2155
+ steps:
2156
+ - uses: google-github-actions/auth@v2
2157
+ with:
2158
+ workload_identity_provider: ${cloud.workloadProvider}
2159
+ service_account: ${cloud.serviceAccountEmail}
2160
+
2161
+ - uses: google-github-actions/setup-gcloud@v2
2162
+
1886
2163
  - name: Deploy
1887
2164
  id: deploy
2165
+ env:
2166
+ DATABASE: \${{ needs.build.outputs.database }}
1888
2167
  run: |
1889
2168
  SERVICE="$APP-$ENVIRONMENT"
1890
- gcloud run deploy "$SERVICE" --image "$IMAGE" --region "$REGION" --project "$PROJECT_ID" --quiet
2169
+ SECRETS=()
2170
+ if [ "$DATABASE" = "true" ]; then
2171
+ SECRETS=(--set-secrets "DATABASE_URL=$APP-$ENVIRONMENT-${secretSuffix}:latest"${cloudSql ? ` --add-cloudsql-instances "$PROJECT_ID:$REGION:$APP-$ENVIRONMENT-db"` : ""})
2172
+ fi
2173
+ gcloud run deploy "$SERVICE" --image "$IMAGE" --region "$REGION" --project "$PROJECT_ID" "\${SECRETS[@]}" --quiet
1891
2174
  URL=$(gcloud run services describe "$SERVICE" --region "$REGION" --project "$PROJECT_ID" --format='value(status.url)')
1892
2175
  echo "url=$URL" >> "$GITHUB_OUTPUT"
1893
2176
  echo "### Live at $URL" >> "$GITHUB_STEP_SUMMARY"
@@ -1901,13 +2184,14 @@ This project deploys to Google Cloud project \`${cloud.projectId}\` (${cloud.reg
1901
2184
 
1902
2185
  - **Dev:** every push to \`${defaultBranch}\` deploys it.${envs.length > 1 ? "\n- **Stage and prod:** in GitHub, Actions \u2192 CompBox \u2192 Run workflow, then pick the environment. Add required reviewers to the `prod` environment (Settings \u2192 Environments) so prod waits for approval." : ""}
1903
2186
  - **The app:** a \`Dockerfile\` at the repository root, for a container that listens on \`$PORT\` (8080).
2187
+ - **Database:** ${cloudSql ? `each environment has a Cloud SQL for PostgreSQL database (\`${app}-<environment>-db\`, in \`database.tf\`), created by the first deploy. Terraform keeps its \`DATABASE_URL\` in Secret Manager (\`${app}-<environment>-cloudsql-url\`) and the deploy gives it to the service as \`DATABASE_URL\`. Deletion protection is on: Terraform won't delete the database. The database password is in the Terraform state (the \`${app}\` prefix of the state bucket), so keep that bucket private.` : `when the environment has a \`DATABASE_URL\` secret, the deploy keeps it in Secret Manager (\`${app}-<environment>-database-url\`) and gives it to the service as \`DATABASE_URL\`.`} Before the new version goes live, it runs the app's \`db:migrate\` script (or \`migrate\`) with npm, pnpm or yarn, matching the lockfile; with neither script, migrations are skipped. Migrations run in the \`<environment>-migrations\` GitHub environment: add required reviewers there to approve them before they run. CompBox never runs a reset or a data-loss migration.
1904
2188
  - **Sign-in:** GitHub Actions sign in to Google Cloud through Workload Identity \u2014 there are no keys to store or rotate.
1905
2189
  - **Changes:** edit the Terraform here; the next deploy applies it. Services are public by default; remove the \`public\` resource in \`main.tf\` to keep one private.
1906
2190
  `
1907
2191
  });
1908
2192
  return files;
1909
2193
  }
1910
- var STACK_TIERS, STACK_WORKFLOW, APP, BRANCH;
2194
+ var STACK_TIERS, STACK_WORKFLOW, CLOUD_SQL_PROXY_VERSION, APP, BRANCH;
1911
2195
  var init_stack_files = __esm({
1912
2196
  "../shared/dist/stack-files.js"() {
1913
2197
  "use strict";
@@ -1917,6 +2201,7 @@ var init_stack_files = __esm({
1917
2201
  full: { label: "Dev, stage and prod", environments: ["dev", "stage", "prod"] }
1918
2202
  };
1919
2203
  STACK_WORKFLOW = "compbox.yml";
2204
+ CLOUD_SQL_PROXY_VERSION = "v2.14.1";
1920
2205
  APP = /^[a-z][a-z0-9-]{1,19}$/;
1921
2206
  BRANCH = /^[A-Za-z0-9._/-]{1,200}$/;
1922
2207
  }
@@ -1986,17 +2271,22 @@ __export(dist_exports, {
1986
2271
  APPEND_DESCRIPTION_MAX: () => APPEND_DESCRIPTION_MAX,
1987
2272
  AWS_REGIONS: () => AWS_REGIONS,
1988
2273
  AZURE_DEPLOY_IDENTITY: () => AZURE_DEPLOY_IDENTITY,
2274
+ CLOUD_SQL_MONTHLY_ESTIMATE_USD: () => CLOUD_SQL_MONTHLY_ESTIMATE_USD,
2275
+ CLOUD_SQL_PROXY_VERSION: () => CLOUD_SQL_PROXY_VERSION,
1989
2276
  COMPLETION_REPAIR_INSTRUCTION: () => COMPLETION_REPAIR_INSTRUCTION,
1990
2277
  CONVERSATION_QUALITY_ROUNDS: () => CONVERSATION_QUALITY_ROUNDS,
2278
+ DATABASE_CHOICE_VALUES: () => DATABASE_CHOICE_VALUES,
1991
2279
  DESCRIPTION_MAX: () => DESCRIPTION_MAX,
1992
2280
  EMPTY_ARM_TEMPLATE: () => EMPTY_ARM_TEMPLATE,
1993
2281
  GCP_CONNECT_STEPS: () => GCP_CONNECT_STEPS,
1994
2282
  GCP_CONNECT_STEP_LABELS: () => GCP_CONNECT_STEP_LABELS,
1995
2283
  GCP_DEPLOY_ACCOUNT: () => GCP_DEPLOY_ACCOUNT,
2284
+ GCP_DEPLOY_CONDITIONAL_ROLE: () => GCP_DEPLOY_CONDITIONAL_ROLE,
1996
2285
  GCP_DEPLOY_ROLES: () => GCP_DEPLOY_ROLES,
1997
2286
  GCP_IDENTITY_POOL: () => GCP_IDENTITY_POOL,
1998
2287
  GCP_IDENTITY_PROVIDER: () => GCP_IDENTITY_PROVIDER,
1999
2288
  GCP_REGIONS: () => GCP_REGIONS,
2289
+ GCP_SERVICES: () => GCP_SERVICES,
2000
2290
  INTERVIEW_DEFINITION: () => INTERVIEW_DEFINITION,
2001
2291
  INTERVIEW_FIELD_MIN_WORDS: () => INTERVIEW_FIELD_MIN_WORDS,
2002
2292
  INTERVIEW_STATUSES: () => INTERVIEW_STATUSES,
@@ -2030,7 +2320,9 @@ __export(dist_exports, {
2030
2320
  buildInterviewSystemPrompt: () => buildInterviewSystemPrompt,
2031
2321
  buildStackFiles: () => buildStackFiles,
2032
2322
  cloudRunUrl: () => cloudRunUrl,
2323
+ cloudSqlInstanceName: () => cloudSqlInstanceName,
2033
2324
  complianceFromRecord: () => complianceFromRecord,
2325
+ databaseSecretName: () => databaseSecretName,
2034
2326
  deployRunTitle: () => deployRunTitle,
2035
2327
  err: () => err,
2036
2328
  extractCompletionJson: () => extractCompletionJson,
@@ -2079,6 +2371,7 @@ __export(dist_exports, {
2079
2371
  mcpServerConfigSchema: () => mcpServerConfigSchema,
2080
2372
  meetsComplianceTarget: () => meetsComplianceTarget,
2081
2373
  modelRecommendationSourceValues: () => modelRecommendationSourceValues,
2374
+ normalizeDatabaseChoice: () => normalizeDatabaseChoice,
2082
2375
  normalizeGitRemote: () => normalizeGitRemote,
2083
2376
  ok: () => ok,
2084
2377
  probeProxyHealth: () => probeProxyHealth,
@@ -12343,7 +12636,7 @@ function withLegacyToolCallRewrite(transport) {
12343
12636
  var SERVER_NAME = "compbox-mcp";
12344
12637
  function resolveServerVersion() {
12345
12638
  if (true) {
12346
- return "1.21.7";
12639
+ return "1.21.8";
12347
12640
  }
12348
12641
  const require2 = createRequire(import.meta.url);
12349
12642
  for (const candidate of ["../package.json", "./package.json"]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycompbox/compbox-mcp",
3
- "version": "1.21.7",
3
+ "version": "1.21.8",
4
4
  "description": "CompBox MCP server - Uses HTTP API client (no direct database access)",
5
5
  "license": "MIT",
6
6
  "type": "module",