@catladder/pipeline 1.53.0 → 1.55.0

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.
package/dist/constants.js CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.DOCKER_REGISTRY = exports.PIPELINE_IMAGE_TAG = void 0;
5
- exports.PIPELINE_IMAGE_TAG = "v1-53-0-709281ec" || "";
5
+ exports.PIPELINE_IMAGE_TAG = "v1-55-0-40141b86" || "";
6
6
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "";
@@ -1,5 +1,5 @@
1
1
  import type { Config } from "../types/config";
2
2
  import type { CommitInfo, Context, Environment } from "../types/context";
3
+ export declare const getEnvironment: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined, alreadyVisited?: Record<string, Record<string, boolean>>) => Promise<Environment>;
3
4
  export declare const getSecretVarName: (env: string, componentName: string, key: string) => string;
4
- export declare const getSecretVarNameForContext: (context: Context, key: string) => string;
5
- export declare const getEnvironment: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined, alreadyVisited?: Record<string, Record<string, boolean>>) => Promise<Environment>;
5
+ export declare const getSecretVarNameForContext: (context: Context, key: string) => string;
@@ -190,52 +190,19 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
190
190
  return to.concat(ar || Array.prototype.slice.call(from));
191
191
  };
192
192
 
193
- var __importDefault = this && this.__importDefault || function (mod) {
194
- return mod && mod.__esModule ? mod : {
195
- "default": mod
196
- };
197
- };
198
-
199
193
  exports.__esModule = true;
200
- exports.getEnvironment = exports.getSecretVarNameForContext = exports.getSecretVarName = void 0;
194
+ exports.getSecretVarNameForContext = exports.getSecretVarName = exports.getEnvironment = void 0;
201
195
 
202
196
  var lodash_1 = require("lodash");
203
197
 
204
- var slugify_1 = __importDefault(require("slugify"));
205
-
206
198
  var deploy_1 = require("../deploy");
207
199
 
208
- var types_1 = require("../deploy/types");
209
-
210
200
  var config_1 = require("../types/config");
211
201
 
212
202
  var utils_1 = require("../utils");
213
203
 
214
204
  var resolveReferences_1 = require("./resolveReferences");
215
205
 
