@catladder/pipeline 1.146.2 → 1.148.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 (94) hide show
  1. package/dist/build/base/createAppBuildJob.js +6 -6
  2. package/dist/build/base/writeBuildInfo.js +1 -1
  3. package/dist/build/base/writeDotEnv.js +1 -1
  4. package/dist/build/custom/__tests__/testJob.test.js +11 -14
  5. package/dist/build/custom/buildJob.js +5 -5
  6. package/dist/build/custom/testJob.js +5 -5
  7. package/dist/build/docker.d.ts +26 -9
  8. package/dist/build/docker.js +41 -20
  9. package/dist/build/node/buildJob.js +8 -8
  10. package/dist/build/node/cache.js +1 -1
  11. package/dist/build/node/meteor.js +6 -6
  12. package/dist/build/node/testJob.js +11 -11
  13. package/dist/build/rails/build.js +3 -3
  14. package/dist/build/rails/test.js +4 -4
  15. package/dist/build/sbom.js +2 -2
  16. package/dist/build/types.d.ts +34 -26
  17. package/dist/bundles/catladder-gitlab/index.js +2 -2
  18. package/dist/constants.js +1 -1
  19. package/dist/context/getLabels.js +1 -1
  20. package/dist/context/index.js +34 -12
  21. package/dist/deploy/base/deploy.js +9 -8
  22. package/dist/deploy/cloudRun/artifactsRegistry.d.ts +1 -5
  23. package/dist/deploy/cloudRun/artifactsRegistry.js +8 -9
  24. package/dist/deploy/cloudRun/cloudRunRevisions.js +4 -5
  25. package/dist/deploy/cloudRun/createJobs/cloudRunServices.js +1 -1
  26. package/dist/deploy/cloudRun/createJobs/common.d.ts +4 -4
  27. package/dist/deploy/cloudRun/createJobs/common.js +2 -1
  28. package/dist/deploy/cloudRun/createJobs/index.js +2 -4
  29. package/dist/deploy/custom/deployJob.js +7 -10
  30. package/dist/deploy/dockerTag/deployJob.js +3 -5
  31. package/dist/deploy/kubernetes/cloudSql/index.js +11 -9
  32. package/dist/deploy/kubernetes/deployJob.js +4 -7
  33. package/dist/deploy/kubernetes/kubeEnv.js +2 -1
  34. package/dist/deploy/kubernetes/kubeValues.js +10 -10
  35. package/dist/deploy/kubernetes/mongodb.js +11 -11
  36. package/dist/deploy/sbom.js +1 -1
  37. package/dist/deploy/types/index.d.ts +1 -1
  38. package/dist/deploy/types/index.js +1 -1
  39. package/dist/deploy/utils.js +2 -1
  40. package/dist/pipeline/createJobsForComponent.js +5 -5
  41. package/dist/pipeline/generatePipelineFiles.js +40 -9
  42. package/dist/pipeline/gitlab/createGitlabJobs.js +2 -9
  43. package/dist/pipeline/gitlab/sortGitLabJobDefProps.d.ts +7 -0
  44. package/dist/pipeline/gitlab/sortGitLabJobDefProps.js +27 -0
  45. package/dist/tsconfig.tsbuildinfo +1 -1
  46. package/dist/types/config.d.ts +1 -1
  47. package/dist/types/context.d.ts +13 -1
  48. package/dist/utils/removeUndefined.d.ts +1 -0
  49. package/dist/utils/removeUndefined.js +36 -0
  50. package/examples/__snapshots__/cloud-run-storybook.ts.snap +1687 -0
  51. package/examples/__snapshots__/cloud-run-with-ngnix.ts.snap +1971 -0
  52. package/examples/cloud-run-storybook.ts +24 -0
  53. package/examples/cloud-run-with-ngnix.ts +24 -0
  54. package/package.json +1 -1
  55. package/src/build/base/createAppBuildJob.ts +7 -7
  56. package/src/build/base/writeBuildInfo.ts +1 -1
  57. package/src/build/base/writeDotEnv.ts +1 -1
  58. package/src/build/custom/__tests__/testJob.test.ts +5 -8
  59. package/src/build/custom/buildJob.ts +6 -9
  60. package/src/build/custom/testJob.ts +5 -5
  61. package/src/build/docker.ts +68 -24
  62. package/src/build/node/buildJob.ts +12 -12
  63. package/src/build/node/cache.ts +1 -1
  64. package/src/build/node/meteor.ts +11 -17
  65. package/src/build/node/testJob.ts +14 -14
  66. package/src/build/rails/build.ts +3 -3
  67. package/src/build/rails/test.ts +4 -4
  68. package/src/build/sbom.ts +3 -3
  69. package/src/build/types.ts +53 -38
  70. package/src/context/getLabels.ts +1 -1
  71. package/src/context/index.ts +21 -5
  72. package/src/deploy/base/deploy.ts +8 -14
  73. package/src/deploy/cloudRun/artifactsRegistry.ts +5 -10
  74. package/src/deploy/cloudRun/cloudRunRevisions.ts +3 -5
  75. package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +1 -1
  76. package/src/deploy/cloudRun/createJobs/common.ts +5 -5
  77. package/src/deploy/cloudRun/createJobs/index.ts +1 -4
  78. package/src/deploy/custom/deployJob.ts +4 -6
  79. package/src/deploy/dockerTag/deployJob.ts +2 -5
  80. package/src/deploy/kubernetes/cloudSql/index.ts +7 -4
  81. package/src/deploy/kubernetes/deployJob.ts +1 -4
  82. package/src/deploy/kubernetes/kubeEnv.ts +1 -1
  83. package/src/deploy/kubernetes/kubeValues.ts +3 -3
  84. package/src/deploy/kubernetes/mongodb.ts +6 -6
  85. package/src/deploy/sbom.ts +1 -2
  86. package/src/deploy/types/index.ts +2 -2
  87. package/src/deploy/utils.ts +1 -1
  88. package/src/pipeline/createJobsForComponent.ts +6 -10
  89. package/src/pipeline/generatePipelineFiles.ts +21 -8
  90. package/src/pipeline/gitlab/createGitlabJobs.ts +2 -7
  91. package/src/pipeline/gitlab/sortGitLabJobDefProps.ts +59 -0
  92. package/src/types/config.ts +3 -1
  93. package/src/types/context.ts +16 -1
  94. package/src/utils/removeUndefined.ts +4 -0
package/dist/constants.js CHANGED
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DOCKER_REGISTRY = exports.PIPELINE_IMAGE_TAG = void 0;
7
- exports.PIPELINE_IMAGE_TAG = "v1-146-2-0f533fec" || "latest";
7
+ exports.PIPELINE_IMAGE_TAG = "v1-148-0-262813d5" || "latest";
8
8
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "git.panter.ch:5001/catladder/catladder";
@@ -34,7 +34,7 @@ var getLabels = function (context) {
34
34
  "app-name": sanitize(context.fullConfig.appName),
35
35
  "env-type": sanitize(context.environment.envType),
36
36
  "env-name": sanitize(context.environment.shortName),
37
- "build-type": sanitize((_a = context.componentConfig.build) === null || _a === void 0 ? void 0 : _a.type)
37
+ "build-type": sanitize((_a = context.build.config) === null || _a === void 0 ? void 0 : _a.type)
38
38
  }, (_c = (_b = context.fullConfig.meta) === null || _b === void 0 ? void 0 : _b.labels) !== null && _c !== void 0 ? _c : {});
39
39
  return labels;
40
40
  };
@@ -1,5 +1,15 @@
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
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
3
13
  var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
4
14
  if (k2 === undefined) k2 = k;
5
15
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -138,6 +148,7 @@ Object.defineProperty(exports, "__esModule", {
138
148
  value: true
139
149
  });
140
150
  exports.createContext = exports.createComponentContext = void 0;
151
+ var lodash_1 = require("lodash");
141
152
  var build_1 = require("../build");
142
153
  var deploy_1 = require("../deploy");
143
154
  var utils_1 = require("../utils");
@@ -147,10 +158,9 @@ __exportStar(require("./getEnvironment"), exports);
147
158
  __exportStar(require("./getEnvironmentVariables"), exports);
148
159
  var createComponentContext = function (ctx) {
149
160
  return __awaiter(void 0, void 0, void 0, function () {
150
- var envContext, componentConfigWithoutDefaults, defaults, componentConfig;
151
- var _a;
152
- return __generator(this, function (_b) {
153
- switch (_b.label) {
161
+ var envContext, componentConfigWithoutDefaults, defaults, componentConfig, environment, deploy, build, customJobs, dir, context, resolvedCustomJobs;
162
+ return __generator(this, function (_a) {
163
+ switch (_a.label) {
154
164
  case 0:
155
165
  if (!/^[a-z0-9-]+$/.test(ctx.componentName)) {
156
166
  throw new Error("componentName may only contain lower case letters, numbers and -");
@@ -165,19 +175,31 @@ var createComponentContext = function (ctx) {
165
175
  deploy: {}
166
176
  };
167
177
  componentConfig = (0, utils_1.mergeWithMergingArrays)(defaults, componentConfigWithoutDefaults);
168
- _a = {
178
+ return [4 /*yield*/, (0, getEnvironment_1.getEnvironment)(ctx)];
179
+ case 1:
180
+ environment = _a.sent();
181
+ deploy = componentConfig.deploy, build = componentConfig.build, customJobs = componentConfig.customJobs, dir = componentConfig.dir;
182
+ context = {
169
183
  fullConfig: ctx.config,
170
184
  componentConfig: componentConfig,
171
- buildContext: {
172
- dir: componentConfig.dir,
185
+ build: {
186
+ dir: dir,
173
187
  packageManagerInfo: ctx.packageManagerInfo,
174
- config: componentConfig.build
188
+ config: build
175
189
  },
176
- componentName: ctx.componentName
190
+ deploy: deploy ? {
191
+ config: deploy
192
+ } : null,
193
+ componentName: ctx.componentName,
194
+ environment: environment,
195
+ packageManagerInfo: ctx.packageManagerInfo,
196
+ pipelineType: ctx.pipelineType,
197
+ trigger: ctx.trigger
177
198
  };
178
- return [4 /*yield*/, (0, getEnvironment_1.getEnvironment)(ctx)];
179
- case 1:
180
- return [2 /*return*/, (_a.environment = _b.sent(), _a.packageManagerInfo = ctx.packageManagerInfo, _a.pipelineType = ctx.pipelineType, _a.trigger = ctx.trigger, _a)];
199
+ resolvedCustomJobs = (0, lodash_1.isFunction)(customJobs) ? customJobs(context) : customJobs;
200
+ return [2 /*return*/, __assign(__assign({}, context), {
201
+ customJobs: resolvedCustomJobs
202
+ })];
181
203
  }
182
204
  });
183
205
  });
@@ -53,15 +53,16 @@ var stop_1 = require("./stop");
53
53
  var variables_1 = require("./variables");
54
54
  exports.DEPLOY_JOB_NAME = "🚀 Deploy";
55
55
  var createDeployJob = function (context, jobDefinition) {
56
- var _a, _b, _c, _d, _e, _f;
56
+ var _a, _b, _c, _d, _e, _f, _g;
57
57
  var hasDocker = (0, docker_1.requiresDockerBuild)(context);
58
58
  var isStoppable = (0, utils_1.contextIsStoppable)(context);
59
59
  var autoStop = context.environment.envType === "review" ? "1 week" : context.environment.envType === "dev" ? "4 weeks" : undefined;
60
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
60
61
  // if auto or manual is configured explicitly, use that
61
- var whenDeployDefined = context.componentConfig.deploy && context.componentConfig.deploy.when ? context.componentConfig.deploy.when : undefined;
62
+ var whenDeployDefined = deployConfig && deployConfig.when ? deployConfig.when : undefined;
62
63
  // otherwise auto deploy if env is not prod. If its prod, deploy automatically if stage is disabled
63
64
  var whenDeployDefault = context.environment.envType !== "prod" ? "auto" // is not stage, auto deploy
64
- : ((_a = context.componentConfig.env) === null || _a === void 0 ? void 0 : _a.stage) === false ? "auto" // is prod, but no staging, auto deploy
65
+ : ((_b = context.componentConfig.env) === null || _b === void 0 ? void 0 : _b.stage) === false ? "auto" // is prod, but no staging, auto deploy
65
66
  : "manual"; // manually deploy
66
67
  var whenDeploy = whenDeployDefined ? whenDeployDefined : whenDeployDefault;
67
68
  return {
@@ -76,13 +77,13 @@ var createDeployJob = function (context, jobDefinition) {
76
77
  needs: __spreadArray(__spreadArray([], __read((0, sbom_2.sbomDeactivated)(context) ? [] : [{
77
78
  job: sbom_1.SBOM_BUILD_JOB_NAME,
78
79
  artifacts: true
79
- }]), false), __read(context.componentConfig.deploy ? (_c = (_b = context.componentConfig.deploy.waitFor) === null || _b === void 0 ? void 0 : _b.map(function (c) {
80
+ }]), false), __read(deployConfig ? (_d = (_c = deployConfig.waitFor) === null || _c === void 0 ? void 0 : _c.map(function (c) {
80
81
  return {
81
82
  componentName: c,
82
83
  job: exports.DEPLOY_JOB_NAME,
83
84
  artifacts: false
84
85
  };
85
- })) !== null && _c !== void 0 ? _c : [] : []), false),
86
+ })) !== null && _d !== void 0 ? _d : [] : []), false),
86
87
  // we don't want to deploy when there is a broken test
87
88
  needsStages: [{
88
89
  stage: "build",
@@ -95,13 +96,13 @@ var createDeployJob = function (context, jobDefinition) {
95
96
  when: whenDeploy === "auto" ? "on_success" : "manual",
96
97
  allow_failure: whenDeploy === "manual" ? true : false,
97
98
  stage: "deploy",
98
- variables: __assign(__assign(__assign(__assign(__assign({}, context.environment.envVars), hasDocker ? (0, docker_1.getDockerImageVariables)(context) : {}), context.environment.jobOnlyVars.deploy.envVars), context.componentConfig.deploy ? (_d = context.componentConfig.deploy.extraVars) !== null && _d !== void 0 ? _d : {} : {}), jobDefinition.variables),
99
- runnerVariables: __assign(__assign(__assign({}, variables_1.DEPLOY_RUNNER_VARIABLES), (_e = jobDefinition.runnerVariables) !== null && _e !== void 0 ? _e : {}), context.componentConfig.deploy ? (_f = context.componentConfig.deploy.runnerVariables) !== null && _f !== void 0 ? _f : {} : {}),
99
+ variables: __assign(__assign(__assign(__assign(__assign({}, context.environment.envVars), hasDocker ? (0, docker_1.getDockerImageVariables)(context) : {}), context.environment.jobOnlyVars.deploy.envVars), deployConfig ? (_e = deployConfig.extraVars) !== null && _e !== void 0 ? _e : {} : {}), jobDefinition.variables),
100
+ runnerVariables: __assign(__assign(__assign({}, variables_1.DEPLOY_RUNNER_VARIABLES), (_f = jobDefinition.runnerVariables) !== null && _f !== void 0 ? _f : {}), deployConfig ? (_g = deployConfig.runnerVariables) !== null && _g !== void 0 ? _g : {} : {}),
100
101
  environment: isStoppable ? {
101
102
  on_stop: stop_1.STOP_JOB_NAME,
102
103
  auto_stop_in: autoStop
103
104
  } : undefined,
104
- jobTags: context.componentConfig.deploy ? context.componentConfig.deploy.jobTags : undefined
105
+ jobTags: deployConfig ? deployConfig.jobTags : undefined
105
106
  };
106
107
  };
107
108
  exports.createDeployJob = createDeployJob;
@@ -1,10 +1,6 @@
1
1
  import type { StringOrBashExpression } from "../../bash/BashExpression";
2
2
  import type { ComponentContext } from "../../types/context";
3
- export declare const getArtifactsRegistryHost: ({
4
- componentConfig: {
5
- deploy
6
- }
7
- }: ComponentContext) => string;
3
+ export declare const getArtifactsRegistryHost: (context: ComponentContext) => string;
8
4
  export declare const getArtifactsRegistryDockerUrl: (context: ComponentContext) => string;
9
5
  /**
10
6
  *
@@ -39,17 +39,18 @@ var BashExpression_1 = require("../../bash/BashExpression");
39
39
  var gitlab_1 = require("../../utils/gitlab");
40
40
  var types_1 = require("../types");
41
41
  var removeFirstLinesFromCommandOutput_1 = require("./utils/removeFirstLinesFromCommandOutput");
42
- var getArtifactsRegistryHost = function (_a) {
43
- var deploy = _a.componentConfig.deploy;
44
- if (!(0, types_1.isOfDeployType)(deploy, "google-cloudrun")) {
42
+ var getArtifactsRegistryHost = function (context) {
43
+ var _a;
44
+ if (!(0, types_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "google-cloudrun")) {
45
45
  // should not happen
46
46
  throw new Error("deploy config is wrong");
47
47
  }
48
- return "".concat(deploy.region, "-docker.pkg.dev");
48
+ return "".concat(context.deploy.config.region, "-docker.pkg.dev");
49
49
  };
50
50
  exports.getArtifactsRegistryHost = getArtifactsRegistryHost;
51
51
  var getArtifactsRegistryDockerUrl = function (context) {
52
- var deployConfig = context.componentConfig.deploy;
52
+ var _a;
53
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
53
54
  if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
54
55
  // should not happen
55
56
  throw new Error("deploy config is wrong");
@@ -108,13 +109,11 @@ var getDeleteImageCommands = function (fullImageName, keepNewest) {
108
109
  * @returns
109
110
  */
110
111
  var getDeleteUnusedImagesCommands = function (context, keep) {
112
+ var _a;
111
113
  if (keep === void 0) {
112
114
  keep = 0;
113
115
  }
114
- var deployConfig = context.componentConfig.deploy;
115
- if (deployConfig === false) {
116
- return [];
117
- }
116
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
118
117
  if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
119
118
  // should not happen
120
119
  throw new Error("deploy config is wrong");
@@ -19,8 +19,9 @@ var createArgsString_1 = require("./utils/createArgsString");
19
19
  var getServiceName_1 = require("./utils/getServiceName");
20
20
  var removeFirstLinesFromCommandOutput_1 = require("./utils/removeFirstLinesFromCommandOutput");
21
21
  var getListRevisionsCommand = function (context, args) {
22
+ var _a;
22
23
  var serviceName = (0, getServiceName_1.getServiceName)(context);
23
- var deployConfig = context.componentConfig.deploy;
24
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
24
25
  if (!deployConfig || !(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
25
26
  // should not happen
26
27
  throw new Error("deploy config is wrong");
@@ -37,10 +38,8 @@ var getListRevisionsCommand = function (context, args) {
37
38
  return "gcloud run revisions list ".concat((0, createArgsString_1.createArgsString)(filterRevisionArgs));
38
39
  };
39
40
  var getDeleteUnusedRevisionsCommands = function (context, keep) {
40
- var deployConfig = context.componentConfig.deploy;
41
- if (deployConfig === false) {
42
- return [];
43
- }
41
+ var _a;
42
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
44
43
  if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
45
44
  // should not happen
46
45
  throw new Error("deploy config is wrong");
@@ -56,7 +56,7 @@ var getServiceDeployScript = function (context, service, nameSuffix) {
56
56
  var commonDeployArgs = (0, common_1.getCommonDeployArgs)(context);
57
57
  var serviceName = (0, getServiceName_1.getServiceName)(context);
58
58
  var customConfig = service !== true ? service : undefined;
59
- var command = service !== true ? (_a = service === null || service === void 0 ? void 0 : service.command) !== null && _a !== void 0 ? _a : context.componentConfig.build.startCommand : undefined;
59
+ var command = service !== true ? (_a = service === null || service === void 0 ? void 0 : service.command) !== null && _a !== void 0 ? _a : context.build.config.startCommand : undefined;
60
60
  var commandArray = command ? Array.isArray(command) ? command : command.split(" ") : undefined;
61
61
  var fullServiceName = serviceName.concat(nameSuffix !== null && nameSuffix !== void 0 ? nameSuffix : "");
62
62
  var argsString = createArgsString_1.createArgsString.apply(void 0, __spreadArray([__assign(__assign({
@@ -1,16 +1,16 @@
1
- import type { ComponentContext } from "../../../types/context";
1
+ import type { Context } from "../../../types/context";
2
2
  import type { DeployConfigCloudRun } from "../../types/googleCloudRun";
3
3
  export declare const gcloudCmd: (version?: "beta") => string;
4
4
  export declare const gcloudRunCmd: (version?: "beta") => string;
5
5
  export declare const gcloudSchedulerCmd: (version?: "beta") => string;
6
6
  export declare const setGoogleProjectNumberScript: (deployConfig: DeployConfigCloudRun) => string[];
7
7
  export declare const makeLabelString: (obj: Record<string, unknown>) => string;
8
- export declare const getCloudRunDeployConfig: (context: ComponentContext) => DeployConfigCloudRun;
9
- export declare function getCommonCloudRunArgs(context: ComponentContext): {
8
+ export declare const getCloudRunDeployConfig: (context: Context) => DeployConfigCloudRun;
9
+ export declare function getCommonCloudRunArgs(context: Context): {
10
10
  project: string;
11
11
  region: import("../../types").Gcloudregion;
12
12
  };
13
- export declare function getCommonDeployArgs(context: ComponentContext): {
13
+ export declare function getCommonDeployArgs(context: Context): {
14
14
  "set-cloudsql-instances": string | undefined;
15
15
  project: string;
16
16
  region: import("../../types").Gcloudregion;
@@ -64,7 +64,8 @@ var makeLabelString = function (obj) {
64
64
  };
65
65
  exports.makeLabelString = makeLabelString;
66
66
  var getCloudRunDeployConfig = function (context) {
67
- var deployConfig = context.componentConfig.deploy;
67
+ var _a;
68
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
68
69
  if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
69
70
  // should not happen
70
71
  throw new Error("deploy config is wrong");
@@ -22,10 +22,8 @@ var constants_1 = require("./constants");
22
22
  var getCloudRunDeployScripts_1 = require("./getCloudRunDeployScripts");
23
23
  var getCloudRunStopScripts_1 = require("./getCloudRunStopScripts");
24
24
  var createGoogleCloudRunDeployJobs = function (context) {
25
- var deployConfig = context.componentConfig.deploy;
26
- if (deployConfig === false) {
27
- return [];
28
- }
25
+ var _a;
26
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
29
27
  if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
30
28
  // should not happen
31
29
  throw new Error("deploy config is wrong");
@@ -41,28 +41,25 @@ var base_1 = require("../base");
41
41
  var sbom_1 = require("../sbom");
42
42
  var types_1 = require("../types");
43
43
  var createCustomDeployJobs = function (context) {
44
- var _a, _b, _c;
45
- var deployConfig = context.componentConfig.deploy;
46
- if (deployConfig === false) {
47
- return [];
48
- }
44
+ var _a, _b, _c, _d;
45
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
49
46
  if (!(0, types_1.isOfDeployType)(deployConfig, "custom")) {
50
47
  // should not happen
51
48
  throw new Error("deploy config is not custom");
52
49
  }
53
50
  // FIXME: custom deploy currently assumes yarn-based project
54
- var yarnInstall = (0, yarn_1.getYarnInstall)(context.buildContext, {
51
+ var yarnInstall = (0, yarn_1.getYarnInstall)(context.build, {
55
52
  noCustomPostInstall: true
56
53
  });
57
54
  return (0, base_1.createDeployementJobs)(context, {
58
55
  deploy: {
59
- image: (_a = deployConfig.jobImage) !== null && _a !== void 0 ? _a : (0, runner_1.getRunnerImage)("jobs-default"),
60
- cache: (_b = deployConfig.jobCache) !== null && _b !== void 0 ? _b : [],
61
- script: __spreadArray(__spreadArray(__spreadArray(["cd ".concat(context.componentConfig.dir)], __read(deployConfig.requiresYarnInstall ? yarnInstall : []), false), __read(deployConfig.script), false), __read((0, sbom_1.getDependencyTrackUploadScript)(context)), false),
56
+ image: (_b = deployConfig.jobImage) !== null && _b !== void 0 ? _b : (0, runner_1.getRunnerImage)("jobs-default"),
57
+ cache: (_c = deployConfig.jobCache) !== null && _c !== void 0 ? _c : [],
58
+ script: __spreadArray(__spreadArray(__spreadArray(["cd ".concat(context.build.dir)], __read(deployConfig.requiresYarnInstall ? yarnInstall : []), false), __read(deployConfig.script), false), __read((0, sbom_1.getDependencyTrackUploadScript)(context)), false),
62
59
  variables: {}
63
60
  },
64
61
  stop: deployConfig.stopScript ? {
65
- image: (_c = deployConfig.jobImage) !== null && _c !== void 0 ? _c : (0, runner_1.getRunnerImage)("jobs-default"),
62
+ image: (_d = deployConfig.jobImage) !== null && _d !== void 0 ? _d : (0, runner_1.getRunnerImage)("jobs-default"),
66
63
  script: __spreadArray(__spreadArray([], __read(deployConfig.stopScript), false), __read((0, sbom_1.getDependencyTrackDeleteScript)(context)), false),
67
64
  variables: {}
68
65
  } : undefined
@@ -49,17 +49,15 @@ var docker_1 = require("../../build/docker");
49
49
  var base_1 = require("../base");
50
50
  var types_1 = require("../types");
51
51
  var createDockerTagDeployJobs = function (context) {
52
- var deployConfig = context.componentConfig.deploy;
53
- if (deployConfig === false) {
54
- return [];
55
- }
52
+ var _a;
53
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
56
54
  if (!(0, types_1.isOfDeployType)(deployConfig, "dockerTag")) {
57
55
  // should not happen
58
56
  throw new Error("deploy config is not dockerTag");
59
57
  }
60
58
  var tag = deployConfig.tag;
61
59
  return (0, base_1.createDeployementJobs)(context, {
62
- deploy: __assign(__assign({}, (0, docker_1.getDockerJobBaseProps)(context)), {
60
+ deploy: __assign(__assign({}, (0, docker_1.getDockerJobBaseProps)()), {
63
61
  script: __spreadArray(__spreadArray([], __read((0, docker_1.gitlabDockerLogin)(context)), false), ["docker pull $DOCKER_IMAGE:$DOCKER_IMAGE_TAG", "docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG $DOCKER_IMAGE:".concat(tag), "docker push $DOCKER_IMAGE:".concat(tag), "echo \"pushed as $DOCKER_IMAGE:".concat(tag, "\"")], false)
64
62
  })
65
63
  });
@@ -8,39 +8,41 @@ var context_1 = require("../../../context");
8
8
  var utils_1 = require("../../cloudSql/utils");
9
9
  var types_1 = require("../../types");
10
10
  var hasKubernetesCloudSQL = function (context) {
11
- var _a, _b;
12
- if ((0, types_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
13
- return (_b = (_a = context.componentConfig.deploy.values) === null || _a === void 0 ? void 0 : _a.cloudsql) === null || _b === void 0 ? void 0 : _b.enabled;
11
+ var _a, _b, _c;
12
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
13
+ if ((0, types_1.isOfDeployType)(deployConfig, "kubernetes")) {
14
+ return (_c = (_b = deployConfig.values) === null || _b === void 0 ? void 0 : _b.cloudsql) === null || _c === void 0 ? void 0 : _c.enabled;
14
15
  }
15
16
  return false;
16
17
  };
17
18
  exports.hasKubernetesCloudSQL = hasKubernetesCloudSQL;
18
19
  var createKubernetesCloudsqlBaseValues = function (context) {
19
- var _a, _b, _c, _d, _e, _f;
20
- if (!(0, types_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
20
+ var _a, _b, _c, _d, _e, _f, _g;
21
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
22
+ if (!(0, types_1.isOfDeployType)(deployConfig, "kubernetes")) {
21
23
  throw new Error("cannot get cloud sql config");
22
24
  }
23
- var config = (_a = context.componentConfig.deploy.values) === null || _a === void 0 ? void 0 : _a.cloudsql;
25
+ var config = (_b = deployConfig.values) === null || _b === void 0 ? void 0 : _b.cloudsql;
24
26
  if (!config) {
25
27
  throw new Error("cannot get cloud sql config");
26
28
  }
27
29
  var proxyCredentials = "$".concat((0, context_1.getSecretVarNameForContext)(context, "cloudsqlProxyCredentials"));
28
30
  if ((config === null || config === void 0 ? void 0 : config.type) !== "unmanaged") {
29
- var instanceConnectionName = "".concat((_b = config.projectId) !== null && _b !== void 0 ? _b : "skynet-164509", ":").concat((_c = config.region) !== null && _c !== void 0 ? _c : "europe-west6", ":").concat((_d = config.instanceId) !== null && _d !== void 0 ? _d : context.environment.envVars.KUBE_NAMESPACE);
31
+ var instanceConnectionName = "".concat((_c = config.projectId) !== null && _c !== void 0 ? _c : "skynet-164509", ":").concat((_d = config.region) !== null && _d !== void 0 ? _d : "europe-west6", ":").concat((_e = config.instanceId) !== null && _e !== void 0 ? _e : context.environment.envVars.KUBE_NAMESPACE);
30
32
  return {
31
33
  cloudsql: {
32
34
  enabled: config.enabled,
33
35
  dbUser: "postgres",
34
36
  instanceConnectionName: instanceConnectionName,
35
37
  proxyCredentials: proxyCredentials,
36
- fullDbName: (_e = context.environment.envVars.KUBE_APP_NAME) !== null && _e !== void 0 ? _e : ""
38
+ fullDbName: (_f = context.environment.envVars.KUBE_APP_NAME) !== null && _f !== void 0 ? _f : ""
37
39
  }
38
40
  };
39
41
  } else if (config.type === "unmanaged") {
40
42
  return {
41
43
  cloudsql: {
42
44
  enabled: config.enabled,
43
- dbUser: (_f = config.dbUser) !== null && _f !== void 0 ? _f : "postgres",
45
+ dbUser: (_g = config.dbUser) !== null && _g !== void 0 ? _g : "postgres",
44
46
  instanceConnectionName: config.instanceConnectionName,
45
47
  proxyCredentials: proxyCredentials,
46
48
  fullDbName: (0, utils_1.getFullDbName)(config, context.fullConfig, context.environment.slugPrefix, context.componentName)
@@ -55,11 +55,8 @@ var bashYaml_1 = require("../../bash/bashYaml");
55
55
  var gitlab_1 = require("../../utils/gitlab");
56
56
  var ALL_VALUES_FILE = "__all_values.yml";
57
57
  var createKubernetesDeployJobs = function (context) {
58
- var _a, _b;
59
- var deployConfig = context.componentConfig.deploy;
60
- if (deployConfig === false) {
61
- return [];
62
- }
58
+ var _a, _b, _c;
59
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
63
60
  if (!(0, types_1.isOfDeployType)(deployConfig, "kubernetes")) {
64
61
  // should not happen
65
62
  throw new Error("deploy config is not kubernetes");
@@ -78,8 +75,8 @@ var createKubernetesDeployJobs = function (context) {
78
75
  RELEASE_NAME: context.environment.fullName,
79
76
  HELM_EXPERIMENTAL_OCI: "1",
80
77
  KUBE_DOCKER_IMAGE_PULL_SECRET: "gitlab-registry-".concat(context.componentName),
81
- HELM_GITLAB_CHART_NAME: (_a = deployConfig.chartName) !== null && _a !== void 0 ? _a : "/helm-charts/the-panter-chart",
82
- HELM_ARGS: __spreadArray(__spreadArray([], __read(deployConfig.debug ? ["--debug"] : []), false), __read((_b = deployConfig.additionalHelmArgs) !== null && _b !== void 0 ? _b : []), false).join(" "),
78
+ HELM_GITLAB_CHART_NAME: (_b = deployConfig.chartName) !== null && _b !== void 0 ? _b : "/helm-charts/the-panter-chart",
79
+ HELM_ARGS: __spreadArray(__spreadArray([], __read(deployConfig.debug ? ["--debug"] : []), false), __read((_c = deployConfig.additionalHelmArgs) !== null && _c !== void 0 ? _c : []), false).join(" "),
83
80
  COMPONENT_NAME: context.componentName,
84
81
  /** @deprecated */
85
82
  BUILD_ID: context.environment.envVars.BUILD_INFO_BUILD_ID
@@ -50,7 +50,8 @@ var shouldGoIntoSecrets = function (key, value) {
50
50
  * we evalulate the actual values later, but want to store the secrets in kubernetes secrets
51
51
  */
52
52
  var createKubeEnv = function (context) {
53
- if (!(0, types_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
53
+ var _a;
54
+ if (!(0, types_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "kubernetes")) {
54
55
  // should not happen
55
56
  throw new Error("deploy config is not kubernetes");
56
57
  }
@@ -63,7 +63,7 @@ var createAppConfig = function (context, application) {
63
63
  rest = __rest(_a, ["healthRoute", "command"]);
64
64
  return (0, utils_1.mergeWithMergingArrays)({
65
65
  host: context.environment.host,
66
- command: command !== null && command !== void 0 ? command : context.componentConfig.build.startCommand,
66
+ command: command !== null && command !== void 0 ? command : context.build.config.startCommand,
67
67
  livenessProbe: {
68
68
  httpGet: {
69
69
  path: healthRoute !== null && healthRoute !== void 0 ? healthRoute : "__health"
@@ -92,9 +92,9 @@ var removeFalsy = function (record) {
92
92
  }));
93
93
  };
94
94
  var createKubeValues = function (context) {
95
- var _a, _b;
96
- var deployConfig = context.componentConfig.deploy;
97
- if (deployConfig === false) {
95
+ var _a, _b, _c;
96
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
97
+ if (!deployConfig) {
98
98
  return [];
99
99
  }
100
100
  if (!(0, types_1.isOfDeployType)(deployConfig, "kubernetes")) {
@@ -104,16 +104,16 @@ var createKubeValues = function (context) {
104
104
  var values = deployConfig.values;
105
105
  // we remove the application config because it can be just the value `false` which is a convenience feature, but not supported in the helm chart
106
106
  // we only merge the rest of the values in
107
- var _c = values !== null && values !== void 0 ? values : {},
108
- application = _c.application,
109
- jobs = _c.jobs,
110
- cronjobs = _c.cronjobs,
111
- rest = __rest(_c, ["application", "jobs", "cronjobs"]);
107
+ var _d = values !== null && values !== void 0 ? values : {},
108
+ application = _d.application,
109
+ jobs = _d.jobs,
110
+ cronjobs = _d.cronjobs,
111
+ rest = __rest(_d, ["application", "jobs", "cronjobs"]);
112
112
  var env = (0, kubeEnv_1.createKubeEnv)(context);
113
113
  var defaultKubeValues = (0, lodash_1.merge)({
114
114
  env: env,
115
115
  application: createAppConfig(context, application)
116
- }, (0, cloudSql_1.hasKubernetesCloudSQL)(context) ? (0, cloudSql_1.createKubernetesCloudsqlBaseValues)(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) : {});
116
+ }, (0, cloudSql_1.hasKubernetesCloudSQL)(context) ? (0, cloudSql_1.createKubernetesCloudsqlBaseValues)(context) : {}, ((_c = (_b = deployConfig.values) === null || _b === void 0 ? void 0 : _b.mongodb) === null || _c === void 0 ? void 0 : _c.enabled) ? (0, mongodb_1.createMongodbBaseConfig)(context) : {});
117
117
  var kubeValues = (0, processSecretsAsFiles_1.processSecretsAsFiles)((0, utils_1.mergeWithMergingArrays)(defaultKubeValues, __assign({
118
118
  jobs: removeFalsy(jobs),
119
119
  cronjobs: removeFalsy(cronjobs)
@@ -33,15 +33,15 @@ var getMongodbReplicasetHost = function (context, index) {
33
33
  return getMongodbHost(context, "".concat(fullAppname, "-mongodb-").concat(index, ".").concat(fullAppname, "-mongodb-headless"));
34
34
  };
35
35
  var createMongodbUrl = function (context, dbName) {
36
- var _a, _b;
37
- if (!(0, types_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
36
+ var _a, _b, _c, _d;
37
+ if (!(0, types_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "kubernetes")) {
38
38
  throw new Error("can only createMongodbUrl on supported deploys");
39
39
  }
40
- var mongodbConfig = (_a = context.componentConfig.deploy.values) === null || _a === void 0 ? void 0 : _a.mongodb;
40
+ var mongodbConfig = (_c = (_b = context.deploy) === null || _b === void 0 ? void 0 : _b.config.values) === null || _c === void 0 ? void 0 : _c.mongodb;
41
41
  var queryParams = undefined;
42
42
  var hosts = "";
43
43
  if ((mongodbConfig === null || mongodbConfig === void 0 ? void 0 : mongodbConfig.architecture) === "replicaset") {
44
- hosts = (0, lodash_1.range)(0, (_b = mongodbConfig === null || mongodbConfig === void 0 ? void 0 : mongodbConfig.replicaCount) !== null && _b !== void 0 ? _b : 2).map(function (i) {
44
+ hosts = (0, lodash_1.range)(0, (_d = mongodbConfig === null || mongodbConfig === void 0 ? void 0 : mongodbConfig.replicaCount) !== null && _d !== void 0 ? _d : 2).map(function (i) {
45
45
  return getMongodbReplicasetHost(context, i);
46
46
  }).join(",");
47
47
  queryParams = "replicaSet=rs0&authSource=admin";
@@ -52,11 +52,11 @@ var createMongodbUrl = function (context, dbName) {
52
52
  return "mongodb://".concat(getCredentialString(context)).concat(hosts, "/").concat(dbName).concat(queryParams ? "?".concat(queryParams) : "");
53
53
  };
54
54
  var createMongoBackupDefaultConfig = function (context) {
55
- var _a;
56
- if (!(0, types_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
55
+ var _a, _b, _c;
56
+ if (!(0, types_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "kubernetes")) {
57
57
  throw new Error("can only create mongodb base config on supported deploys");
58
58
  }
59
- var mongodbConfig = (_a = context.componentConfig.deploy.values) === null || _a === void 0 ? void 0 : _a.mongodb;
59
+ var mongodbConfig = (_c = (_b = context.deploy) === null || _b === void 0 ? void 0 : _b.config.values) === null || _c === void 0 ? void 0 : _c.mongodb;
60
60
  var fullAppName = context.environment.envVars.KUBE_APP_NAME;
61
61
  var backupEnabled = ["prod", "stage"].includes(context.environment.envType);
62
62
  var hostToBackup;
@@ -81,11 +81,11 @@ var createMongoBackupDefaultConfig = function (context) {
81
81
  };
82
82
  };
83
83
  var createMongodbBaseConfig = function (context) {
84
- var _a, _b;
85
- if (!(0, types_1.isOfDeployType)(context.componentConfig.deploy, "kubernetes")) {
84
+ var _a, _b, _c, _d;
85
+ if (!(0, types_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "kubernetes")) {
86
86
  throw new Error("can only create mongodb base config on supported deploys");
87
87
  }
88
- var mongodbConfig = (_a = context.componentConfig.deploy.values) === null || _a === void 0 ? void 0 : _a.mongodb;
88
+ var mongodbConfig = (_c = (_b = context.deploy) === null || _b === void 0 ? void 0 : _b.config.values) === null || _c === void 0 ? void 0 : _c.mongodb;
89
89
  return {
90
90
  mongodb: {
91
91
  enabled: true,
@@ -101,7 +101,7 @@ var createMongodbBaseConfig = function (context) {
101
101
  },
102
102
  env: {
103
103
  secret: __assign({
104
- MONGO_URL: createMongodbUrl(context, (_b = mongodbConfig === null || mongodbConfig === void 0 ? void 0 : mongodbConfig.dbName) !== null && _b !== void 0 ? _b : "app")
104
+ MONGO_URL: createMongodbUrl(context, (_d = mongodbConfig === null || mongodbConfig === void 0 ? void 0 : mongodbConfig.dbName) !== null && _d !== void 0 ? _d : "app")
105
105
  }, (mongodbConfig === null || mongodbConfig === void 0 ? void 0 : mongodbConfig.architecture) === "replicaset" ? {
106
106
  MONGO_OPLOG_URL: createMongodbUrl(context, "local")
107
107
  } // oplog only works with replicasets
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getDependencyTrackDeleteScript = exports.getDependencyTrackUploadScript = exports.sbomDeactivated = void 0;
7
7
  var sbom_1 = require("../build/sbom");
8
8
  var sbomDeactivated = function (context) {
9
- return context.componentConfig.build.type === "custom" && context.componentConfig.build.sbom === false;
9
+ return context.build.config.type === "custom" && context.build.config.sbom === false;
10
10
  };
11
11
  exports.sbomDeactivated = sbomDeactivated;
12
12
  var getDependencyTrackUploadScript = function (context) {
@@ -11,7 +11,7 @@ export type DeployConfigType = DeployConfig["type"];
11
11
  export type DeployConfigGeneric<T extends DeployConfigType> = Extract<DeployConfig, {
12
12
  type: T;
13
13
  }>;
14
- export declare const isOfDeployType: <T extends ("kubernetes" | "custom" | "google-cloudrun" | "dockerTag")[]>(t: DeployConfig | false, ...types: T) => t is Extract<DeployConfigKubernetes, {
14
+ export declare const isOfDeployType: <T extends ("kubernetes" | "custom" | "google-cloudrun" | "dockerTag")[]>(t: DeployConfig | false | null | undefined, ...types: T) => t is Extract<DeployConfigKubernetes, {
15
15
  type: T[number];
16
16
  }> | Extract<DeployConfigCustom, {
17
17
  type: T[number];
@@ -32,6 +32,6 @@ var isOfDeployType = function (t) {
32
32
  for (var _i = 1; _i < arguments.length; _i++) {
33
33
  types[_i - 1] = arguments[_i];
34
34
  }
35
- return t && types.includes(t.type);
35
+ return t && types.includes(t.type) ? true : false;
36
36
  };
37
37
  exports.isOfDeployType = isOfDeployType;
@@ -16,7 +16,8 @@ var getKubernetesNamespace = function (config, env) {
16
16
  };
17
17
  exports.getKubernetesNamespace = getKubernetesNamespace;
18
18
  var contextIsStoppable = function (context) {
19
- var deployConfig = context.componentConfig.deploy;
19
+ var _a;
20
+ var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
20
21
  if ((0, types_1.isOfDeployType)(deployConfig, "kubernetes")) {
21
22
  return true;
22
23
  }
@@ -168,7 +168,6 @@ Object.defineProperty(exports, "__esModule", {
168
168
  value: true
169
169
  });
170
170
  exports.createJobsForComponent = void 0;
171
- var lodash_1 = require("lodash");
172
171
  var build_1 = require("../build");
173
172
  var context_1 = require("../context");
174
173
  var deploy_1 = require("../deploy");
@@ -184,15 +183,16 @@ var injectDefaultVarsInCustomJobs = function (context, jobs) {
184
183
  });
185
184
  };
186
185
  var getCustomJobs = function (context) {
187
- if (!context.componentConfig.customJobs) {
186
+ if (!context.customJobs) {
188
187
  return [];
189
188
  }
190
- var rawJobs = (0, lodash_1.isFunction)(context.componentConfig.customJobs) ? context.componentConfig.customJobs(context) : context.componentConfig.customJobs;
189
+ var rawJobs = context.customJobs;
191
190
  return injectDefaultVarsInCustomJobs(context, rawJobs);
192
191
  };
193
192
  var createRawJobs = function (context) {
194
- var buildJobs = build_1.BUILD_TYPES[context.componentConfig.build.type].jobs(context);
195
- var deployJobs = context.componentConfig.deploy !== false ? deploy_1.DEPLOY_TYPES[context.componentConfig.deploy.type].jobs(context) : [];
193
+ var _a, _b;
194
+ var buildJobs = build_1.BUILD_TYPES[context.build.config.type].jobs(context);
195
+ var deployJobs = ((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config) ? deploy_1.DEPLOY_TYPES[(_b = context.deploy) === null || _b === void 0 ? void 0 : _b.config.type].jobs(context) : [];
196
196
  var customJobs = getCustomJobs(context);
197
197
  return __spreadArray(__spreadArray(__spreadArray([], __read(buildJobs), false), __read(deployJobs), false), __read(customJobs), false);
198
198
  };