@catladder/cli 0.0.0-main-332b079a → 0.0.0-main-752fde5b

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.
@@ -1195,6 +1195,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
1195
1195
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1196
1196
  }
1197
1197
  };
1198
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
1199
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1200
+ if (ar || !(i in from)) {
1201
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1202
+ ar[i] = from[i];
1203
+ }
1204
+ }
1205
+ return to.concat(ar || Array.prototype.slice.call(from));
1206
+ };
1198
1207
  exports.__esModule = true;
1199
1208
  var pipeline_1 = __nccwpck_require__(25355);
1200
1209
  var child_process_promise_1 = __nccwpck_require__(75763);
@@ -1213,79 +1222,79 @@ exports["default"] = (function (vorpal) { return __awaiter(void 0, void 0, void
1213
1222
  return [4 /*yield*/, (0, autocompletions_1.envAndComponents)()];
1214
1223
  case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])
1215
1224
  .action(function (_a) {
1216
- var _b, _c, _d, _e;
1217
1225
  var envComponent = _a.envComponent;
1218
1226
  return __awaiter(this, void 0, void 0, function () {
1219
- var _f, env, componentName, config, localPort, envVars, POSTGRESQL_PASSWORD, context, values, projectId, defaultInstanceId, instanceId, defaultRegion, region, instanceName, cloudsqlProxyCredentials;
1227
+ var _b, env, componentName, context, proxyInfo, DB_PASSWORD, DB_NAME, instanceName, localPort, cloudsqlProxyCredentials;
1220
1228
  var _this = this;
1221
- return __generator(this, function (_g) {
1222
- switch (_g.label) {
1229
+ return __generator(this, function (_c) {
1230
+ switch (_c.label) {
1223
1231
  case 0:
1224
- _f = (0, getProjectConfig_1.parseChoice)(envComponent), env = _f.env, componentName = _f.componentName;
1225
- return [4 /*yield*/, (0, getProjectConfig_1.getProjectConfig)()];
1232
+ _b = (0, getProjectConfig_1.parseChoice)(envComponent), env = _b.env, componentName = _b.componentName;
1233
+ return [4 /*yield*/, (0, getProjectConfig_1.getPipelineContextByChoice)(env, componentName)];
1226
1234
  case 1:
1227
- config = _g.sent();
1235
+ context = _c.sent();
1236
+ if (env === "review") {
1237
+ vorpal.log("⚠️ connection string does not include mr information on review environments");
1238
+ }
1239
+ if (!(0, pipeline_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) return [3 /*break*/, 3];
1240
+ return [4 /*yield*/, getProxyInfoForKubernetes(context)];
1241
+ case 2:
1242
+ proxyInfo = _c.sent();
1243
+ return [3 /*break*/, 6];
1244
+ case 3:
1245
+ if (!(0, pipeline_1.isOfDeployType)(context.componentConfig.deploy, "google-cloudrun")) return [3 /*break*/, 5];
1246
+ return [4 /*yield*/, getProxyInfoForCloudRun(context)];
1247
+ case 4:
1248
+ proxyInfo = _c.sent();
1249
+ return [3 /*break*/, 6];
1250
+ case 5: throw new Error("unsupported environment");
1251
+ case 6:
1252
+ DB_PASSWORD = proxyInfo.DB_PASSWORD, DB_NAME = proxyInfo.DB_NAME, instanceName = proxyInfo.instanceName;
1228
1253
  return [4 /*yield*/, this.prompt({
1229
1254
  type: "number",
1230
1255
  name: "localPort",
1231
1256
  "default": "54320",
1232
1257
  message: "Local port: "
1233
1258
  })];
1234
- case 2:
1235
- localPort = (_g.sent()).localPort;
1236
- return [4 /*yield*/, (0, getProjectConfig_1.getEnvVars)(this, env, componentName)];
1237
- case 3:
1238
- envVars = _g.sent();
1239
- POSTGRESQL_PASSWORD = envVars === null || envVars === void 0 ? void 0 : envVars.POSTGRESQL_PASSWORD;
1240
- return [4 /*yield*/, (0, getProjectConfig_1.getPipelineContextByChoice)(env, componentName)];
1241
- case 4:
1242
- context = _g.sent();
1243
- if (!(0, pipeline_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
1244
- throw new Error("currently only supported for kubernetes deployment");
1245
- }
1259
+ case 7:
1260
+ localPort = (_c.sent()).localPort;
1246
1261
  this.log("");
1247
- this.log("postgres-PW: ".concat(POSTGRESQL_PASSWORD));
1262
+ this.log("postgres-PW: ".concat(DB_PASSWORD));
1248
1263
  this.log("");
1249
- this.log("POSTGRESQL_URL=postgresql://postgres:".concat(POSTGRESQL_PASSWORD, "@localhost:").concat(localPort, "/").concat(context.environment.envVars.KUBE_APP_NAME, "?schema=public"));
1264
+ this.log("POSTGRESQL_URL=postgresql://postgres:".concat(DB_PASSWORD, "@localhost:").concat(localPort, "/").concat(DB_NAME, "?schema=public"));
1250
1265
  this.log("");
1251
- values = context.componentConfig.deploy.values;
1252
- projectId = ((_b = values === null || values === void 0 ? void 0 : values.cloudsql) === null || _b === void 0 ? void 0 : _b.projectId) ||
1253
- ((_c = context.componentConfig.deploy.cluster) === null || _c === void 0 ? void 0 : _c.projectId);
1254
- defaultInstanceId = "".concat(config.customerName, "-").concat(config.appName, "-").concat(env);
1255
- instanceId = ((_d = values === null || values === void 0 ? void 0 : values.cloudsql) === null || _d === void 0 ? void 0 : _d.instanceId) || defaultInstanceId;
1256
- defaultRegion = "europe-west6";
1257
- region = ((_e = values === null || values === void 0 ? void 0 : values.cloudsql) === null || _e === void 0 ? void 0 : _e.region) || defaultRegion;
1258
- instanceName = "".concat(projectId, ":").concat(region, ":").concat(instanceId, "=tcp:").concat(localPort);
1259
1266
  return [4 /*yield*/, (0, getProjectConfig_1.getGitlabVar)(this, env, componentName, "cloudsqlProxyCredentials")];
1260
- case 5:
1261
- cloudsqlProxyCredentials = _g.sent();
1262
- if (!cloudsqlProxyCredentials) {
1263
- // we store cloudsqlProxyCredentials on gitlab, but its currently get pushed via bitwarden due to legacy reasons
1264
- // this will be fixed with when https://git.panter.ch/catladder/catladder/-/merge_requests/32/ is merged
1265
- this.log("cloudsqlProxyCredentials env var missing in gitlab. Please contact gilde-ci-cd about that.");
1266
- throw new Error("cloudsqlProxyCredentials missing in secrets");
1267
- }
1267
+ case 8:
1268
+ cloudsqlProxyCredentials = _c.sent();
1268
1269
  return [4 /*yield*/, (0, tmp_promise_1.withFile)(function (_a) {
1269
1270
  var tmpFilePath = _a.path;
1270
1271
  return __awaiter(_this, void 0, void 0, function () {
1271
1272
  return __generator(this, function (_b) {
1272
1273
  switch (_b.label) {
1273
- case 0: return [4 /*yield*/, (0, fs_extra_1.writeFile)(tmpFilePath, cloudsqlProxyCredentials)];
1274
+ case 0:
1275
+ if (!cloudsqlProxyCredentials) return [3 /*break*/, 2];
1276
+ return [4 /*yield*/, (0, fs_extra_1.writeFile)(tmpFilePath, cloudsqlProxyCredentials)];
1274
1277
  case 1:
1275
1278
  _b.sent();
1276
- return [4 /*yield*/, (0, child_process_promise_1.spawn)("cloud_sql_proxy", ["-instances", instanceName, "-credential_file", tmpFilePath], {
1277
- stdio: "inherit",
1278
- shell: true
1279
- })];
1280
- case 2:
1279
+ _b.label = 2;
1280
+ case 2: return [4 /*yield*/, (0, child_process_promise_1.spawn)("cloud_sql_proxy", __spreadArray([
1281
+ "-instances",
1282
+ "".concat(instanceName, "=tcp:").concat(localPort)
1283
+ ], (cloudsqlProxyCredentials
1284
+ ? ["-credential_file", tmpFilePath]
1285
+ : []), true), {
1286
+ stdio: "inherit",
1287
+ shell: true
1288
+ })];
1289
+ case 3:
1281
1290
  _b.sent();
1282
1291
  return [2 /*return*/];
1283
1292
  }
1284
1293
  });
1285
1294
  });
1286
1295
  })];
1287
- case 6:
1288
- _g.sent();
1296
+ case 9:
1297
+ _c.sent();
1289
1298
  return [2 /*return*/];
1290
1299
  }
1291
1300
  });
@@ -1294,6 +1303,58 @@ exports["default"] = (function (vorpal) { return __awaiter(void 0, void 0, void
1294
1303
  }
1295
1304
  });
1296
1305
  }); });
1306
+ var getProxyInfoForKubernetes = function (context) { return __awaiter(void 0, void 0, void 0, function () {
1307
+ var envVars, DB_PASSWORD, DB_NAME, values, projectId, defaultInstanceId, instanceId, defaultRegion, region, instanceName;
1308
+ var _a, _b, _c, _d;
1309
+ return __generator(this, function (_e) {
1310
+ switch (_e.label) {
1311
+ case 0:
1312
+ if (!(0, pipeline_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
1313
+ throw new Error("unsupported");
1314
+ }
1315
+ return [4 /*yield*/, (0, getProjectConfig_1.getEnvVars)(this, context.environment.shortName, context.componentName)];
1316
+ case 1:
1317
+ envVars = _e.sent();
1318
+ DB_PASSWORD = (envVars === null || envVars === void 0 ? void 0 : envVars.DB_PASSWORD) || (envVars === null || envVars === void 0 ? void 0 : envVars.POSTGRESQL_PASSWORD);
1319
+ DB_NAME = context.environment.envVars.KUBE_APP_NAME;
1320
+ values = context.componentConfig.deploy.values;
1321
+ projectId = ((_a = values === null || values === void 0 ? void 0 : values.cloudsql) === null || _a === void 0 ? void 0 : _a.projectId) ||
1322
+ ((_b = context.componentConfig.deploy.cluster) === null || _b === void 0 ? void 0 : _b.projectId);
1323
+ defaultInstanceId = "".concat(context.fullConfig.customerName, "-").concat(context.fullConfig.appName, "-").concat(context.environment.shortName);
1324
+ instanceId = ((_c = values === null || values === void 0 ? void 0 : values.cloudsql) === null || _c === void 0 ? void 0 : _c.instanceId) || defaultInstanceId;
1325
+ defaultRegion = "europe-west6";
1326
+ region = ((_d = values === null || values === void 0 ? void 0 : values.cloudsql) === null || _d === void 0 ? void 0 : _d.region) || defaultRegion;
1327
+ instanceName = "".concat(projectId, ":").concat(region, ":").concat(instanceId);
1328
+ return [2 /*return*/, {
1329
+ instanceName: instanceName,
1330
+ DB_PASSWORD: DB_PASSWORD,
1331
+ DB_NAME: DB_NAME
1332
+ }];
1333
+ }
1334
+ });
1335
+ }); };
1336
+ var getProxyInfoForCloudRun = function (context) { return __awaiter(void 0, void 0, void 0, function () {
1337
+ var envVars, DB_PASSWORD, DB_NAME;
1338
+ return __generator(this, function (_a) {
1339
+ switch (_a.label) {
1340
+ case 0:
1341
+ if (!(0, pipeline_1.isOfDeployType)(context.componentConfig.deploy, "google-cloudrun") ||
1342
+ !context.componentConfig.deploy.cloudSql) {
1343
+ throw new Error("unsupported");
1344
+ }
1345
+ return [4 /*yield*/, (0, getProjectConfig_1.getEnvVars)(this, context.environment.shortName, context.componentName)];
1346
+ case 1:
1347
+ envVars = _a.sent();
1348
+ DB_PASSWORD = envVars === null || envVars === void 0 ? void 0 : envVars.DB_PASSWORD;
1349
+ DB_NAME = context.environment.envVars.DB_NAME;
1350
+ return [2 /*return*/, {
1351
+ instanceName: context.componentConfig.deploy.cloudSql.instanceConnectionName,
1352
+ DB_PASSWORD: DB_PASSWORD,
1353
+ DB_NAME: DB_NAME
1354
+ }];
1355
+ }
1356
+ });
1357
+ }); };
1297
1358
  //# sourceMappingURL=commandCloudSqlProxy.js.map
1298
1359
 
1299
1360
  /***/ }),
@@ -4158,6 +4219,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
4158
4219
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
4159
4220
  }
4160
4221
  };
4222
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
4223
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4224
+ if (ar || !(i in from)) {
4225
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
4226
+ ar[i] = from[i];
4227
+ }
4228
+ }
4229
+ return to.concat(ar || Array.prototype.slice.call(from));
4230
+ };
4161
4231
  exports.__esModule = true;
4162
4232
  exports.setupCloudRun = void 0;
4163
4233
  var pipeline_1 = __nccwpck_require__(25355);
@@ -4178,7 +4248,12 @@ var setupCloudRun = function (instance, context) { return __awaiter(void 0, void
4178
4248
  config = context.componentConfig.deploy;
4179
4249
  // enable services
4180
4250
  instance.log("enable required servies...");
4181
- return [4 /*yield*/, (0, enableServices_1.enableGCloudServices)(["run.googleapis.com", "artifactregistry.googleapis.com"], config)];
4251
+ return [4 /*yield*/, (0, enableServices_1.enableGCloudServices)(__spreadArray([
4252
+ "run.googleapis.com",
4253
+ "artifactregistry.googleapis.com"
4254
+ ], (config.cloudSql
4255
+ ? ["sqladmin.googleapis.com", "sql-component.googleapis.com"]
4256
+ : []), true), config)];
4182
4257
  case 1:
4183
4258
  _b.sent();
4184
4259
  instance.log("upsert artifacts registry...");
@@ -4192,11 +4267,11 @@ var setupCloudRun = function (instance, context) { return __awaiter(void 0, void
4192
4267
  description: "This service account deploys to google cloud",
4193
4268
  name: "cl-d",
4194
4269
  // TODO: run.admin is a bit much, would be better to follow https://stackoverflow.com/questions/55788714/deploying-to-cloud-run-with-a-custom-service-account-failed-with-iam-serviceacco
4195
- roles: [
4270
+ roles: __spreadArray([
4196
4271
  "roles/artifactregistry.repoAdmin",
4197
4272
  "roles/run.admin",
4198
- "roles/iam.serviceAccountUser",
4199
- ]
4273
+ "roles/iam.serviceAccountUser"
4274
+ ], (config.cloudSql ? ["roles/cloudsql.admin"] : []), true)
4200
4275
  }, pipeline_1.GCLOUD_DEPLOY_CREDENTIALS_KEY)];
4201
4276
  case 3:
4202
4277
  _b.sent();
@@ -4272,10 +4347,10 @@ var pipeline_1 = __nccwpck_require__(25355);
4272
4347
  var setupCloudSQL = function (instance, context) { return __awaiter(void 0, void 0, void 0, function () {
4273
4348
  var config;
4274
4349
  return __generator(this, function (_a) {
4275
- if (!(0, pipeline_1.hasCloudSQL)(context)) {
4350
+ if (!(0, pipeline_1.hasKubernetesCloudSQL)(context)) {
4276
4351
  throw new Error("cannot setup cloudsql, as it has none");
4277
4352
  }
4278
- config = (0, pipeline_1.getCloudSQLConfig)(context);
4353
+ config = (0, pipeline_1.getKubernetesCloudSQLConfig)(context);
4279
4354
  instance.log("");
4280
4355
  instance.log("! make sure to provide cloudsqlProxyCredentials for the cloud sql service account in " +
4281
4356
  config.projectId);
@@ -4354,7 +4429,7 @@ var setupContext = function (instance, context) { return __awaiter(void 0, void
4354
4429
  _a.sent();
4355
4430
  _a.label = 2;
4356
4431
  case 2:
4357
- if (!(0, pipeline_1.hasCloudSQL)(context)) return [3 /*break*/, 4];
4432
+ if (!(0, pipeline_1.hasKubernetesCloudSQL)(context)) return [3 /*break*/, 4];
4358
4433
  return [4 /*yield*/, (0, setupCloudSQL_1.setupCloudSQL)(instance, context)];
4359
4434
  case 3:
4360
4435
  _a.sent();
@@ -350930,7 +351005,7 @@ exports.readConfigSync = readConfigSync;
350930
351005
 
350931
351006
  exports.__esModule = true;
350932
351007
  exports.DOCKER_REGISTRY = exports.PIPELINE_IMAGE_TAG = void 0;
350933
- exports.PIPELINE_IMAGE_TAG = "main-332b079a" || 0;
351008
+ exports.PIPELINE_IMAGE_TAG = "main-752fde5b" || 0;
350934
351009
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || 0;
350935
351010
 
350936
351011
  /***/ }),
@@ -352401,10 +352476,12 @@ var types_1 = __nccwpck_require__(63109);
352401
352476
 
352402
352477
  var gcloudServiceAccountLoginCommands_1 = __nccwpck_require__(22607);
352403
352478
 
352479
+ var database_1 = __nccwpck_require__(41384);
352480
+
352404
352481
  var gitlab_1 = __nccwpck_require__(84997);
352405
352482
 
352406
352483
  var createGoogleCloudRunDeployJobs = function (context) {
352407
- var _a, _b;
352484
+ var _a;
352408
352485
 
352409
352486
  var deployConfig = context.componentConfig.deploy;
352410
352487
 
@@ -352433,7 +352510,8 @@ var createGoogleCloudRunDeployJobs = function (context) {
352433
352510
  return "".concat(key, "=").concat(value);
352434
352511
  }).join(",");
352435
352512
  var commonArgs = "--project ".concat(deployConfig.projectId, " --region=").concat(deployConfig.region);
352436
- var commonDeployArgs = "--image ".concat(gcloudImageName, " ").concat(commonArgs, " --labels ").concat(labelsString);
352513
+ var cloudRunArgs = deployConfig.cloudSql ? "--set-cloudsql-instances=".concat(deployConfig.cloudSql.instanceConnectionName) : "";
352514
+ var commonDeployArgs = "--image ".concat(gcloudImageName, " ").concat(commonArgs, " ").concat(cloudRunArgs, " --labels ").concat(labelsString);
352437
352515
  var serviceName = context.environment.fullName.toLowerCase();
352438
352516
 
352439
352517
  var getServiceDeployScript = function (service) {
@@ -352448,7 +352526,7 @@ var createGoogleCloudRunDeployJobs = function (context) {
352448
352526
  // due to some oversight from google, jobs create does not accept `--env-vars-file` 🤦
352449
352527
  // lucky, update on the other hand accepts it... so let's just imediatly update it
352450
352528
  // also we cannot upsert a job, so we have to create it and catch the error and then update
352451
- var args = "".concat(jobName, " --command=\"").concat(job.command.split(" ").join(","), "\" ").concat(commonDeployArgs);
352529
+ var args = "".concat(jobName, " --command=\"").concat(job.command.split(" ").join(","), "\" ").concat(commonDeployArgs, " --memory=").concat(job.memory || "512Mi");
352452
352530
  return __spreadArray(__spreadArray([], __read((0, gitlab_1.allowFailureInScripts)(["gcloud beta run jobs create ".concat(args)])), false), ["gcloud beta run jobs update ".concat(args, " --env-vars-file=____envvars.yaml")], false);
352453
352531
  };
352454
352532
 
@@ -352457,10 +352535,13 @@ var createGoogleCloudRunDeployJobs = function (context) {
352457
352535
  };
352458
352536
 
352459
352537
  var getFullJobName = function (name) {
352460
- return context.environment.fullName.toLowerCase() + "-" + name;
352538
+ return context.environment.fullName.toLowerCase() + "-" + name.toLowerCase();
352461
352539
  };
352462
352540
 
352463
- var jobsWithNames = Object.entries((_a = deployConfig.jobs) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
352541
+ var jobsWithNames = Object.entries((_a = deployConfig.jobs) !== null && _a !== void 0 ? _a : {}) // filter out disabled jobs
352542
+ .filter(function (entry) {
352543
+ return Boolean(entry[1]);
352544
+ }).map(function (_a) {
352464
352545
  var _b = __read(_a, 2),
352465
352546
  name = _b[0],
352466
352547
  job = _b[1];
@@ -352468,7 +352549,8 @@ var createGoogleCloudRunDeployJobs = function (context) {
352468
352549
  return [getFullJobName(name), job];
352469
352550
  });
352470
352551
 
352471
- var cloudRunDeployScripts = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(["echo \"$ENV_VARS\" > ____envvars.yaml", "cat ____envvars.yaml"], __read(jobsWithNames.map(function (_a) {
352552
+ var cloudRunDeployScripts = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(["echo \"$ENV_VARS\" > ____envvars.yaml"], __read(deployConfig.cloudSql ? (0, database_1.getDatabaseCreateScript)(context, deployConfig) // we create the db, so that we can also delete it afterwards
352553
+ : []), false), __read(jobsWithNames.map(function (_a) {
352472
352554
  var _b = __read(_a, 2),
352473
352555
  name = _b[0],
352474
352556
  job = _b[1];
@@ -352476,37 +352558,32 @@ var createGoogleCloudRunDeployJobs = function (context) {
352476
352558
  return getJobCreateScripts(name, job);
352477
352559
  }).flat()), false), __read(jobsWithNames.filter(function (_a) {
352478
352560
  var _b = __read(_a, 2),
352479
- name = _b[0],
352480
352561
  job = _b[1];
352481
352562
 
352482
352563
  return job.when === "preDeploy";
352483
352564
  }).map(function (_a) {
352484
- var _b = __read(_a, 2),
352485
- name = _b[0],
352486
- job = _b[1];
352565
+ var _b = __read(_a, 1),
352566
+ name = _b[0];
352487
352567
 
352488
352568
  return getJobRunScript(name);
352489
352569
  })), false), __read(deployConfig.service !== false ? [getServiceDeployScript(deployConfig.service)] : []), false), __read(jobsWithNames.filter(function (_a) {
352490
352570
  var _b = __read(_a, 2),
352491
- name = _b[0],
352492
352571
  job = _b[1];
352493
352572
 
352494
352573
  return job.when === "postDeploy";
352495
352574
  }).map(function (_a) {
352496
- var _b = __read(_a, 2),
352497
- name = _b[0],
352498
- job = _b[1];
352575
+ var _b = __read(_a, 1),
352576
+ name = _b[0];
352499
352577
 
352500
352578
  return getJobRunScript(name);
352501
352579
  })), false), ["docker image rm ".concat(gcloudImageName)], false);
352502
352580
 
352503
- var cloudRunStopScripts = __spreadArray(__spreadArray([], __read(deployConfig.service !== false ? ["gcloud run services delete ".concat(serviceName, " ").concat(commonArgs)] : []), false), __read(Object.entries((_b = deployConfig.jobs) !== null && _b !== void 0 ? _b : {}).map(function (_a) {
352504
- var _b = __read(_a, 2),
352505
- name = _b[0],
352506
- job = _b[1];
352581
+ var cloudRunStopScripts = __spreadArray(__spreadArray(__spreadArray([], __read(deployConfig.service !== false ? ["gcloud run services delete ".concat(serviceName, " ").concat(commonArgs)] : []), false), __read(jobsWithNames.map(function (_a) {
352582
+ var _b = __read(_a, 1),
352583
+ name = _b[0];
352507
352584
 
352508
- return "gcloud beta run jobs delete ".concat(getFullJobName(name), " ").concat(commonArgs);
352509
- })), false);
352585
+ return "gcloud beta run jobs delete ".concat(name, " ").concat(commonArgs);
352586
+ })), false), __read(deployConfig.cloudSql && deployConfig.cloudSql.deleteDatabaseOnStop ? (0, database_1.getDatabaseDeleteScript)(context, deployConfig) : []), false);
352510
352587
 
352511
352588
  var baseStopJob = (0, base_1.getBaseDeploymentStopJob)(context);
352512
352589
  return [(0, lodash_1.merge)({}, baseDeploymentJob, (0, docker_1.getDockerJobBaseProps)(context), {
@@ -352581,6 +352658,16 @@ var __read = this && this.__read || function (o, n) {
352581
352658
  return ar;
352582
352659
  };
352583
352660
 
352661
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
352662
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
352663
+ if (ar || !(i in from)) {
352664
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
352665
+ ar[i] = from[i];
352666
+ }
352667
+ }
352668
+ return to.concat(ar || Array.prototype.slice.call(from));
352669
+ };
352670
+
352584
352671
  exports.__esModule = true;
352585
352672
  exports.GCLOUD_RUN_DEPLOY_TYPE = exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = void 0;
352586
352673
 
@@ -352592,13 +352679,50 @@ var deployJob_1 = __nccwpck_require__(82256);
352592
352679
 
352593
352680
  exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
352594
352681
  exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = "GCLOUD_RUN_canonicalHostSuffix";
352682
+
352683
+ var getCloudSqlVariables = function (_a) {
352684
+ var _b;
352685
+
352686
+ var deployConfigRaw = _a.deployConfigRaw,
352687
+ environmentSlug = _a.environmentSlug,
352688
+ env = _a.env,
352689
+ componentName = _a.componentName,
352690
+ fullConfig = _a.fullConfig;
352691
+
352692
+ if (deployConfigRaw && deployConfigRaw.cloudSql) {
352693
+ var DB_NAME = [(_b = deployConfigRaw.cloudSql.dbNamePrefix) !== null && _b !== void 0 ? _b : "".concat(fullConfig.customerName, "-").concat(fullConfig.appName), environmentSlug].filter(Boolean).join("-");
352694
+ var hostAndDb = "localhost/$DB_NAME?host=/cloudsql/$CLOUD_SQL_INSTANCE_CONNECTION_NAME";
352695
+ return {
352696
+ CLOUD_SQL_INSTANCE_CONNECTION_NAME: deployConfigRaw.cloudSql.instanceConnectionName,
352697
+ DB_NAME: DB_NAME,
352698
+ DB_USER: "postgres",
352699
+ DB_PASSWORD: "$" + (0, context_1.getSecretVarName)(env, componentName, "DB_PASSWORD"),
352700
+ DATABASE_URL: "postgresql://$DB_USER:$DB_PASSWORD@".concat(hostAndDb),
352701
+ DATABASE_URL_NO_PW: "postgresql://".concat(hostAndDb)
352702
+ };
352703
+ }
352704
+
352705
+ return {};
352706
+ };
352707
+
352595
352708
  exports.GCLOUD_RUN_DEPLOY_TYPE = {
352596
352709
  jobs: deployJob_1.createGoogleCloudRunDeployJobs,
352597
- defaults: function () {
352710
+ defaults: function (_a) {
352711
+ var deployConfigRaw = _a.deployConfigRaw,
352712
+ envType = _a.envType;
352713
+
352714
+ if (deployConfigRaw && deployConfigRaw.cloudSql) {
352715
+ return {
352716
+ cloudSql: {
352717
+ deleteDatabaseOnStop: envType === "review"
352718
+ }
352719
+ };
352720
+ }
352721
+
352598
352722
  return {};
352599
352723
  },
352600
- additionalSecretKeys: function () {
352601
- return [exports.GCLOUD_DEPLOY_CREDENTIALS_KEY];
352724
+ additionalSecretKeys: function (ctx) {
352725
+ return __spreadArray([exports.GCLOUD_DEPLOY_CREDENTIALS_KEY], __read(ctx.deployConfigRaw && ctx.deployConfigRaw.cloudSql ? ["DB_PASSWORD"] : []), false);
352602
352726
  },
352603
352727
  getAdditionalEnvVars: function (ctx) {
352604
352728
  var fullName = ctx.fullName,
@@ -352613,69 +352737,121 @@ exports.GCLOUD_RUN_DEPLOY_TYPE = {
352613
352737
 
352614
352738
  return ["CLOUD_RUN_JOB_TRIGGER_URL_" + (0, gitlab_1.sanitizeForBashVariable)(name), "https://".concat(deployConfigRaw.region, "-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/").concat(deployConfigRaw.projectId, "/jobs/").concat(name, ":run")];
352615
352739
  })) : {};
352616
- return __assign({
352740
+ return __assign(__assign({
352617
352741
  HOST_CANONICAL: HOST_CANONICAL
352618
- }, jobTriggers);
352742
+ }, getCloudSqlVariables(ctx)), jobTriggers);
352619
352743
  }
352620
352744
  };
352621
352745
 
352622
352746
  /***/ }),
352623
352747
 
352624
- /***/ 22607:
352625
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
352748
+ /***/ 41384:
352749
+ /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
352626
352750
 
352627
352751
  "use strict";
352628
352752
 
352629
352753
 
352754
+ var __read = this && this.__read || function (o, n) {
352755
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
352756
+ if (!m) return o;
352757
+ var i = m.call(o),
352758
+ r,
352759
+ ar = [],
352760
+ e;
352761
+
352762
+ try {
352763
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
352764
+ } catch (error) {
352765
+ e = {
352766
+ error: error
352767
+ };
352768
+ } finally {
352769
+ try {
352770
+ if (r && !r.done && (m = i["return"])) m.call(i);
352771
+ } finally {
352772
+ if (e) throw e.error;
352773
+ }
352774
+ }
352775
+
352776
+ return ar;
352777
+ };
352778
+
352630
352779
  exports.__esModule = true;
352631
- exports.gcloudServiceAccountLoginCommands = void 0;
352780
+ exports.getDatabaseCreateScript = exports.getDatabaseDeleteScript = void 0;
352632
352781
 
352633
- var __1 = __nccwpck_require__(81344);
352782
+ var gitlab_1 = __nccwpck_require__(84997);
352634
352783
 
352635
- var context_1 = __nccwpck_require__(22041);
352784
+ var getDatabaseDeleteScript = function (context, deployConfig) {
352785
+ var _a;
352636
352786
 
352637
- var gcloudServiceAccountLoginCommands = function (context) {
352638
- return ["echo $".concat((0, context_1.getSecretVarNameForContext)(context, __1.GCLOUD_DEPLOY_CREDENTIALS_KEY), " > ./____keyfile.json\n "), "gcloud auth activate-service-account --key-file=\"./____keyfile.json\""];
352639
- };
352787
+ if (!deployConfig.cloudSql || !deployConfig.cloudSql.deleteDatabaseOnStop) {
352788
+ throw new Error("not possible");
352789
+ }
352640
352790
 
352641
- exports.gcloudServiceAccountLoginCommands = gcloudServiceAccountLoginCommands;
352791
+ var DB_NAME = ((_a = context.environment.envVars) !== null && _a !== void 0 ? _a : {}).DB_NAME;
352642
352792
 
352643
- /***/ }),
352793
+ if (!DB_NAME) {
352794
+ throw new Error("error: env vars did not specify DB_NAME");
352795
+ }
352644
352796
 
352645
- /***/ 13539:
352646
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
352797
+ var _b = __read(deployConfig.cloudSql.instanceConnectionName.split(":"), 3),
352798
+ projectId = _b[0],
352799
+ region = _b[1],
352800
+ instanceId = _b[2]; // unfortunatly the database cannot be deleted right after the service has stopped, as it might still have connections
352801
+ // we have to repeate this process
352647
352802
 
352648
- "use strict";
352649
352803
 
352804
+ return ["echo \"deleting database ".concat(DB_NAME, "...\""), "echo \"\uD83D\uDC46 this can take multiple attemps (3-5min), because google cloud run may still have a connection to the database after the cloud run service is shut down\"", (0, gitlab_1.repeatOnFailure)("gcloud sql databases delete ".concat(DB_NAME, " --instance=").concat(instanceId, " --project ").concat(projectId), {
352805
+ pauseInSeconds: 10
352806
+ })];
352807
+ };
352650
352808
 
352651
- exports.__esModule = true;
352652
- exports.getCloudSQLConfig = exports.hasCloudSQL = void 0;
352809
+ exports.getDatabaseDeleteScript = getDatabaseDeleteScript;
352653
352810
 
352654
- var types_1 = __nccwpck_require__(63109);
352811
+ var getDatabaseCreateScript = function (context, deployConfig) {
352812
+ var _a;
352655
352813
 
352656
- var hasCloudSQL = function (context) {
352657
- var _a, _b;
352814
+ if (!deployConfig.cloudSql) {
352815
+ throw new Error("not possible");
352816
+ }
352658
352817
 
352659
- if ((0, types_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
352660
- return (_b = (_a = context.componentConfig.deploy.values) === null || _a === void 0 ? void 0 : _a.cloudsql) === null || _b === void 0 ? void 0 : _b.enabled;
352818
+ var DB_NAME = ((_a = context.environment.envVars) !== null && _a !== void 0 ? _a : {}).DB_NAME;
352819
+
352820
+ if (!DB_NAME) {
352821
+ throw new Error("error: env vars did not specify DB_NAME");
352661
352822
  }
352662
352823
 
352663
- return false;
352824
+ var _b = __read(deployConfig.cloudSql.instanceConnectionName.split(":"), 3),
352825
+ projectId = _b[0],
352826
+ region = _b[1],
352827
+ instanceId = _b[2]; // may fail if it already exists
352828
+
352829
+
352830
+ return (0, gitlab_1.allowFailureInScripts)(["echo \"ensuring Database...\"", "gcloud sql databases create ".concat(DB_NAME, " --instance=").concat(instanceId, " --project ").concat(projectId)]);
352664
352831
  };
352665
352832
 
352666
- exports.hasCloudSQL = hasCloudSQL;
352833
+ exports.getDatabaseCreateScript = getDatabaseCreateScript;
352667
352834
 
352668
- var getCloudSQLConfig = function (context) {
352669
- var _a;
352835
+ /***/ }),
352670
352836
 
352671
- if ((0, types_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
352672
- return (_a = context.componentConfig.deploy.values) === null || _a === void 0 ? void 0 : _a.cloudsql;
352673
- }
352837
+ /***/ 22607:
352838
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
352674
352839
 
352675
- throw new Error("cannot get cloud sql config");
352840
+ "use strict";
352841
+
352842
+
352843
+ exports.__esModule = true;
352844
+ exports.gcloudServiceAccountLoginCommands = void 0;
352845
+
352846
+ var __1 = __nccwpck_require__(81344);
352847
+
352848
+ var context_1 = __nccwpck_require__(22041);
352849
+
352850
+ var gcloudServiceAccountLoginCommands = function (context) {
352851
+ return ["echo $".concat((0, context_1.getSecretVarNameForContext)(context, __1.GCLOUD_DEPLOY_CREDENTIALS_KEY), " > ./____keyfile.json\n "), "gcloud auth activate-service-account --key-file=\"./____keyfile.json\""];
352676
352852
  };
352677
352853
 
352678
- exports.getCloudSQLConfig = getCloudSQLConfig;
352854
+ exports.gcloudServiceAccountLoginCommands = gcloudServiceAccountLoginCommands;
352679
352855
 
352680
352856
  /***/ }),
352681
352857
 
@@ -352882,7 +353058,7 @@ var kubernetes_1 = __nccwpck_require__(95682);
352882
353058
 
352883
353059
  __exportStar(__nccwpck_require__(81344), exports);
352884
353060
 
352885
- __exportStar(__nccwpck_require__(13539), exports);
353061
+ __exportStar(__nccwpck_require__(11925), exports);
352886
353062
 
352887
353063
  __exportStar(__nccwpck_require__(95682), exports);
352888
353064
 
@@ -352939,6 +353115,43 @@ exports.additionalKubernetesSecretKeys = additionalKubernetesSecretKeys;
352939
353115
 
352940
353116
  /***/ }),
352941
353117
 
353118
+ /***/ 11925:
353119
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
353120
+
353121
+ "use strict";
353122
+
353123
+
353124
+ exports.__esModule = true;
353125
+ exports.getKubernetesCloudSQLConfig = exports.hasKubernetesCloudSQL = void 0;
353126
+
353127
+ var types_1 = __nccwpck_require__(63109);
353128
+
353129
+ var hasKubernetesCloudSQL = function (context) {
353130
+ var _a, _b;
353131
+
353132
+ if ((0, types_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
353133
+ return (_b = (_a = context.componentConfig.deploy.values) === null || _a === void 0 ? void 0 : _a.cloudsql) === null || _b === void 0 ? void 0 : _b.enabled;
353134
+ }
353135
+
353136
+ return false;
353137
+ };
353138
+
353139
+ exports.hasKubernetesCloudSQL = hasKubernetesCloudSQL;
353140
+
353141
+ var getKubernetesCloudSQLConfig = function (context) {
353142
+ var _a;
353143
+
353144
+ if ((0, types_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
353145
+ return (_a = context.componentConfig.deploy.values) === null || _a === void 0 ? void 0 : _a.cloudsql;
353146
+ }
353147
+
353148
+ throw new Error("cannot get cloud sql config");
353149
+ };
353150
+
353151
+ exports.getKubernetesCloudSQLConfig = getKubernetesCloudSQLConfig;
353152
+
353153
+ /***/ }),
353154
+
352942
353155
  /***/ 395:
352943
353156
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
352944
353157
 
@@ -353275,7 +353488,7 @@ var lodash_1 = __nccwpck_require__(23255);
353275
353488
 
353276
353489
  var utils_1 = __nccwpck_require__(37461);
353277
353490
 
353278
- var cloudSql_1 = __nccwpck_require__(13539);
353491
+ var cloudSql_1 = __nccwpck_require__(11925);
353279
353492
 
353280
353493
  var types_1 = __nccwpck_require__(63109);
353281
353494
 
@@ -353345,7 +353558,7 @@ var createKubeValues = function (context) {
353345
353558
  var defaultKubeValues = (0, lodash_1.merge)({
353346
353559
  env: env,
353347
353560
  application: createAppConfig(context, application)
353348
- }, (0, cloudSql_1.hasCloudSQL)(context) ? (0, cloudsql_1.createCloudsqlBaseConfig)(context) : {}, ((_b = (_a = deployConfig.values) === null || _a === void 0 ? void 0 : _a.mongodb) === null || _b === void 0 ? void 0 : _b.enabled) ? (0, mongodb_1.createMongodbBaseConfig)(context) : {});
353561
+ }, (0, cloudSql_1.hasKubernetesCloudSQL)(context) ? (0, cloudsql_1.createCloudsqlBaseConfig)(context) : {}, ((_b = (_a = deployConfig.values) === null || _a === void 0 ? void 0 : _a.mongodb) === null || _b === void 0 ? void 0 : _b.enabled) ? (0, mongodb_1.createMongodbBaseConfig)(context) : {});
353349
353562
  var kubeValues = (0, processSecretsAsFiles_1.processSecretsAsFiles)((0, utils_1.mergeWithMergingArrays)(defaultKubeValues, rest));
353350
353563
  return kubeValues;
353351
353564
  };
@@ -355135,7 +355348,7 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
355135
355348
  };
355136
355349
 
355137
355350
  exports.__esModule = true;
355138
- exports.sanitizeForBashVariable = exports.allowFailureInScripts = void 0;
355351
+ exports.repeatOnFailure = exports.sanitizeForBashVariable = exports.allowFailureInScripts = void 0;
355139
355352
 
355140
355353
  var allowFailureInScripts = function (script) {
355141
355354
  return __spreadArray(__spreadArray(["set +e"], __read(script), false), ["set -e" // reenable
@@ -355150,6 +355363,12 @@ var sanitizeForBashVariable = function (name) {
355150
355363
 
355151
355364
  exports.sanitizeForBashVariable = sanitizeForBashVariable;
355152
355365
 
355366
+ var repeatOnFailure = function (command, options) {
355367
+ return "\n until ".concat(command, " &> /dev/null\n do\n echo \"Trying again.\"\n sleep ").concat(options.pauseInSeconds, "\n done\n ");
355368
+ };
355369
+
355370
+ exports.repeatOnFailure = repeatOnFailure;
355371
+
355153
355372
  /***/ }),
355154
355373
 
355155
355374
  /***/ 37461: