@catladder/pipeline 1.52.2 → 1.54.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-52-2-6a3a3676" || "";
5
+ exports.PIPELINE_IMAGE_TAG = "v1-54-0-a367bcd6" || "";
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,16 +56,16 @@ 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
60
  var deployConfig = context.componentConfig.deploy;
61
61
 
62
62
  if (deployConfig === false) {
63
63
  return [];
64
64
  }
65
65
 
66
- if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
66
+ if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun", "google-cloudrun-job")) {
67
67
  // should not happen
68
- throw new Error("deploy config is not custom");
68
+ throw new Error("deploy config is wrong");
69
69
  }
70
70
 
71
71
  var baseDeploymentJob = (0, base_1.getBaseDeploymentJob)(context);
@@ -76,7 +76,6 @@ var createDeployJob = function (context) {
76
76
  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
77
 
78
78
  var allEnvVars = (0, lodash_1.omit)(context.environment.envVars, _1.GCLOUD_DEPLOY_CREDENTIALS_KEY);
79
- var serviceName = context.environment.fullName.toLowerCase();
80
79
  var labelsString = Object.entries((0, getLabels_1.getLabels)(context)).map(function (_a) {
81
80
  var _b = __read(_a, 2),
82
81
  key = _b[0],
@@ -84,9 +83,39 @@ var createDeployJob = function (context) {
84
83
 
85
84
  return "".concat(key, "=").concat(value);
86
85
  }).join(",");
87
- var command = context.componentConfig.build.startCommand ? "--command=\"".concat(context.componentConfig.build.startCommand.split(" ").join(","), "\"") : ""; // TODO: split secrets out
86
+ var commonArgs = "--project ".concat(deployConfig.projectId, " --region=").concat(deployConfig.region);
88
87
 
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)];
88
+ var getDeployCommand = function () {
89
+ var _a;
90
+
91
+ var name = context.environment.fullName.toLowerCase();
92
+ var command = (_a = deployConfig.command) !== null && _a !== void 0 ? _a : context.componentConfig.build.startCommand;
93
+ var commandArg = command ? "--command=\"".concat(command.split(" ").join(","), "\"") : "";
94
+ var commonDeployArgs = "".concat(commandArg, " --image ").concat(gcloudImageName, " ").concat(commonArgs, " --env-vars-file=____envvars.yaml --labels ").concat(labelsString);
95
+
96
+ if (deployConfig.type === "google-cloudrun") {
97
+ return "gcloud run deploy ".concat(name, " ").concat(commonDeployArgs, " --allow-unauthenticated");
98
+ }
99
+
100
+ if (deployConfig.type === "google-cloudrun-job") {
101
+ return "gcloud beta run jobs create ".concat(name, " ").concat(commonDeployArgs);
102
+ }
103
+ };
104
+
105
+ var getStopCommand = function () {
106
+ var name = context.environment.fullName.toLowerCase();
107
+ var commonStopArgs = "".concat(commonArgs, " --quiet");
108
+
109
+ if (deployConfig.type === "google-cloudrun") {
110
+ return "gcloud run services delete ".concat(name, " ").concat(commonStopArgs);
111
+ }
112
+
113
+ if (deployConfig.type === "google-cloudrun-job") {
114
+ return "gcloud beta run jobs delete ".concat(name, " ").concat(commonStopArgs);
115
+ }
116
+ };
117
+
118
+ var cloudRunDeploy = ["echo \"$ENV_VARS\" > ____envvars.yaml", getDeployCommand(), "docker image rm ".concat(gcloudImageName)];
90
119
  var baseStopJob = (0, base_1.getBaseDeploymentStopJob)(context);
91
120
  return [(0, lodash_1.merge)({}, baseDeploymentJob, (0, docker_1.getDockerJobBaseProps)(context), {
92
121
  artifacts: {
@@ -103,8 +132,8 @@ var createDeployJob = function (context) {
103
132
  script: __spreadArray(__spreadArray([], __read(pushImageToArtifactsRegistry), false), __read(cloudRunDeploy), false)
104
133
  }), (0, lodash_1.merge)({}, baseStopJob, {
105
134
  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)
135
+ script: __spreadArray(__spreadArray([], __read((0, gcloudServiceAccountLoginCommands_1.gcloudServiceAccountLoginCommands)(context)), false), [getStopCommand()], false)
107
136
  })];
108
137
  };
109
138
 
110
- exports.createDeployJob = createDeployJob;
139
+ exports.createGoogleCloudRunDeployJobs = createGoogleCloudRunDeployJobs;
@@ -1,4 +1,9 @@
1
1
  import type { DeployTypeDefinition } from "..";
2
2
  export declare const GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
3
3
  export declare const GCLOUD_RUN_CANONICAL_HOST_SUFFIX = "GCLOUD_RUN_canonicalHostSuffix";
4
- export declare const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<"google-cloudrun">;
4
+ export declare const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<"google-cloudrun">;
5
+ export declare const GCLOUD_RUN_JOB_DEPLOY_TYPE: DeployTypeDefinition<"google-cloudrun-job">;
6
+ export declare const GCLOUD_RUN_DEPLOY_TYPES: {
7
+ "google-cloudrun": DeployTypeDefinition<"google-cloudrun">;
8
+ "google-cloudrun-job": DeployTypeDefinition<"google-cloudrun-job">;
9
+ };
@@ -1,18 +1,56 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.GCLOUD_RUN_DEPLOY_TYPE = exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = void 0;
4
+ exports.GCLOUD_RUN_DEPLOY_TYPES = exports.GCLOUD_RUN_JOB_DEPLOY_TYPE = exports.GCLOUD_RUN_DEPLOY_TYPE = exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = void 0;
5
+
6
+ var context_1 = require("../../context");
5
7
 
6
8
  var deployJob_1 = require("./deployJob");
7
9
 
8
10
  exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
9
11
  exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = "GCLOUD_RUN_canonicalHostSuffix";
10
12
  exports.GCLOUD_RUN_DEPLOY_TYPE = {
11
- jobs: deployJob_1.createDeployJob,
13
+ jobs: deployJob_1.createGoogleCloudRunDeployJobs,
12
14
  defaults: function () {
13
15
  return {};
14
16
  },
15
17
  additionalSecretKeys: function () {
16
18
  return [exports.GCLOUD_DEPLOY_CREDENTIALS_KEY];
19
+ },
20
+ getAdditionalEnvVars: function (_a) {
21
+ var fullName = _a.fullName,
22
+ env = _a.env,
23
+ componentName = _a.componentName;
24
+ var HOST_CANONICAL = fullName.toLowerCase() + "-" + process.env[(0, context_1.getSecretVarName)(env, componentName, exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX)];
25
+ return {
26
+ HOST_CANONICAL: HOST_CANONICAL
27
+ };
28
+ }
29
+ };
30
+ exports.GCLOUD_RUN_JOB_DEPLOY_TYPE = {
31
+ jobs: deployJob_1.createGoogleCloudRunDeployJobs,
32
+ defaults: function () {
33
+ return {};
34
+ },
35
+ additionalSecretKeys: function () {
36
+ return [exports.GCLOUD_DEPLOY_CREDENTIALS_KEY];
37
+ },
38
+ getAdditionalEnvVars: function (_a) {
39
+ var deployConfig = _a.deployConfig,
40
+ fullName = _a.fullName;
41
+
42
+ if (!deployConfig) {
43
+ return {};
44
+ }
45
+
46
+ var jobName = fullName.toLowerCase();
47
+ var CLOUD_RUN_JOB_TRIGGER_URL = "https://".concat(deployConfig.region, "-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/").concat(deployConfig.projectId, "/jobs/").concat(jobName, ":run");
48
+ return {
49
+ CLOUD_RUN_JOB_TRIGGER_URL: CLOUD_RUN_JOB_TRIGGER_URL
50
+ };
17
51
  }
52
+ };
53
+ exports.GCLOUD_RUN_DEPLOY_TYPES = {
54
+ "google-cloudrun": exports.GCLOUD_RUN_DEPLOY_TYPE,
55
+ "google-cloudrun-job": exports.GCLOUD_RUN_JOB_DEPLOY_TYPE
18
56
  };