216
- var sanitizeForEnVar = function (s) {
217
- return s.replace(/-/g, "_");
218
- };
219
-
220
- var getSecretVarName = function (env, componentName, key) {
221
- return "CL_".concat(sanitizeForEnVar(env), "_").concat(sanitizeForEnVar(componentName), "_").concat(key);
222
- }; // remove dash from component name
223
-
224
-
225
- exports.getSecretVarName = getSecretVarName;
226
-
227
- var addIndexVar = function (vars) {
228
- return __assign(__assign({}, vars), {
229
- _ALL_ENV_VAR_KEYS: JSON.stringify(Object.keys(vars))
230
- });
231
- };
232
-
233
- var getSecretVarNameForContext = function (context, key) {
234
- return (0, exports.getSecretVarName)(context.environment.shortName, context.componentName, key);
235
- };
236
-
237
- exports.getSecretVarNameForContext = getSecretVarNameForContext;
238
-
239
206
  var getEnvironment = function (config, componentName, env, commitInfo, alreadyVisited // to prevent endless loop
240
207
  ) {
241
208
  if (alreadyVisited === void 0) {
@@ -243,27 +210,15 @@ var getEnvironment = function (config, componentName, env, commitInfo, alreadyVi
243
210
  }
244
211
 
245
212
  return __awaiter(void 0, void 0, void 0, function () {
246
- var defaultConfig, envConfig, mergedConfig, envType, basePredefinedVariables, gitlabEnvironmentName, environmentSlug, predefinedVariables, host, url, fullName, devLocalConfig, port, componentSlug, envInUrl, domainCanonical, HOST_CANONICAL, KUBE_APP_NAME_PREFIX, KUBE_APP_NAME, KUBE_NAMESPACE, publicEnvVarsRaw, additionalSecretKeys, secretEnvVarKeys, secretEnvVars, legacyFromComponents, publicEnvVarsRawWithLegasyFromComponents, publicEnvVarsRawSanitized, envVarsRaw, envVars;
213
+ var envConfig, envType, basePredefinedVariables, gitlabEnvironmentName, environmentSlug, predefinedVariables, host, url, fullName, envVarContext, devLocalConfig, port, additionalEnvVars, publicEnvVarsRaw, additionalSecretKeys, secretEnvVarKeys, secretEnvVars, legacyFromComponents, publicEnvVarsRawWithLegasyFromComponents, publicEnvVarsRawSanitized, envVarsRaw, envVars;
247
214
 
248
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
215
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
249
216
 
250
- return __generator(this, function (_o) {
251
- switch (_o.label) {
217
+ return __generator(this, function (_l) {
218
+ switch (_l.label) {
252
219
  case 0:
253
- defaultConfig = config.components[componentName];
254
-
255
- if (!defaultConfig) {
256
- throw new Error("unknown component " + componentName);
257
- }
258
-
259
- envConfig = (_b = (_a = defaultConfig.env) === null || _a === void 0 ? void 0 : _a[env]) !== null && _b !== void 0 ? _b : {};
260
-
261
- if (envConfig === false) {
262
- throw new Error("env is disabled: " + env);
263
- }
264
-
265
- mergedConfig = (0, utils_1.mergeWithMergingArrays)(defaultConfig, envConfig);
266
- envType = (_c = envConfig === null || envConfig === void 0 ? void 0 : envConfig.type) !== null && _c !== void 0 ? _c : (0, config_1.isKnowEnvType)(env) ? env : null;
220
+ envConfig = getEnvConfig(config, componentName, env);
221
+ envType = (_a = envConfig === null || envConfig === void 0 ? void 0 : envConfig.type) !== null && _a !== void 0 ? _a : (0, config_1.isKnowEnvType)(env) ? env : null;
267
222
 
268
223
  if (!envType) {
269
224
  throw new Error("Missing type in environment " + env + " in component " + componentName);
@@ -271,16 +226,25 @@ var getEnvironment = function (config, componentName, env, commitInfo, alreadyVi
271
226
 
272
227
  basePredefinedVariables = {
273
228
  ENV_SHORT: env,
274
- APP_DIR: mergedConfig.dir,
229
+ APP_DIR: envConfig.dir,
275
230
  ENV_TYPE: envType
276
231
  };
277
232
  gitlabEnvironmentName = envType === "review" && commitInfo ? "".concat(env, "/").concat(commitInfo.refName, "/").concat(componentName) : "".concat(env, "/").concat(componentName);
278
233
  environmentSlug = envType === "review" && commitInfo ? "".concat(env, "-").concat(commitInfo.reviewSlug, "-").concat(componentName) : "".concat(env, "-").concat(componentName);
279
234
  fullName = "".concat(config.customerName, "-").concat(config.appName, "-").concat(environmentSlug);
235
+ envVarContext = {
236
+ deployConfig: envConfig.deploy,
237
+ fullName: fullName,
238
+ envType: envType,
239
+ commitInfo: commitInfo,
240
+ componentName: componentName,
241
+ env: env,
242
+ fullConfig: config
243
+ };
280
244
 
281
245
  if (envType === "local") {
282
- devLocalConfig = mergedConfig;
283
- port = (_d = devLocalConfig.port) !== null && _d !== void 0 ? _d : 3000;
246
+ devLocalConfig = envConfig;
247
+ port = (_b = devLocalConfig.port) !== null && _b !== void 0 ? _b : 3000;
284
248
  host = "localhost:" + port;
285
249
  url = "http://" + host;
286
250
  predefinedVariables = {
@@ -289,34 +253,22 @@ var getEnvironment = function (config, componentName, env, commitInfo, alreadyVi
289
253
  PORT: port.toString()
290
254
  };
291
255
  } else {
292
- componentSlug = (0, slugify_1["default"])(componentName);
293
- envInUrl = envType === "review" && commitInfo ? "".concat(commitInfo.reviewSlug, ".").concat(env) : env;
294
- domainCanonical = (mergedConfig === null || mergedConfig === void 0 ? void 0 : mergedConfig.deploy) && (mergedConfig === null || mergedConfig === void 0 ? void 0 : mergedConfig.deploy.type) === "kubernetes" && ((_e = mergedConfig.deploy.cluster) === null || _e === void 0 ? void 0 : _e.domainCanonical) || // for convenience, we allow clusters to define a canonical domain, because a cluster has a fixed ip and you will usually have a domain pointing to that cluster
295
- config.domainCanonical || "panter.cloud";
296
- HOST_CANONICAL = (0, types_1.isOfDeployType)(mergedConfig.deploy, "google-cloudrun") ? fullName.toLowerCase() + "-" + process.env[(0, exports.getSecretVarName)(env, componentName, deploy_1.GCLOUD_RUN_CANONICAL_HOST_SUFFIX)] : "".concat(componentSlug, ".").concat(envInUrl, ".").concat(config.appName, ".").concat(config.customerName, ".").concat(domainCanonical);
297
- host = (_f = mergedConfig === null || mergedConfig === void 0 ? void 0 : mergedConfig.host) !== null && _f !== void 0 ? _f : HOST_CANONICAL;
256
+ additionalEnvVars = envConfig.deploy ? deploy_1.DEPLOY_TYPES[envConfig.deploy.type].getAdditionalEnvVars(envVarContext) : {};
257
+ host = (_d = (_c = envConfig === null || envConfig === void 0 ? void 0 : envConfig.host) !== null && _c !== void 0 ? _c : additionalEnvVars.HOST_CANONICAL) !== null && _d !== void 0 ? _d : "unknown-host.example.com";
298
258
  url = "https://".concat(host);
299
- KUBE_APP_NAME_PREFIX = envType === "review" && commitInfo ? "".concat(commitInfo.reviewSlug, "-") : "";
300
- KUBE_APP_NAME = "".concat(KUBE_APP_NAME_PREFIX).concat(componentName);
301
- KUBE_NAMESPACE = (0, deploy_1.getKubernetesNamespace)(config, env);
302
- predefinedVariables = __assign(__assign({}, basePredefinedVariables), {
303
- HOST_CANONICAL: HOST_CANONICAL,
259
+ predefinedVariables = __assign(__assign(__assign({}, basePredefinedVariables), {
304
260
  HOST: host,
305
- ROOT_URL: url,
306
- KUBE_NAMESPACE: KUBE_NAMESPACE,
307
- KUBE_APP_NAME: KUBE_APP_NAME,
308
- KUBE_APP_NAME_PREFIX: KUBE_APP_NAME_PREFIX
309
- });
261
+ ROOT_URL: url
262
+ }), additionalEnvVars);
310
263
  }
311
264
 
312
- publicEnvVarsRaw = (_h = (_g = mergedConfig.vars) === null || _g === void 0 ? void 0 : _g.public) !== null && _h !== void 0 ? _h : {};
313
- additionalSecretKeys = mergedConfig.deploy ? deploy_1.DEPLOY_TYPES[mergedConfig.deploy.type].additionalSecretKeys( // eslint-disable-next-line @typescript-eslint/no-explicit-any
314
- mergedConfig.deploy) : [];
315
- secretEnvVarKeys = __spreadArray(__spreadArray([], __read((_k = (_j = mergedConfig.vars) === null || _j === void 0 ? void 0 : _j.secret) !== null && _k !== void 0 ? _k : []), false), __read(additionalSecretKeys), false);
265
+ publicEnvVarsRaw = (_f = (_e = envConfig.vars) === null || _e === void 0 ? void 0 : _e.public) !== null && _f !== void 0 ? _f : {};
266
+ additionalSecretKeys = envConfig.deploy ? deploy_1.DEPLOY_TYPES[envConfig.deploy.type].additionalSecretKeys(envVarContext) : [];
267
+ secretEnvVarKeys = __spreadArray(__spreadArray([], __read((_h = (_g = envConfig.vars) === null || _g === void 0 ? void 0 : _g.secret) !== null && _h !== void 0 ? _h : []), false), __read(additionalSecretKeys), false);
316
268
  secretEnvVars = Object.fromEntries(secretEnvVarKeys.map(function (key) {
317
269
  return [key, "$".concat((0, exports.getSecretVarName)(env, componentName, key))];
318
270
  }));
319
- legacyFromComponents = (_m = (_l = mergedConfig.vars) === null || _l === void 0 ? void 0 : _l.fromComponents) !== null && _m !== void 0 ? _m : {};
271
+ legacyFromComponents = (_k = (_j = envConfig.vars) === null || _j === void 0 ? void 0 : _j.fromComponents) !== null && _k !== void 0 ? _k : {};
320
272
  publicEnvVarsRawWithLegasyFromComponents = (0, lodash_1.merge)({}, (0, resolveReferences_1.translateLegacyFromComponents)(legacyFromComponents), publicEnvVarsRaw);
321
273
  publicEnvVarsRawSanitized = Object.fromEntries(Object.entries(publicEnvVarsRawWithLegasyFromComponents).map(function (_a) {
322
274
  var _b = __read(_a, 2),
@@ -349,7 +301,7 @@ var getEnvironment = function (config, componentName, env, commitInfo, alreadyVi
349
301
  }, alreadyVisited)];
350
302
 
351
303
  case 1:
352
- envVars = _o.sent();
304
+ envVars = _l.sent();
353
305
  return [2
354
306
  /*return*/
355
307
  , {
@@ -371,4 +323,45 @@ var getEnvironment = function (config, componentName, env, commitInfo, alreadyVi
371
323
  });
372
324
  };
373
325
 
374
- exports.getEnvironment = getEnvironment;
326
+ exports.getEnvironment = getEnvironment;
327
+
328
+ var sanitizeForEnVar = function (s) {
329
+ return s.replace(/-/g, "_");
330
+ };
331
+
332
+ var getSecretVarName = function (env, componentName, key) {
333
+ return "CL_".concat(sanitizeForEnVar(env), "_").concat(sanitizeForEnVar(componentName), "_").concat(key);
334
+ }; // remove dash from component name
335
+
336
+
337
+ exports.getSecretVarName = getSecretVarName;
338
+
339
+ var addIndexVar = function (vars) {
340
+ return __assign(__assign({}, vars), {
341
+ _ALL_ENV_VAR_KEYS: JSON.stringify(Object.keys(vars))
342
+ });
343
+ };
344
+
345
+ var getSecretVarNameForContext = function (context, key) {
346
+ return (0, exports.getSecretVarName)(context.environment.shortName, context.componentName, key);
347
+ };
348
+
349
+ exports.getSecretVarNameForContext = getSecretVarNameForContext;
350
+
351
+ var getEnvConfig = function (config, componentName, env) {
352
+ var _a, _b;
353
+
354
+ var defaultConfig = config.components[componentName];
355
+
356
+ if (!defaultConfig) {
357
+ throw new Error("unknown component " + componentName);
358
+ }
359
+
360
+ var envCustomizations = (_b = (_a = defaultConfig.env) === null || _a === void 0 ? void 0 : _a[env]) !== null && _b !== void 0 ? _b : {};
361
+
362
+ if (envCustomizations === false) {
363
+ throw new Error("env is disabled: " + env);
364
+ }
365
+
366
+ return (0, utils_1.mergeWithMergingArrays)(defaultConfig, envCustomizations);
367
+ };
@@ -1,3 +1,3 @@
1
1
  import type { Context } from "../../types/context";
2
2
  import type { CatladderJob } from "../../types/jobs";
3
- export declare const createDeployJob: (context: Context) => CatladderJob[];
3
+ export declare const createGoogleCloudRunDeployJobs: (context: Context) => CatladderJob[];
@@ -36,7 +36,7 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
36
36
  };
37
37
 
38
38
  exports.__esModule = true;
39
- exports.createDeployJob = void 0;
39
+ exports.createGoogleCloudRunDeployJobs = void 0;
40
40
 
41
41
  var js_yaml_1 = require("js-yaml");
42
42
 
@@ -56,7 +56,9 @@ var types_1 = require("../types");
56
56
 
57
57
  var gcloudServiceAccountLoginCommands_1 = require("./utils/gcloudServiceAccountLoginCommands");
58
58
 
59
- var createDeployJob = function (context) {
59
+ var createGoogleCloudRunDeployJobs = function (context) {
60
+ var _a, _b;
61
+
60
62
  var deployConfig = context.componentConfig.deploy;
61
63
 
62
64
  if (deployConfig === false) {
@@ -65,7 +67,7 @@ var createDeployJob = function (context) {
65
67
 
66
68
  if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
67
69
  // should not happen
68
- throw new Error("deploy config is not custom");
70
+ throw new Error("deploy config is wrong");
69
71
  }
70
72
 
71
73
  var baseDeploymentJob = (0, base_1.getBaseDeploymentJob)(context);
@@ -76,7 +78,6 @@ var createDeployJob = function (context) {
76
78
  var pushImageToArtifactsRegistry = __spreadArray(__spreadArray([docker_1.gitlabDockerLogin], __read((0, gcloudServiceAccountLoginCommands_1.gcloudServiceAccountLoginCommands)(context)), false), ["gcloud auth configure-docker ".concat(deployConfig.region, "-docker.pkg.dev"), "docker pull $DOCKER_IMAGE:$DOCKER_IMAGE_TAG", "docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG ".concat(gcloudImageName), "docker push ".concat(gcloudImageName)], false);
77
79
 
78
80
  var allEnvVars = (0, lodash_1.omit)(context.environment.envVars, _1.GCLOUD_DEPLOY_CREDENTIALS_KEY);
79
- var serviceName = context.environment.fullName.toLowerCase();
80
81
  var labelsString = Object.entries((0, getLabels_1.getLabels)(context)).map(function (_a) {
81
82
  var _b = __read(_a, 2),
82
83
  key = _b[0],
@@ -84,15 +85,77 @@ var createDeployJob = function (context) {
84
85
 
85
86
  return "".concat(key, "=").concat(value);
86
87
  }).join(",");
87
- var command = context.componentConfig.build.startCommand ? "--command=\"".concat(context.componentConfig.build.startCommand.split(" ").join(","), "\"") : ""; // TODO: split secrets out
88
+ var commonArgs = "--project ".concat(deployConfig.projectId, " --region=").concat(deployConfig.region);
89
+ var commonDeployArgs = "--image ".concat(gcloudImageName, " ").concat(commonArgs, " --labels ").concat(labelsString);
90
+ var serviceName = context.environment.fullName.toLowerCase();
91
+
92
+ var getServiceDeployScript = function (service) {
93
+ var _a;
94
+
95
+ var command = service !== true ? (_a = service === null || service === void 0 ? void 0 : service.command) !== null && _a !== void 0 ? _a : context.componentConfig.build.startCommand : undefined;
96
+ var commandArg = command ? "--command=\"".concat(command.split(" ").join(","), "\"") : "";
97
+ return "gcloud run deploy ".concat(serviceName, " ").concat(commandArg, " ").concat(commonDeployArgs, " --env-vars-file=____envvars.yaml --allow-unauthenticated");
98
+ };
99
+
100
+ var getJobDeployScripts = function (jobName, job) {
101
+ // due to some oversight from google, jobs create does not accept `--env-vars-file` 🤦
102
+ // lucky, update on the other hand accepts it... so let's just imediatly update it
103
+ // also we cannot upsert a job, so we have to create it and catch the error and then update
104
+ var args = "".concat(jobName, " --command=\"").concat(job.command.split(" ").join(","), "\" ").concat(commonDeployArgs);
105
+ return ["set +e", "gcloud beta run jobs create ".concat(args), "set -e", "gcloud beta run jobs update ".concat(args, " --env-vars-file=____envvars.yaml")];
106
+ };
107
+
108
+ var getJobRunScript = function (jobName) {
109
+ return "gcloud beta run jobs execute ".concat(jobName, " ").concat(commonArgs);
110
+ };
111
+
112
+ var getFullJobName = function (name) {
113
+ return context.environment.fullName.toLowerCase() + "-" + name;
114
+ };
115
+
116
+ var jobsWithNames = Object.entries((_a = deployConfig.jobs) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
117
+ var _b = __read(_a, 2),
118
+ name = _b[0],
119
+ job = _b[1];
120
+
121
+ return [getFullJobName(name), job];
122
+ });
123
+
124
+ var cloudRunDeployScripts = __spreadArray(__spreadArray(__spreadArray(__spreadArray(["echo \"$ENV_VARS\" > ____envvars.yaml"], __read(jobsWithNames.map(function (_a) {
125
+ var _b = __read(_a, 2),
126
+ name = _b[0],
127
+ job = _b[1];
128
+
129
+ return getJobDeployScripts(name, job);
130
+ }).flat()), false), __read(deployConfig.service !== false ? [getServiceDeployScript(deployConfig.service)] : []), false), __read(jobsWithNames.filter(function (_a) {
131
+ var _b = __read(_a, 2),
132
+ name = _b[0],
133
+ job = _b[1];
134
+
135
+ return job.when === "postDeploy";
136
+ }).map(function (_a) {
137
+ var _b = __read(_a, 2),
138
+ name = _b[0],
139
+ job = _b[1];
140
+
141
+ return getJobRunScript(name);
142
+ })), false), ["docker image rm ".concat(gcloudImageName)], false);
143
+
144
+ var cloudRunStopScripts = __spreadArray(__spreadArray([], __read(deployConfig.service !== false ? ["gcloud run services delete ".concat(serviceName)] : []), false), __read(Object.entries((_b = deployConfig.jobs) !== null && _b !== void 0 ? _b : {}).map(function (_a) {
145
+ var _b = __read(_a, 2),
146
+ jobName = _b[0],
147
+ job = _b[1];
148
+
149
+ return "gcloud beta run jobs delete ".concat(jobName);
150
+ })), false);
88
151
 
89
- var cloudRunDeploy = ["echo \"$ENV_VARS\" > ____envvars.yaml", "gcloud run deploy ".concat(serviceName, " --image ").concat(gcloudImageName, " --region=").concat(deployConfig.region, " --allow-unauthenticated --project ").concat(deployConfig.projectId, " ").concat(command, " --env-vars-file=____envvars.yaml --labels ").concat(labelsString), "docker image rm ".concat(gcloudImageName)];
90
152
  var baseStopJob = (0, base_1.getBaseDeploymentStopJob)(context);
91
153
  return [(0, lodash_1.merge)({}, baseDeploymentJob, (0, docker_1.getDockerJobBaseProps)(context), {
92
154
  artifacts: {
93
155
  paths: ["____envvars.yaml"]
94
156
  },
95
157
  variables: {
158
+ CLOUDSDK_CORE_DISABLE_PROMPTS: "1",
96
159
  ENV_VARS: (0, js_yaml_1.dump)(allEnvVars, {
97
160
  lineWidth: -1,
98
161
  quotingType: "'",
@@ -100,11 +163,14 @@ var createDeployJob = function (context) {
100
163
  })
101
164
  },
102
165
  image: (0, runner_1.getRunnerImage)("gcloud"),
103
- script: __spreadArray(__spreadArray([], __read(pushImageToArtifactsRegistry), false), __read(cloudRunDeploy), false)
166
+ script: __spreadArray(__spreadArray([], __read(pushImageToArtifactsRegistry), false), __read(cloudRunDeployScripts), false)
104
167
  }), (0, lodash_1.merge)({}, baseStopJob, {
105
168
  image: (0, runner_1.getRunnerImage)("gcloud"),
106
- script: __spreadArray(__spreadArray([], __read((0, gcloudServiceAccountLoginCommands_1.gcloudServiceAccountLoginCommands)(context)), false), ["gcloud run services delete ".concat(serviceName, " --project ").concat(deployConfig.projectId, " --region=").concat(deployConfig.region, " --quiet")], false)
169
+ variables: {
170
+ CLOUDSDK_CORE_DISABLE_PROMPTS: "1"
171
+ },
172
+ script: __spreadArray(__spreadArray([], __read((0, gcloudServiceAccountLoginCommands_1.gcloudServiceAccountLoginCommands)(context)), false), __read(cloudRunStopScripts), false)
107
173
  })];
108
174
  };
109
175
 
110
- exports.createDeployJob = createDeployJob;
176
+ exports.createGoogleCloudRunDeployJobs = createGoogleCloudRunDeployJobs;
@@ -1,18 +1,76 @@
1
1
  "use strict";
2
2
 
3
+ var __assign = this && this.__assign || function () {
4
+ __assign = Object.assign || function (t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+
8
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
9
+ }
10
+
11
+ return t;
12
+ };
13
+
14
+ return __assign.apply(this, arguments);
15
+ };
16
+
17
+ var __read = this && this.__read || function (o, n) {
18
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
19
+ if (!m) return o;
20
+ var i = m.call(o),
21
+ r,
22
+ ar = [],
23
+ e;
24
+
25
+ try {
26
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
27
+ } catch (error) {
28
+ e = {
29
+ error: error
30
+ };
31
+ } finally {
32
+ try {
33
+ if (r && !r.done && (m = i["return"])) m.call(i);
34
+ } finally {
35
+ if (e) throw e.error;
36
+ }
37
+ }
38
+
39
+ return ar;
40
+ };
41
+
3
42
  exports.__esModule = true;
4
43
  exports.GCLOUD_RUN_DEPLOY_TYPE = exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = void 0;
5
44
 
45
+ var context_1 = require("../../context");
46
+
6
47
  var deployJob_1 = require("./deployJob");
7
48
 
8
49
  exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
9
50
  exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = "GCLOUD_RUN_canonicalHostSuffix";
10
51
  exports.GCLOUD_RUN_DEPLOY_TYPE = {
11
- jobs: deployJob_1.createDeployJob,
52
+ jobs: deployJob_1.createGoogleCloudRunDeployJobs,
12
53
  defaults: function () {
13
54
  return {};
14
55
  },
15
56
  additionalSecretKeys: function () {
16
57
  return [exports.GCLOUD_DEPLOY_CREDENTIALS_KEY];
58
+ },
59
+ getAdditionalEnvVars: function (_a) {
60
+ var fullName = _a.fullName,
61
+ env = _a.env,
62
+ componentName = _a.componentName,
63
+ deployConfig = _a.deployConfig;
64
+ var HOST_CANONICAL = fullName.toLowerCase() + "-" + process.env[(0, context_1.getSecretVarName)(env, componentName, exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX)];
65
+ var jobTriggers = deployConfig && deployConfig.jobs ? Object.fromEntries(Object.entries(deployConfig.jobs).map(function (_a) {
66
+ var _b = __read(_a, 2),
67
+ name = _b[0],
68
+ job = _b[1];
69
+
70
+ return ["CLOUD_RUN_JOB_TRIGGER_URL_" + name, "https://".concat(deployConfig.region, "-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/").concat(deployConfig.projectId, "/jobs/").concat(name, ":run")];
71
+ })) : {};
72
+ return __assign({
73
+ HOST_CANONICAL: HOST_CANONICAL
74
+ }, jobTriggers);
17
75
  }
18
76
  };
@@ -12,5 +12,8 @@ exports.CUSTOM_DEPLOY_TYPE = {
12
12
  },
13
13
  additionalSecretKeys: function () {
14
14
  return [];
15
+ },
16
+ getAdditionalEnvVars: function () {
17
+ return {};
15
18
  }
16
19
  };
@@ -12,5 +12,8 @@ exports.DOCKER_TAG_DEPLOY_TYPE = {
12
12
  },
13
13
  additionalSecretKeys: function () {
14
14
  return [];
15
+ },
16
+ getAdditionalEnvVars: function () {
17
+ return {};
15
18
  }
16
19
  };
@@ -1,13 +1,28 @@
1
- import type { Context } from "../types/context";
1
+ import type { Config, EnvType } from "../types";
2
+ import type { CommitInfo, Context } from "../types/context";
2
3
  import type { CatladderJob } from "../types/jobs";
3
4
  import type { DeployConfigGeneric, DeployConfigType } from "./types";
4
5
  export * from "./kubernetes";
5
6
  export * from "./types";
6
7
  export * from "./utils";
8
+ export declare type EnvVarContext<D extends DeployConfigType> = {
9
+ deployConfig: false | DeployConfigGeneric<D>;
10
+ commitInfo?: CommitInfo;
11
+ env: string;
12
+ envType: EnvType;
13
+ componentName: string;
14
+ fullName: string;
15
+ /**
16
+ * the full catladder config
17
+ */
18
+
19
+ fullConfig: Config;
20
+ };
7
21
  export declare type DeployTypeDefinition<T extends DeployConfigType> = {
8
22
  jobs: (context: Context) => CatladderJob[];
9
23
  defaults: () => Partial<DeployConfigGeneric<T>>;
10
- additionalSecretKeys: (config: DeployConfigGeneric<T>) => string[];
24
+ additionalSecretKeys: (envVarContext: EnvVarContext<T>) => string[];
25
+ getAdditionalEnvVars: (envVarContext: EnvVarContext<T>) => Record<string, string | undefined | null>;
11
26
  };
12
27
  export * from "./cloudSql";
13
28
  export * from "./cloudRun";
@@ -41,6 +41,6 @@ __exportStar(require("./cloudRun"), exports);
41
41
  exports.DEPLOY_TYPES = {
42
42
  kubernetes: kubernetes_1.KUBERNETES_DEPLOY_TYPE,
43
43
  custom: custom_1.CUSTOM_DEPLOY_TYPE,
44
- "google-cloudrun": cloudRun_1.GCLOUD_RUN_DEPLOY_TYPE,
45
- dockerTag: dockerTag_1.DOCKER_TAG_DEPLOY_TYPE
44
+ dockerTag: dockerTag_1.DOCKER_TAG_DEPLOY_TYPE,
45
+ "google-cloudrun": cloudRun_1.GCLOUD_RUN_DEPLOY_TYPE
46
46
  };
@@ -1,2 +1,4 @@
1
- import type { DeployConfigKubernetes } from "../types";
2
- export declare const additionalKubernetesSecretKeys: (config: DeployConfigKubernetes) => string[];
1
+ import type { EnvVarContext } from "..";
2
+ export declare const additionalKubernetesSecretKeys: ({
3
+ deployConfig
4
+ }: EnvVarContext<"kubernetes">) => string[];
@@ -3,20 +3,26 @@
3
3
  exports.__esModule = true;
4
4
  exports.additionalKubernetesSecretKeys = void 0;
5
5
 
6
- var additionalKubernetesSecretKeys = function (config) {
7
- var _a, _b, _c, _d;
6
+ var additionalKubernetesSecretKeys = function (_a) {
7
+ var _b, _c, _d, _e;
8
+
9
+ var deployConfig = _a.deployConfig;
10
+
11
+ if (!deployConfig) {
12
+ return [];
13
+ }
8
14
 
9
15
  var keys = [];
10
16
 
11
- if ((_b = (_a = config.values) === null || _a === void 0 ? void 0 : _a.mongodb) === null || _b === void 0 ? void 0 : _b.enabled) {
17
+ if ((_c = (_b = deployConfig.values) === null || _b === void 0 ? void 0 : _b.mongodb) === null || _c === void 0 ? void 0 : _c.enabled) {
12
18
  keys.push("MONGODB_ROOT_PASSWORD");
13
19
 
14
- if (config.values.mongodb.architecture === "replicaset") {
20
+ if (deployConfig.values.mongodb.architecture === "replicaset") {
15
21
  keys.push("MONGODB_REPLICASET_KEY");
16
22
  }
17
23
  }
18
24
 
19
- if ((_d = (_c = config.values) === null || _c === void 0 ? void 0 : _c.cloudsql) === null || _d === void 0 ? void 0 : _d.enabled) {
25
+ if ((_e = (_d = deployConfig.values) === null || _d === void 0 ? void 0 : _d.cloudsql) === null || _e === void 0 ? void 0 : _e.enabled) {
20
26
  keys.push("POSTGRESQL_PASSWORD");
21
27
  keys.push("cloudsqlProxyCredentials");
22
28
  }
@@ -1,8 +1,18 @@
1
1
  "use strict";
2
2
 
3
+ var __importDefault = this && this.__importDefault || function (mod) {
4
+ return mod && mod.__esModule ? mod : {
5
+ "default": mod
6
+ };
7
+ };
8
+
3
9
  exports.__esModule = true;
4
10
  exports.KUBERNETES_DEPLOY_TYPE = void 0;
5
11
 
12
+ var slugify_1 = __importDefault(require("slugify"));
13
+
14
+ var __1 = require("..");
15
+
6
16
  var additionalSecretKeys_1 = require("./additionalSecretKeys");
7
17
 
8
18
  var deployJob_1 = require("./deployJob");
@@ -12,5 +22,30 @@ exports.KUBERNETES_DEPLOY_TYPE = {
12
22
  defaults: function () {
13
23
  return {};
14
24
  },
15
- additionalSecretKeys: additionalSecretKeys_1.additionalKubernetesSecretKeys
25
+ additionalSecretKeys: additionalSecretKeys_1.additionalKubernetesSecretKeys,
26
+ getAdditionalEnvVars: function (_a) {
27
+ var _b;
28
+
29
+ var componentName = _a.componentName,
30
+ fullConfig = _a.fullConfig,
31
+ deployConfig = _a.deployConfig,
32
+ env = _a.env,
33
+ envType = _a.envType,
34
+ commitInfo = _a.commitInfo;
35
+ var KUBE_APP_NAME_PREFIX = envType === "review" && commitInfo ? "".concat(commitInfo.reviewSlug, "-") : "";
36
+ var KUBE_APP_NAME = "".concat(KUBE_APP_NAME_PREFIX).concat(componentName);
37
+ var KUBE_NAMESPACE = (0, __1.getKubernetesNamespace)(fullConfig, env);
38
+ var componentSlug = (0, slugify_1["default"])(componentName);
39
+ var envInUrl = envType === "review" && commitInfo ? "".concat(commitInfo.reviewSlug, ".").concat(env) : env;
40
+ var domainCanonical = deployConfig && ((_b = deployConfig.cluster) === null || _b === void 0 ? void 0 : _b.domainCanonical) || // for convenience, we allow clusters to define a canonical domain, because a cluster has a fixed ip and you will usually have a domain pointing to that cluster
41
+ fullConfig.domainCanonical || "panter.cloud";
42
+ var HOST_CANONICAL = "".concat(componentSlug, ".").concat(envInUrl, ".").concat(fullConfig.appName, ".").concat(fullConfig.customerName, ".").concat(domainCanonical); // default for kubernetes and rest
43
+
44
+ return {
45
+ KUBE_NAMESPACE: KUBE_NAMESPACE,
46
+ KUBE_APP_NAME: KUBE_APP_NAME,
47
+ KUBE_APP_NAME_PREFIX: KUBE_APP_NAME_PREFIX,
48
+ HOST_CANONICAL: HOST_CANONICAL
49
+ };
50
+ }
16
51
  };
@@ -1,9 +1,24 @@
1
1
  import type { DeployConfigBase } from "./base";
2
2
  export declare type Gcloudregion = "asia-east1" | "asia-northeast1" | "asia-northeast2" | "europe-north1" | "europe-southwest1" | "europe-west1" | "europe-west4" | "europe-west8" | "europe-west9" | "me-west1" | "us-central1" | "us-east1" | "us-east4" | "us-east5" | "us-south1" | "us-west1" | "asia-east2" | "asia-northeast3" | "asia-southeast1" | "asia-southeast2" | "asia-south1" | "asia-south2" | "australia-southeast1" | "australia-southeast2" | "europe-central2" | "europe-west2" | "europe-west3" | "europe-west6" | "northamerica-northeast1" | "northamerica-northeast2" | "southamerica-east1" | "southamerica-west1" | "us-west2" | "us-west3" | "us-west4";
3
+ export declare type DeployConfigCloudRunService = {
4
+ /**
5
+ * command / entrypoint, fallsback to buildConfig.startcommand
6
+ */
7
+ command?: string;
8
+ };
9
+ export declare type DeployConfigCloudRunJob = {
10
+ /**
11
+ * command
12
+ */
13
+ command: string;
14
+ when: "manual" | "postDeploy";
15
+ };
3
16
  export declare type DeployConfigCloudRun = {
4
17
  /**
5
18
  * EXPERIMENTAL cloud run deployment.
6
19
  *
20
+ * This will deploy a cloud run service.
21
+ *
7
22
  * Requires that cloud run is enabled on the project, as well as cloud run api and artifacts registry.
8
23
  */
9
24
  type: "google-cloudrun";
@@ -17,4 +32,12 @@ export declare type DeployConfigCloudRun = {
17
32
  */
18
33
 
19
34
  region: Gcloudregion;
35
+ /**
36
+ * whether to enable the service, defaults to true
37
+ */
38
+
39
+ service?: boolean | DeployConfigCloudRunService;
40
+ jobs?: {
41
+ [name: string]: DeployConfigCloudRunJob;
42
+ };
20
43
  } & DeployConfigBase;