@catladder/pipeline 1.55.0 → 1.56.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.
Files changed (56) hide show
  1. package/bin/catladder-gitlab-dev.js +3 -0
  2. package/dist/build/index.d.ts +2 -1
  3. package/dist/build/node/cache.js +8 -1
  4. package/dist/build/node/yarn.js +1 -1
  5. package/dist/build/types.d.ts +3 -0
  6. package/dist/bundles/catladder-gitlab/index.js +3 -3
  7. package/dist/constants.js +1 -1
  8. package/dist/context/getEnvConfig.d.ts +2 -0
  9. package/dist/context/getEnvConfig.js +26 -0
  10. package/dist/context/getEnvType.d.ts +4 -0
  11. package/dist/context/getEnvType.js +18 -0
  12. package/dist/context/getEnvironment.d.ts +2 -4
  13. package/dist/context/getEnvironment.js +15 -195
  14. package/dist/context/getEnvironmentContext.d.ts +4 -0
  15. package/dist/context/getEnvironmentContext.js +36 -0
  16. package/dist/context/getEnvironmentVariables.d.ts +10 -0
  17. package/dist/context/getEnvironmentVariables.js +322 -0
  18. package/dist/context/index.d.ts +1 -0
  19. package/dist/context/index.js +12 -16
  20. package/dist/deploy/cloudRun/deployJob.js +19 -5
  21. package/dist/deploy/cloudRun/index.js +7 -7
  22. package/dist/deploy/index.d.ts +7 -20
  23. package/dist/deploy/index.js +4 -4
  24. package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +3 -3
  25. package/dist/deploy/kubernetes/additionalSecretKeys.js +5 -5
  26. package/dist/deploy/kubernetes/index.js +2 -2
  27. package/dist/deploy/types/googleCloudRun.d.ts +1 -1
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/dist/types/config.d.ts +1 -0
  30. package/dist/types/context.d.ts +6 -0
  31. package/dist/types/environmentContext.d.ts +22 -0
  32. package/dist/types/environmentContext.js +3 -0
  33. package/dist/utils/gitlab.d.ts +1 -0
  34. package/dist/utils/gitlab.js +46 -0
  35. package/examples/test.catladder.ts +26 -0
  36. package/package.json +1 -1
  37. package/src/build/index.ts +4 -1
  38. package/src/build/node/cache.ts +13 -5
  39. package/src/build/node/yarn.ts +1 -1
  40. package/src/build/types.ts +6 -0
  41. package/src/context/getEnvConfig.ts +21 -0
  42. package/src/context/getEnvType.ts +17 -0
  43. package/src/context/getEnvironment.ts +16 -164
  44. package/src/context/getEnvironmentContext.ts +57 -0
  45. package/src/context/getEnvironmentVariables.ts +152 -0
  46. package/src/context/index.ts +17 -14
  47. package/src/deploy/cloudRun/deployJob.ts +9 -5
  48. package/src/deploy/cloudRun/index.ts +5 -4
  49. package/src/deploy/index.ts +9 -21
  50. package/src/deploy/kubernetes/additionalSecretKeys.ts +7 -7
  51. package/src/deploy/kubernetes/index.ts +2 -2
  52. package/src/deploy/types/googleCloudRun.ts +1 -1
  53. package/src/types/config.ts +2 -0
  54. package/src/types/context.ts +8 -0
  55. package/src/types/environmentContext.ts +26 -0
  56. package/src/utils/gitlab.ts +5 -0
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-55-0-40141b86" || "";
5
+ exports.PIPELINE_IMAGE_TAG = "v1-56-0-4063dbc1" || "";
6
6
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "";
@@ -0,0 +1,2 @@
1
+ import type { Config, EnvConfigWithComponent } from "../types/config";
2
+ export declare const getEnvConfig: (config: Config, componentName: string, env: string) => EnvConfigWithComponent;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.getEnvConfig = void 0;
5
+
6
+ var utils_1 = require("../utils");
7
+
8
+ var getEnvConfig = function (config, componentName, env) {
9
+ var _a, _b;
10
+
11
+ var defaultConfig = config.components[componentName];
12
+
13
+ if (!defaultConfig) {
14
+ throw new Error("unknown component " + componentName);
15
+ }
16
+
17
+ var envCustomizations = (_b = (_a = defaultConfig.env) === null || _a === void 0 ? void 0 : _a[env]) !== null && _b !== void 0 ? _b : {};
18
+
19
+ if (envCustomizations === false) {
20
+ throw new Error("env is disabled: " + env);
21
+ }
22
+
23
+ return (0, utils_1.mergeWithMergingArrays)(defaultConfig, envCustomizations);
24
+ };
25
+
26
+ exports.getEnvConfig = getEnvConfig;
@@ -0,0 +1,4 @@
1
+ import type { EnvType } from "../types";
2
+ export declare const getEnvType: (env: string, envConfig: {
3
+ type?: EnvType;
4
+ }) => EnvType;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.getEnvType = void 0;
5
+
6
+ var types_1 = require("../types");
7
+
8
+ var getEnvType = function (env, envConfig) {
9
+ if (envConfig.type) return envConfig.type;
10
+
11
+ if ((0, types_1.isKnowEnvType)(env)) {
12
+ return env;
13
+ }
14
+
15
+ throw new Error("unknown env type: " + env);
16
+ };
17
+
18
+ exports.getEnvType = getEnvType;
@@ -1,5 +1,3 @@
1
1
  import type { Config } from "../types/config";
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>;
4
- export declare const getSecretVarName: (env: string, componentName: string, key: string) => string;
5
- export declare const getSecretVarNameForContext: (context: Context, key: string) => string;
2
+ import type { CommitInfo, Environment } from "../types/context";
3
+ export declare const getEnvironment: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined) => Promise<Environment>;
@@ -1,19 +1,5 @@
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
3
  var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
18
4
  function adopt(value) {
19
5
  return value instanceof P ? value : new P(function (resolve) {
@@ -155,153 +141,28 @@ var __generator = this && this.__generator || function (thisArg, body) {
155
141
  }
156
142
  };
157
143
 
158
- var __read = this && this.__read || function (o, n) {
159
- var m = typeof Symbol === "function" && o[Symbol.iterator];
160
- if (!m) return o;
161
- var i = m.call(o),
162
- r,
163
- ar = [],
164
- e;
165
-
166
- try {
167
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
168
- } catch (error) {
169
- e = {
170
- error: error
171
- };
172
- } finally {
173
- try {
174
- if (r && !r.done && (m = i["return"])) m.call(i);
175
- } finally {
176
- if (e) throw e.error;
177
- }
178
- }
179
-
180
- return ar;
181
- };
182
-
183
- var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
184
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
185
- if (ar || !(i in from)) {
186
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
187
- ar[i] = from[i];
188
- }
189
- }
190
- return to.concat(ar || Array.prototype.slice.call(from));
191
- };
192
-
193
144
  exports.__esModule = true;
194
- exports.getSecretVarNameForContext = exports.getSecretVarName = exports.getEnvironment = void 0;
195
-
196
- var lodash_1 = require("lodash");
197
-
198
- var deploy_1 = require("../deploy");
199
-
200
- var config_1 = require("../types/config");
145
+ exports.getEnvironment = void 0;
201
146
 
202
- var utils_1 = require("../utils");
147
+ var getEnvironmentContext_1 = require("./getEnvironmentContext");
203
148
 