@@ -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";
@@ -1,5 +1,19 @@
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
+
3
17
  var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
4
18
  if (k2 === undefined) k2 = k;
5
19
  Object.defineProperty(o, k2, {
@@ -38,9 +52,8 @@ __exportStar(require("./cloudSql"), exports);
38
52
 
39
53
  __exportStar(require("./cloudRun"), exports);
40
54
 
41
- exports.DEPLOY_TYPES = {
55
+ exports.DEPLOY_TYPES = __assign({
42
56
  kubernetes: kubernetes_1.KUBERNETES_DEPLOY_TYPE,
43
57
  custom: custom_1.CUSTOM_DEPLOY_TYPE,
44
- "google-cloudrun": cloudRun_1.GCLOUD_RUN_DEPLOY_TYPE,
45
58
  dockerTag: dockerTag_1.DOCKER_TAG_DEPLOY_TYPE
46
- };
59
+ }, cloudRun_1.GCLOUD_RUN_DEPLOY_TYPES);
@@ -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,20 +1,39 @@
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 DeployConfigCloudRun = {
4
- /**
5
- * EXPERIMENTAL cloud run deployment.
6
- *
7
- * Requires that cloud run is enabled on the project, as well as cloud run api and artifacts registry.
8
- */
9
- type: "google-cloudrun";
3
+ export declare type DeployConfigCloudRunBase = {
10
4
  /**
11
5
  * the google cloud porject id
12
6
  */
13
-
14
7
  projectId: string;
15
8
  /**
16
9
  * the region. Set to europe-west6 for switzerland
17
10
  */
18
11
 
19
12
  region: Gcloudregion;
20
- } & DeployConfigBase;
13
+ /**
14
+ * command / entrypoint, fallsback to buildConfig.startcommand
15
+ */
16
+
17
+ command?: string;
18
+ } & DeployConfigBase;
19
+ export declare type DeployConfigCloudRunService = {
20
+ /**
21
+ * EXPERIMENTAL cloud run deployment.
22
+ *
23
+ * This will deploy a cloud run service.
24
+ *
25
+ * Requires that cloud run is enabled on the project, as well as cloud run api and artifacts registry.
26
+ */
27
+ type: "google-cloudrun";
28
+ } & DeployConfigCloudRunBase;
29
+ export declare type DeployConfigCloudRunJob = {
30
+ /**
31
+ * EXPERIMENTAL cloud run job.
32
+ *
33
+ * This will deploy a cloud run job. This does not do much currently, but will be later used for cronjobs
34
+ *
35
+ * Requires that cloud run is enabled on the project, as well as cloud run api and artifacts registry.
36
+ */
37
+ type: "google-cloudrun-job";
38
+ } & DeployConfigCloudRunBase;
39
+ export declare type DeployConfigCloudRun = DeployConfigCloudRunService | DeployConfigCloudRunJob;
@@ -11,11 +11,13 @@ export declare type DeployConfigType = DeployConfig["type"];
11
11
  export declare type DeployConfigGeneric<T extends DeployConfigType> = Extract<DeployConfig, {
12
12
  type: T;
13
13
  }>;
14
- export declare const isOfDeployType: <T extends ("custom" | "dockerTag" | "google-cloudrun" | "kubernetes")[]>(t: DeployConfig | false, ...types: T) => t is Extract<DeployConfigCustom, {
14
+ export declare const isOfDeployType: <T extends ("custom" | "dockerTag" | "google-cloudrun" | "google-cloudrun-job" | "kubernetes")[]>(t: DeployConfig | false, ...types: T) => t is Extract<DeployConfigCustom, {
15
15
  type: T[number];
16
16
  }> | Extract<DeployConfigDockerTag, {
17
17
  type: T[number];
18
- }> | Extract<DeployConfigCloudRun, {
18
+ }> | Extract<import("./googleCloudRun").DeployConfigCloudRunService, {
19
+ type: T[number];
20
+ }> | Extract<import("./googleCloudRun").DeployConfigCloudRunJob, {
19
21
  type: T[number];
20
22
  }> | Extract<DeployConfigKubernetes, {
21
23
  type: T[number];