204
- var resolveReferences_1 = require("./resolveReferences");
205
-
206
- var getEnvironment = function (config, componentName, env, commitInfo, alreadyVisited // to prevent endless loop
207
- ) {
208
- if (alreadyVisited === void 0) {
209
- alreadyVisited = {};
210
- }
149
+ var getEnvironmentVariables_1 = require("./getEnvironmentVariables");
211
150
 
151
+ var getEnvironment = function (config, componentName, env, commitInfo) {
212
152
  return __awaiter(void 0, void 0, void 0, function () {
213
- var envConfig, envType, basePredefinedVariables, gitlabEnvironmentName, environmentSlug, predefinedVariables, host, url, fullName, envVarContext, devLocalConfig, port, additionalEnvVars, publicEnvVarsRaw, additionalSecretKeys, secretEnvVarKeys, secretEnvVars, legacyFromComponents, publicEnvVarsRawWithLegasyFromComponents, publicEnvVarsRawSanitized, envVarsRaw, envVars;
214
-
215
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
153
+ var _a, envVars, secretEnvVarKeys, host, url, envContext, envType;
216
154
 
217
- return __generator(this, function (_l) {
218
- switch (_l.label) {
155
+ return __generator(this, function (_b) {
156
+ switch (_b.label) {
219
157
  case 0:
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;
222
-
223
- if (!envType) {
224
- throw new Error("Missing type in environment " + env + " in component " + componentName);
225
- }
226
-
227
- basePredefinedVariables = {
228
- ENV_SHORT: env,
229
- APP_DIR: envConfig.dir,
230
- ENV_TYPE: envType
231
- };
232
- gitlabEnvironmentName = envType === "review" && commitInfo ? "".concat(env, "/").concat(commitInfo.refName, "/").concat(componentName) : "".concat(env, "/").concat(componentName);
233
- environmentSlug = envType === "review" && commitInfo ? "".concat(env, "-").concat(commitInfo.reviewSlug, "-").concat(componentName) : "".concat(env, "-").concat(componentName);
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
- };
244
-
245
- if (envType === "local") {
246
- devLocalConfig = envConfig;
247
- port = (_b = devLocalConfig.port) !== null && _b !== void 0 ? _b : 3000;
248
- host = "localhost:" + port;
249
- url = "http://" + host;
250
- predefinedVariables = {
251
- ENV_SHORT: "local",
252
- ROOT_URL: url,
253
- PORT: port.toString()
254
- };
255
- } else {
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";
258
- url = "https://".concat(host);
259
- predefinedVariables = __assign(__assign(__assign({}, basePredefinedVariables), {
260
- HOST: host,
261
- ROOT_URL: url
262
- }), additionalEnvVars);
263
- }
264
-
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);
268
- secretEnvVars = Object.fromEntries(secretEnvVarKeys.map(function (key) {
269
- return [key, "$".concat((0, exports.getSecretVarName)(env, componentName, key))];
270
- }));
271
- legacyFromComponents = (_k = (_j = envConfig.vars) === null || _j === void 0 ? void 0 : _j.fromComponents) !== null && _k !== void 0 ? _k : {};
272
- publicEnvVarsRawWithLegasyFromComponents = (0, lodash_1.merge)({}, (0, resolveReferences_1.translateLegacyFromComponents)(legacyFromComponents), publicEnvVarsRaw);
273
- publicEnvVarsRawSanitized = Object.fromEntries(Object.entries(publicEnvVarsRawWithLegasyFromComponents).map(function (_a) {
274
- var _b = __read(_a, 2),
275
- key = _b[0],
276
- value = _b[1];
277
-
278
- return [key, (0, lodash_1.isObject)(value) ? JSON.stringify(value) : "".concat(value)];
279
- }));
280
- envVarsRaw = addIndexVar(__assign(__assign(__assign({}, predefinedVariables), secretEnvVars), publicEnvVarsRawSanitized));
281
158
  return [4
282
159
  /*yield*/
283
- , (0, resolveReferences_1.resolveReferences)(envVarsRaw, function (componentName, variableName, alreadyVisited) {
284
- return __awaiter(void 0, void 0, void 0, function () {
285
- var envVars;
286
- return __generator(this, function (_a) {
287
- switch (_a.label) {
288
- case 0:
289
- return [4
290
- /*yield*/
291
- , (0, exports.getEnvironment)(config, componentName, env, commitInfo, alreadyVisited)];
292
-
293
- case 1:
294
- envVars = _a.sent().envVars;
295
- return [2
296
- /*return*/
297
- , envVars[variableName]];
298
- }
299
- });
300
- });
301
- }, alreadyVisited)];
160
+ , (0, getEnvironmentVariables_1.getEnvironmentVariables)(config, componentName, env, commitInfo)];
302
161
 
303
162
  case 1:
304
- envVars = _l.sent();
163
+ _a = _b.sent(), envVars = _a.envVars, secretEnvVarKeys = _a.secretEnvVarKeys, host = _a.host, url = _a.url;
164
+ envContext = (0, getEnvironmentContext_1.getEnvironmentContext)(config, env, componentName, commitInfo);
165
+ envType = envContext.envType;
305
166
  return [2
306
167
  /*return*/
307
168
  , {
@@ -309,11 +170,11 @@ var getEnvironment = function (config, componentName, env, commitInfo, alreadyVi
309
170
  host: host,
310
171
  url: url,
311
172
  gitlabEnvironment: {
312
- name: gitlabEnvironmentName,
173
+ name: envContext.gitlabEnvironmentName,
313
174
  url: url
314
175
  },
315
- fullName: fullName,
316
- slug: environmentSlug,
176
+ fullName: envContext.fullName,
177
+ slug: envContext.environmentSlug,
317
178
  shortName: env,
318
179
  envVars: envVars,
319
180
  secretEnvVarKeys: secretEnvVarKeys
@@ -323,45 +184,4 @@ var getEnvironment = function (config, componentName, env, commitInfo, alreadyVi
323
184
  });
324
185
  };
325
186
 
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
- };
187
+ exports.getEnvironment = getEnvironment;
@@ -0,0 +1,4 @@
1
+ import type { Config } from "../types/config";
2
+ import type { CommitInfo } from "../types/context";
3
+ import type { EnvironmentContext } from "../types/environmentContext";
4
+ export declare const getEnvironmentContext: (config: Config, env: string, componentName: string, commitInfo?: CommitInfo | undefined) => EnvironmentContext<any, any>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.getEnvironmentContext = void 0;
5
+
6
+ var getEnvConfig_1 = require("./getEnvConfig");
7
+
8
+ var getEnvType_1 = require("./getEnvType");
9
+
10
+ var getEnvironmentSlug = function (envConfig, env, componentName, commitInfo) {
11
+ var envType = (0, getEnvType_1.getEnvType)(env, envConfig);
12
+ return envType === "review" && commitInfo ? "".concat(env, "-").concat(commitInfo.reviewSlug, "-").concat(componentName) : "".concat(env, "-").concat(componentName);
13
+ };
14
+
15
+ var getEnvironmentContext = function (config, env, componentName, commitInfo) {
16
+ var envConfigRaw = (0, getEnvConfig_1.getEnvConfig)(config, componentName, env);
17
+ var envType = (0, getEnvType_1.getEnvType)(env, envConfigRaw);
18
+ var environmentSlug = getEnvironmentSlug(envConfigRaw, env, componentName, commitInfo);
19
+ var gitlabEnvironmentName = envType === "review" && commitInfo ? "".concat(env, "/").concat(commitInfo.refName, "/").concat(componentName) : "".concat(env, "/").concat(componentName);
20
+ var fullName = "".concat(config.customerName, "-").concat(config.appName, "-").concat(environmentSlug);
21
+ return {
22
+ envConfigRaw: envConfigRaw,
23
+ deployConfigRaw: envConfigRaw.deploy,
24
+ buildConfigRaw: envConfigRaw.build,
25
+ environmentSlug: environmentSlug,
26
+ gitlabEnvironmentName: gitlabEnvironmentName,
27
+ fullName: fullName,
28
+ envType: envType,
29
+ commitInfo: commitInfo,
30
+ componentName: componentName,
31
+ env: env,
32
+ fullConfig: config
33
+ };
34
+ };
35
+
36
+ exports.getEnvironmentContext = getEnvironmentContext;
@@ -0,0 +1,10 @@
1
+ import type { CommitInfo, Context } from "../types";
2
+ import type { Config } from "../types/config";
3
+ export declare const getEnvironmentVariables: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined, alreadyVisited?: Record<string, Record<string, boolean>>) => Promise<{
4
+ envVars: Record<string, string>;
5
+ secretEnvVarKeys: string[];
6
+ host: string;
7
+ url: string;
8
+ }>;
9
+ export declare const getSecretVarName: (env: string, componentName: string, key: string) => string;
10
+ export declare const getSecretVarNameForContext: (context: Context, key: string) => string;