@catladder/pipeline 0.0.0-tagged-release-2fffd3dd → 0.0.0-waitfor-deploy-e64a33ba

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 (120) hide show
  1. package/dist/build/base/constants.js +2 -2
  2. package/dist/build/base/createBuildJob.d.ts +4 -2
  3. package/dist/build/base/createBuildJob.js +18 -17
  4. package/dist/build/base/getBuildInfo.d.ts +2 -0
  5. package/dist/build/base/getBuildInfo.js +12 -0
  6. package/dist/build/docker.d.ts +29 -4
  7. package/dist/build/docker.js +74 -23
  8. package/dist/build/index.d.ts +2 -2
  9. package/dist/build/index.js +1 -1
  10. package/dist/build/node/buildJob.d.ts +2 -2
  11. package/dist/build/node/buildJob.js +27 -11
  12. package/dist/build/node/cache.d.ts +3 -1
  13. package/dist/build/node/cache.js +34 -6
  14. package/dist/build/node/constants.js +2 -2
  15. package/dist/build/node/index.d.ts +4 -4
  16. package/dist/build/node/meteor.d.ts +2 -2
  17. package/dist/build/node/meteor.js +7 -23
  18. package/dist/build/node/testJob.d.ts +2 -2
  19. package/dist/build/node/testJob.js +22 -30
  20. package/dist/build/node/yarn.d.ts +5 -0
  21. package/dist/build/node/yarn.js +51 -3
  22. package/dist/build/tests/storybook.test.js +17 -24
  23. package/dist/build/types.d.ts +13 -0
  24. package/dist/catladder-gitlab.js +42 -9
  25. package/dist/config/configruedEnvs.test.js +12 -3
  26. package/dist/config/readConfig.d.ts +5 -1
  27. package/dist/config/readConfig.js +20 -5
  28. package/dist/constants.js +1 -1
  29. package/dist/context/index.d.ts +4 -3
  30. package/dist/context/index.js +56 -43
  31. package/dist/context/resolveReferences.d.ts +6 -0
  32. package/dist/context/resolveReferences.js +93 -0
  33. package/dist/context/resolveReferences.test.d.ts +1 -0
  34. package/dist/context/resolveReferences.test.js +141 -0
  35. package/dist/deploy/base.d.ts +3 -4
  36. package/dist/deploy/base.js +55 -35
  37. package/dist/deploy/custom/deployJob.d.ts +3 -0
  38. package/dist/deploy/custom/deployJob.js +65 -0
  39. package/dist/deploy/custom/index.d.ts +1 -0
  40. package/dist/deploy/custom/index.js +22 -0
  41. package/dist/deploy/index.d.ts +5 -3
  42. package/dist/deploy/index.js +12 -0
  43. package/dist/deploy/kubernetes/cloudsql.js +1 -1
  44. package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
  45. package/dist/deploy/kubernetes/deployJob.js +74 -42
  46. package/dist/deploy/kubernetes/mongodb.js +1 -1
  47. package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +87 -0
  48. package/dist/deploy/kubernetes/processSecretsAsFiles.js +39 -0
  49. package/dist/deploy/types.d.ts +194 -84
  50. package/dist/deploy/utils.d.ts +5 -0
  51. package/dist/deploy/utils.js +36 -0
  52. package/dist/pipeline/createChildPipeline.d.ts +2 -8
  53. package/dist/pipeline/createChildPipeline.js +24 -15
  54. package/dist/pipeline/createChildPipeline.test.js +10 -15
  55. package/dist/pipeline/createJobs.d.ts +2 -2
  56. package/dist/pipeline/createJobs.js +95 -33
  57. package/dist/pipeline/gitlab/makeGitlabJob.d.ts +8 -0
  58. package/dist/pipeline/gitlab/makeGitlabJob.js +45 -0
  59. package/dist/pipeline/packageManager.d.ts +2 -0
  60. package/dist/pipeline/{yarnInfo.js → packageManager.js} +69 -8
  61. package/dist/runner/index.d.ts +1 -1
  62. package/dist/tsconfig.tsbuildinfo +1 -1
  63. package/dist/types/config.d.ts +87 -1
  64. package/dist/types/context.d.ts +19 -8
  65. package/dist/types/gitlab-types.d.ts +10 -22
  66. package/dist/types/gitlab-types.js +1 -3
  67. package/dist/types/index.d.ts +2 -1
  68. package/dist/types/index.js +3 -1
  69. package/dist/types/jobs.d.ts +80 -0
  70. package/dist/types/jobs.js +5 -0
  71. package/dist/types/pipeline.d.ts +4 -0
  72. package/dist/types/pipeline.js +3 -0
  73. package/dist/utils/index.d.ts +2 -1
  74. package/dist/utils/index.js +45 -2
  75. package/package.json +1 -3
  76. package/src/build/base/constants.ts +2 -2
  77. package/src/build/base/createBuildJob.ts +31 -34
  78. package/src/build/base/getBuildInfo.ts +7 -0
  79. package/src/build/docker.ts +75 -35
  80. package/src/build/index.ts +4 -3
  81. package/src/build/node/buildJob.ts +46 -24
  82. package/src/build/node/cache.ts +31 -6
  83. package/src/build/node/constants.ts +2 -2
  84. package/src/build/node/index.ts +4 -4
  85. package/src/build/node/meteor.ts +12 -18
  86. package/src/build/node/testJob.ts +35 -40
  87. package/src/build/node/yarn.ts +25 -4
  88. package/src/build/tests/storybook.test.ts +10 -2
  89. package/src/build/types.ts +12 -0
  90. package/src/catladder-gitlab.ts +12 -7
  91. package/src/config/configruedEnvs.test.ts +10 -3
  92. package/src/config/readConfig.ts +18 -6
  93. package/src/context/index.ts +90 -52
  94. package/src/context/resolveReferences.test.ts +158 -0
  95. package/src/context/resolveReferences.ts +66 -0
  96. package/src/deploy/base.ts +73 -47
  97. package/src/deploy/custom/deployJob.ts +23 -0
  98. package/src/deploy/custom/index.ts +1 -0
  99. package/src/deploy/index.ts +10 -4
  100. package/src/deploy/kubernetes/cloudsql.ts +3 -4
  101. package/src/deploy/kubernetes/deployJob.ts +85 -45
  102. package/src/deploy/kubernetes/mongodb.ts +1 -3
  103. package/src/deploy/kubernetes/processSecretsAsFiles.ts +34 -0
  104. package/src/deploy/types.ts +177 -42
  105. package/src/deploy/utils.ts +30 -0
  106. package/src/pipeline/createChildPipeline.test.ts +8 -1
  107. package/src/pipeline/createChildPipeline.ts +23 -18
  108. package/src/pipeline/createJobs.ts +104 -56
  109. package/src/pipeline/gitlab/makeGitlabJob.ts +16 -0
  110. package/src/pipeline/packageManager.ts +99 -0
  111. package/src/runner/index.ts +3 -1
  112. package/src/types/config.ts +79 -1
  113. package/src/types/context.ts +18 -5
  114. package/src/types/gitlab-types.ts +10 -30
  115. package/src/types/index.ts +1 -0
  116. package/src/types/jobs.ts +94 -0
  117. package/src/types/pipeline.ts +11 -0
  118. package/src/utils/index.ts +10 -1
  119. package/dist/pipeline/yarnInfo.d.ts +0 -2
  120. package/src/pipeline/yarnInfo.ts +0 -54
@@ -1,12 +1,60 @@
1
1
  "use strict";
2
2
 
3
+ var __read = this && this.__read || function (o, n) {
4
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
5
+ if (!m) return o;
6
+ var i = m.call(o),
7
+ r,
8
+ ar = [],
9
+ e;
10
+
11
+ try {
12
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
13
+ } catch (error) {
14
+ e = {
15
+ error: error
16
+ };
17
+ } finally {
18
+ try {
19
+ if (r && !r.done && (m = i["return"])) m.call(i);
20
+ } finally {
21
+ if (e) throw e.error;
22
+ }
23
+ }
24
+
25
+ return ar;
26
+ };
27
+
28
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
29
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
+ if (ar || !(i in from)) {
31
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
+ ar[i] = from[i];
33
+ }
34
+ }
35
+ return to.concat(ar || Array.prototype.slice.call(from));
36
+ };
37
+
3
38
  exports.__esModule = true;
4
- exports.getYarnInstall = void 0;
39
+ exports.getYarnInstall = exports.ensureNodeVersion = exports.getYarnInstallCommand = void 0;
5
40
 
6
- var getYarnInstall = function (context) {
41
+ var getYarnInstallCommand = function (context, options) {
7
42
  var _a;
8
43
 
9
- return ["if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi", ((_a = context.yarnInfo) === null || _a === void 0 ? void 0 : _a.isClassic) ? "yarn install --frozen-lockfile" : "yarn install --immutable"];
44
+ return ((_a = context.packageManagerInfo) === null || _a === void 0 ? void 0 : _a.isClassic) ? "yarn install --frozen-lockfile ".concat((options === null || options === void 0 ? void 0 : options.prodOnly) ? "--production" : "", " ").concat((options === null || options === void 0 ? void 0 : options.noScripts) ? "--ignore-scripts" : "") : (options === null || options === void 0 ? void 0 : options.prodOnly) ? "".concat((options === null || options === void 0 ? void 0 : options.noScripts) ? "YARN_ENABLE_SCRIPTS=false " : "", "yarn plugin import workspace-tools && yarn workspaces focus --production") // needs yarn plugin import workspace-tools
45
+ : "".concat((options === null || options === void 0 ? void 0 : options.noScripts) ? "YARN_ENABLE_SCRIPTS=false " : "", "yarn install --immutable");
46
+ };
47
+
48
+ exports.getYarnInstallCommand = getYarnInstallCommand;
49
+
50
+ var ensureNodeVersion = function (context) {
51
+ return ["if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi"];
52
+ };
53
+
54
+ exports.ensureNodeVersion = ensureNodeVersion;
55
+
56
+ var getYarnInstall = function (context) {
57
+ return __spreadArray(__spreadArray([], __read((0, exports.ensureNodeVersion)(context)), false), [(0, exports.getYarnInstallCommand)(context)], false);
10
58
  };
11
59
 
12
60
  exports.getYarnInstall = getYarnInstall;
@@ -141,17 +141,6 @@ var __generator = this && this.__generator || function (thisArg, body) {
141
141
  }
142
142
  };
143
143
 
144
- var __rest = this && this.__rest || function (s, e) {
145
- var t = {};
146
-
147
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
148
-
149
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
150
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
151
- }
152
- return t;
153
- };
154
-
155
144
  exports.__esModule = true;
156
145
 
157
146
  var __1 = require("../../");
@@ -168,24 +157,29 @@ describe("storybook build", function () {
168
157
  type: "storybook"
169
158
  },
170
159
  deploy: {
171
- type: "kubernetes"
160
+ type: "kubernetes",
161
+ cluster: {
162
+ name: "production",
163
+ projectId: "bla",
164
+ region: "europe",
165
+ type: "gcloud"
166
+ }
172
167
  }
173
168
  }
174
169
  }
175
170
  };
176
171
  it("creates a pipeline for storybook that does not contain test stages", function () {
177
172
  return __awaiter(void 0, void 0, void 0, function () {
178
- var _a, image, stages, workflow, jobs;
179
-
180
- return __generator(this, function (_b) {
181
- switch (_b.label) {
173
+ var jobs;
174
+ return __generator(this, function (_a) {
175
+ switch (_a.label) {
182
176
  case 0:
183
177
  return [4
184
178
  /*yield*/
185
- , (0, __1.createChildPipeline)("mainBranch", config)];
179
+ , (0, __1.createChildPipeline)("gitlab", "mainBranch", config)];
186
180
 
187
181
  case 1:
188
- _a = _b.sent(), image = _a.image, stages = _a.stages, workflow = _a.workflow, jobs = __rest(_a, ["image", "stages", "workflow"]);
182
+ jobs = _a.sent().jobs;
189
183
  expect(Object.keys(jobs)).toEqual(["dev my-app app-build", "dev my-app docker-build", "dev my-app deploy-to-kubernetes", "dev my-app kubernetes-stop"]);
190
184
  return [2
191
185
  /*return*/
@@ -196,17 +190,16 @@ describe("storybook build", function () {
196
190
  });
197
191
  it("runs build and renames folder", function () {
198
192
  return __awaiter(void 0, void 0, void 0, function () {
199
- var _a, image, stages, workflow, jobs, buildJob;
200
-
201
- return __generator(this, function (_b) {
202
- switch (_b.label) {
193
+ var jobs, buildJob;
194
+ return __generator(this, function (_a) {
195
+ switch (_a.label) {
203
196
  case 0:
204
197
  return [4
205
198
  /*yield*/
206
- , (0, __1.createChildPipeline)("mainBranch", config)];
199
+ , (0, __1.createChildPipeline)("gitlab", "mainBranch", config)];
207
200
 
208
201
  case 1:
209
- _a = _b.sent(), image = _a.image, stages = _a.stages, workflow = _a.workflow, jobs = __rest(_a, ["image", "stages", "workflow"]);
202
+ jobs = _a.sent().jobs;
210
203
  buildJob = jobs["dev my-app app-build"];
211
204
  expect(buildJob.script).toContain("yarn storybook");
212
205
  expect(buildJob.script).toContain("mv ./storybook-out /dist");
@@ -1,5 +1,12 @@
1
1
  export declare type BuildConfigBase = {
2
+ /**
3
+ * command to run on the image to start the app (e.g. yarn start)
4
+ */
2
5
  startCommand?: string;
6
+ /**
7
+ * additional env vars for the buid jobs
8
+ */
9
+
3
10
  extraVars?: Record<string, string>;
4
11
  /**
5
12
  * define the build command
@@ -35,6 +42,12 @@ export declare type BuildConfigBase = {
35
42
  audit?: false | {
36
43
  command?: string | string[];
37
44
  };
45
+ /**
46
+ * additional paths for artifacts,
47
+ * by default "dist" and ".next" are allways included
48
+ */
49
+
50
+ artifactsPaths?: string[];
38
51
  };
39
52
  export declare type BuildConfigNodeBase = BuildConfigBase;
40
53
  export declare type BuildConfigNode = {
@@ -1,21 +1,50 @@
1
1
  "use strict";
2
2
 
3
+ var __assign = this && this.__assign || function () {
4
+ __assign = Object.assign || function (t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+
8
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
9
+ }
10
+
11
+ return t;
12
+ };
13
+
14
+ return __assign.apply(this, arguments);
15
+ };
16
+
17
+ var __rest = this && this.__rest || function (s, e) {
18
+ var t = {};
19
+
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
21
+
22
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
23
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
24
+ }
25
+ return t;
26
+ };
27
+
28
+ var _a;
29
+
3
30
  exports.__esModule = true;
4
31
 
5
32
  var fs_1 = require("fs");
6
33
 
34
+ var js_yaml_1 = require("js-yaml");
35
+
7
36
  var config_1 = require("./config");
8
37
 
9
38
  var constants_1 = require("./constants");
10
39
 
11
40
  var pipeline_1 = require("./pipeline");
12
41
 
13
- var _a = process.env,
14
- CI_MERGE_REQUEST_ID = _a.CI_MERGE_REQUEST_ID,
15
- CI_COMMIT_TAG = _a.CI_COMMIT_TAG,
16
- CI_COMMIT_BRANCH = _a.CI_COMMIT_BRANCH,
17
- CI_DEFAULT_BRANCH = _a.CI_DEFAULT_BRANCH;
18
- var isDefaultBranch = CI_COMMIT_BRANCH == CI_DEFAULT_BRANCH;
42
+ var _b = process.env,
43
+ CI_MERGE_REQUEST_ID = _b.CI_MERGE_REQUEST_ID,
44
+ CI_COMMIT_TAG = _b.CI_COMMIT_TAG,
45
+ CI_COMMIT_BRANCH = _b.CI_COMMIT_BRANCH,
46
+ CI_DEFAULT_BRANCH = _b.CI_DEFAULT_BRANCH;
47
+ var isDefaultBranch = Boolean(CI_DEFAULT_BRANCH) && CI_COMMIT_BRANCH === CI_DEFAULT_BRANCH;
19
48
  var isHotfixBranch = false; // TODO: $CI_COMMIT_BRANCH =~ /^[0-9]+\.([0-9]+|x)\.x$/
20
49
 
21
50
  var isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
@@ -24,14 +53,18 @@ console.info("catladder version ".concat(constants_1.PIPELINE_IMAGE_TAG));
24
53
  var trigger = isMergeRequest || isHotfixBranch ? "mr" : isDefaultBranch ? "mainBranch" : isTaggedRelease ? "taggedRelease" : null;
25
54
 
26
55
  if (trigger) {
27
- var config = (0, config_1.readConfigSync)();
56
+ var config = (_a = (0, config_1.readConfigSync)()) === null || _a === void 0 ? void 0 : _a.config;
28
57
 
29
58
  if (!config) {
30
59
  throw new Error("no catladder config found");
31
60
  }
32
61
 
33
- (0, pipeline_1.createChildPipeline)(trigger, config).then(function (mainPipeline) {
34
- (0, fs_1.writeFileSync)("__pipeline.yml", JSON.stringify(mainPipeline, null, 2), {
62
+ (0, pipeline_1.createChildPipeline)("gitlab", trigger, config).then(function (_a) {
63
+ var jobs = _a.jobs,
64
+ mainPipeline = __rest(_a, ["jobs"]); // need to spread out the jobs
65
+
66
+
67
+ (0, fs_1.writeFileSync)("__pipeline.yml", (0, js_yaml_1.dump)(__assign(__assign({}, jobs), mainPipeline)), {
35
68
  encoding: "utf-8"
36
69
  });
37
70
  });
@@ -5,6 +5,12 @@ exports.__esModule = true;
5
5
  var _1 = require(".");
6
6
 
7
7
  describe("getAllEnvsByTrigger", function () {
8
+ var cluster = {
9
+ type: "gcloud",
10
+ name: "mega-cluster",
11
+ projectId: "super-google-project",
12
+ region: "ch-blabla"
13
+ };
8
14
  var SIMPLE_CONFIG = {
9
15
  appName: "my-app",
10
16
  customerName: "pan",
@@ -15,7 +21,8 @@ describe("getAllEnvsByTrigger", function () {
15
21
  type: "node"
16
22
  },
17
23
  deploy: {
18
- type: "kubernetes"
24
+ type: "kubernetes",
25
+ cluster: cluster
19
26
  }
20
27
  },
21
28
  app2: {
@@ -24,7 +31,8 @@ describe("getAllEnvsByTrigger", function () {
24
31
  type: "node"
25
32
  },
26
33
  deploy: {
27
- type: "kubernetes"
34
+ type: "kubernetes",
35
+ cluster: cluster
28
36
  },
29
37
  env: {
30
38
  dev2: {
@@ -47,7 +55,8 @@ describe("getAllEnvsByTrigger", function () {
47
55
  type: "node"
48
56
  },
49
57
  deploy: {
50
- type: "kubernetes"
58
+ type: "kubernetes",
59
+ cluster: cluster
51
60
  },
52
61
  env: {
53
62
  dev: false,
@@ -1,2 +1,6 @@
1
1
  import { Config } from "../types";
2
- export declare const readConfigSync: (directory?: string) => Config | null;
2
+ export declare const readConfigSync: (directory?: string) => {
3
+ config: Config;
4
+ path: string;
5
+ ext: string;
6
+ } | null;
@@ -14,6 +14,11 @@ var fullPath = function (directory, ext) {
14
14
  return directory + "/catladder." + ext;
15
15
  };
16
16
 
17
+ function requireUncached(module) {
18
+ delete require.cache[require.resolve(module)];
19
+ return require(module);
20
+ }
21
+
17
22
  var readConfigSync = function (directory) {
18
23
  if (directory === void 0) {
19
24
  directory = process.cwd();
@@ -31,13 +36,23 @@ var readConfigSync = function (directory) {
31
36
  });
32
37
 
33
38
  if (found) {
39
+ var filePath = fullPath(directory, found);
40
+
34
41
  if (found === "ts" || found === "js") {
35
- // eslint-disable-next-line @typescript-eslint/no-var-requires
36
- return require(fullPath(directory, found))["default"];
42
+ return {
43
+ path: filePath,
44
+ ext: found,
45
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
46
+ config: requireUncached(filePath)["default"]
47
+ };
37
48
  } else {
38
- return (0, js_yaml_1.load)((0, fs_1.readFileSync)(fullPath(directory, found), {
39
- encoding: "utf-8"
40
- }));
49
+ return {
50
+ path: filePath,
51
+ ext: found,
52
+ config: (0, js_yaml_1.load)((0, fs_1.readFileSync)(filePath, {
53
+ encoding: "utf-8"
54
+ }))
55
+ };
41
56
  }
42
57
  }
43
58
 
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 = "tagged-release-2fffd3dd" || "";
5
+ exports.PIPELINE_IMAGE_TAG = "waitfor-deploy-e64a33ba" || "";
6
6
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "";
@@ -1,5 +1,6 @@
1
1
  import { Config } from "../types/config";
2
- import { CommitInfo, Context, Environment, YarnInfo } from "../types/context";
2
+ import { CommitInfo, Context, Environment } from "../types/context";
3
3
  export declare const getSecretVarName: (env: string, componentName: string, key: string) => string;
4
- export declare const getEnvironment: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined, skipReferences?: boolean) => Environment;
5
- export declare const createContext: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined, yarnInfo?: YarnInfo | undefined) => Context;
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>>) => Environment;
6
+ export declare const createContext: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined, packageManagerInfo?: import("../types/context").YarnPackageManagerInfo | undefined) => Context;
@@ -46,7 +46,7 @@ var __importDefault = this && this.__importDefault || function (mod) {
46
46
  };
47
47
 
48
48
  exports.__esModule = true;
49
- exports.createContext = exports.getEnvironment = exports.getSecretVarName = void 0;
49
+ exports.createContext = exports.getEnvironment = exports.getSecretVarNameForContext = exports.getSecretVarName = void 0;
50
50
 
51
51
  var lodash_1 = require("lodash");
52
52
 
@@ -58,6 +58,10 @@ var deploy_1 = require("../deploy");
58
58
 
59
59
  var config_1 = require("../types/config");
60
60
 
61
+ var utils_1 = require("../utils");
62
+
63
+ var resolveReferences_1 = require("./resolveReferences");
64
+
61
65
  var sanitizeForEnVar = function (s) {
62
66
  return s.replace(/-/g, "_");
63
67
  };
@@ -69,12 +73,18 @@ var getSecretVarName = function (env, componentName, key) {
69
73
 
70
74
  exports.getSecretVarName = getSecretVarName;
71
75
 
72
- var getEnvironment = function (config, componentName, env, commitInfo, skipReferences // to prevent infinit loop
76
+ var getSecretVarNameForContext = function (context, key) {
77
+ return (0, exports.getSecretVarName)(context.environment.shortName, context.componentName, key);
78
+ };
79
+
80
+ exports.getSecretVarNameForContext = getSecretVarNameForContext;
81
+
82
+ var getEnvironment = function (config, componentName, env, commitInfo, alreadyVisited // to prevent endless loop
73
83
  ) {
74
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
84
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
75
85
 
76
- if (skipReferences === void 0) {
77
- skipReferences = false;
86
+ if (alreadyVisited === void 0) {
87
+ alreadyVisited = {};
78
88
  }
79
89
 
80
90
  var componentConfig = config.components[componentName];
@@ -90,42 +100,47 @@ var getEnvironment = function (config, componentName, env, commitInfo, skipRefer
90
100
  throw new Error("env is disabled: " + env);
91
101
  }
92
102
 
93
- var mergedConfig = (0, lodash_1.merge)({}, defaultConfig, envConfig); // env type: if its set manually, use that, otherwise use the known env types
103
+ var mergedConfig = (0, utils_1.mergeWithMergingArrays)(defaultConfig, envConfig); // env type: if its set manually, use that, otherwise use the known env types
94
104
 
95
- var basePredefinedVariables = {
96
- ENV_SHORT: env,
97
- APP_DIR: componentConfig.dir
98
- };
99
105
  var envType = (_c = envConfig === null || envConfig === void 0 ? void 0 : envConfig.type) !== null && _c !== void 0 ? _c : (0, config_1.isKnowEnvType)(env) ? env : null;
100
106
 
101
107
  if (!envType) {
102
108
  throw new Error("Missing type in environment " + env + " in component " + componentName);
103
109
  }
104
110
 
111
+ var basePredefinedVariables = {
112
+ ENV_SHORT: env,
113
+ APP_DIR: componentConfig.dir,
114
+ ENV_TYPE: envType
115
+ };
105
116
  var environmentName = envType === "review" && commitInfo ? "".concat(env, "/").concat(commitInfo.refName, "/").concat(componentName) : "".concat(env, "/").concat(componentName);
106
- var environmentSlug = envType === "review" && commitInfo ? "".concat(env, "-").concat(commitInfo.refSlug, "-").concat(componentName) : "".concat(env, "-").concat(componentName);
117
+ var environmentSlug = envType === "review" && commitInfo ? "".concat(env, "-").concat(commitInfo.reviewSlug, "-").concat(componentName) : "".concat(env, "-").concat(componentName);
107
118
  var predefinedVariables;
108
- var hostname;
119
+ var host;
109
120
  var url;
110
121
 
111
122
  if (envType === "local") {
112
123
  var devLocalConfig = mergedConfig;
113
124
  var port = (_d = devLocalConfig.port) !== null && _d !== void 0 ? _d : 3000;
114
- hostname = "localhost:" + port;
115
- url = "http://" + hostname;
125
+ host = "localhost:" + port;
126
+ url = "http://" + host;
116
127
  predefinedVariables = {
128
+ ENV_SHORT: "local",
117
129
  ROOT_URL: url,
118
130
  PORT: port.toString()
119
131
  };
120
132
  } else {
121
- var KUBE_NAMESPACE = "".concat(config.customerName, "-").concat(config.appName, "-").concat(env);
122
133
  var RELEASE_NAME = "".concat(config.customerName, "-").concat(config.appName, "-").concat(environmentSlug);
123
134
  var componentSlug = (0, slugify_1["default"])(componentName);
124
- var envInUrl = envType === "review" && commitInfo ? "".concat(commitInfo.refSlug, ".").concat(env) : env;
125
- var HOST_CANONICAL = "".concat(config.appName, "-").concat(componentSlug, ".").concat(envInUrl, ".").concat(config.customerName, ".panter.cloud");
126
- hostname = (_e = mergedConfig === null || mergedConfig === void 0 ? void 0 : mergedConfig.hostname) !== null && _e !== void 0 ? _e : HOST_CANONICAL;
127
- var url_1 = "https://".concat(hostname);
128
- var KUBE_APP_NAME = envType === "review" && commitInfo ? "".concat(componentName, "-").concat(commitInfo.refSlug) : componentName;
135
+ var envInUrl = envType === "review" && commitInfo ? "".concat(commitInfo.reviewSlug, ".").concat(env) : env;
136
+ var 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
137
+ config.domainCanonical || "panter.cloud";
138
+ var HOST_CANONICAL = "".concat(componentSlug, ".").concat(envInUrl, ".").concat(config.appName, ".").concat(config.customerName, ".").concat(domainCanonical);
139
+ host = (_f = mergedConfig === null || mergedConfig === void 0 ? void 0 : mergedConfig.host) !== null && _f !== void 0 ? _f : HOST_CANONICAL;
140
+ var url_1 = "https://".concat(host); // FIXME: move to kube specific jobs
141
+
142
+ var KUBE_APP_NAME = envType === "review" && commitInfo ? "".concat(commitInfo.reviewSlug, "-").concat(componentName) : componentName;
143
+ var KUBE_NAMESPACE = (0, deploy_1.getKubernetesNamespace)(config, env);
129
144
  predefinedVariables = __assign(__assign({}, basePredefinedVariables), {
130
145
  HOST_CANONICAL: HOST_CANONICAL,
131
146
  ROOT_URL: url_1,
@@ -135,33 +150,31 @@ var getEnvironment = function (config, componentName, env, commitInfo, skipRefer
135
150
  });
136
151
  }
137
152
 
138
- var publicEnvVars = (_g = (_f = mergedConfig.vars) === null || _f === void 0 ? void 0 : _f.public) !== null && _g !== void 0 ? _g : {};
139
- var secretEnvVarKeys = (_j = (_h = mergedConfig.vars) === null || _h === void 0 ? void 0 : _h.secret) !== null && _j !== void 0 ? _j : [];
153
+ var publicEnvVarsRaw = (_h = (_g = mergedConfig.vars) === null || _g === void 0 ? void 0 : _g.public) !== null && _h !== void 0 ? _h : {};
154
+ var secretEnvVarKeys = (_k = (_j = mergedConfig.vars) === null || _j === void 0 ? void 0 : _j.secret) !== null && _k !== void 0 ? _k : [];
140
155
  var secretEnvVars = Object.fromEntries(secretEnvVarKeys.map(function (key) {
141
156
  return [key, "$".concat((0, exports.getSecretVarName)(env, componentName, key))];
142
- }));
143
- var referencedRaw = (_l = (_k = mergedConfig.vars) === null || _k === void 0 ? void 0 : _k.fromComponents) !== null && _l !== void 0 ? _l : {};
144
- var referenced = skipReferences ? {} : Object.entries(referencedRaw).reduce(function (acc, _a) {
145
- var _b = __read(_a, 2),
146
- otherApp = _b[0],
147
- mapping = _b[1];
157
+ })); // this is deprecated, we now support: $componentname:FOO
148
158
 
149
- var envVars = (0, exports.getEnvironment)(config, otherApp, env, commitInfo, true // prevent infinit loop
150
- ).envVars;
151
- return __assign(__assign({}, acc), Object.fromEntries(Object.entries(mapping).map(function (_a) {
152
- var _b = __read(_a, 2),
153
- ourKey = _b[0],
154
- otherKey = _b[1];
159
+ var legacyFromComponents = (_m = (_l = mergedConfig.vars) === null || _l === void 0 ? void 0 : _l.fromComponents) !== null && _m !== void 0 ? _m : {};
160
+ var publicEnvVarsRawWithLegasyFromComponents = (0, lodash_1.merge)({}, (0, resolveReferences_1.translateLegacyFromComponents)(legacyFromComponents), publicEnvVarsRaw);
161
+ var publicEnvVarsRawSanitized = Object.fromEntries(Object.entries(publicEnvVarsRawWithLegasyFromComponents).map(function (_a) {
162
+ var _b = __read(_a, 2),
163
+ key = _b[0],
164
+ value = _b[1];
155
165
 
156
- return [ourKey, envVars[otherKey]];
157
- })));
158
- }, {});
166
+ return [key, (0, lodash_1.isObject)(value) ? JSON.stringify(value) : "".concat(value)];
167
+ }));
159
168
 
160
- var envVars = __assign(__assign(__assign(__assign({}, predefinedVariables), secretEnvVars), referenced), publicEnvVars);
169
+ var envVarsRaw = __assign(__assign(__assign({}, predefinedVariables), secretEnvVars), publicEnvVarsRawSanitized);
161
170
 
171
+ var envVars = (0, resolveReferences_1.resolveReferences)(envVarsRaw, function (componentName, variableName, alreadyVisited) {
172
+ var envVars = (0, exports.getEnvironment)(config, componentName, env, commitInfo, alreadyVisited).envVars;
173
+ return envVars[variableName];
174
+ }, alreadyVisited);
162
175
  return {
163
176
  envType: envType,
164
- hostname: hostname,
177
+ host: host,
165
178
  fullName: environmentName,
166
179
  slug: environmentSlug,
167
180
  shortName: env,
@@ -173,7 +186,7 @@ var getEnvironment = function (config, componentName, env, commitInfo, skipRefer
173
186
 
174
187
  exports.getEnvironment = getEnvironment;
175
188
 
176
- var createContext = function (config, componentName, env, commitInfo, yarnInfo) {
189
+ var createContext = function (config, componentName, env, commitInfo, packageManagerInfo) {
177
190
  var _a, _b;
178
191
 
179
192
  if (!/^[a-z0-9-]+$/.test(componentName)) {
@@ -188,7 +201,7 @@ var createContext = function (config, componentName, env, commitInfo, yarnInfo)
188
201
 
189
202
 
190
203
  var envConfig = (_b = (_a = rawConfig.env) === null || _a === void 0 ? void 0 : _a[env]) !== null && _b !== void 0 ? _b : {};
191
- var componentConfigWithoutDefaults = (0, lodash_1.merge)({}, rawConfig, envConfig); // fill in defaults of build and deploy
204
+ var componentConfigWithoutDefaults = (0, utils_1.mergeWithMergingArrays)(rawConfig, envConfig); // fill in defaults of build and deploy
192
205
 
193
206
  var defaults = componentConfigWithoutDefaults.deploy ? {
194
207
  build: build_1.BUILD_TYPES[componentConfigWithoutDefaults.build.type].defaults(),
@@ -197,14 +210,14 @@ var createContext = function (config, componentName, env, commitInfo, yarnInfo)
197
210
  build: {},
198
211
  deploy: {}
199
212
  };
200
- var componentConfig = (0, lodash_1.merge)({}, defaults, componentConfigWithoutDefaults);
213
+ var componentConfig = (0, utils_1.mergeWithMergingArrays)(defaults, componentConfigWithoutDefaults);
201
214
  return {
202
215
  fullConfig: config,
203
216
  componentConfig: componentConfig,
204
217
  componentName: componentName,
205
218
  environment: (0, exports.getEnvironment)(config, componentName, env, commitInfo),
206
219
  commitInfo: commitInfo,
207
- yarnInfo: yarnInfo
220
+ packageManagerInfo: packageManagerInfo
208
221
  };
209
222
  };
210
223
 
@@ -0,0 +1,6 @@
1
+ export declare const resolveReferences: (vars: Record<string, string>, getOtherVariables?: ((componentName: string, variableName: string, alreadyVisited: Record<string, Record<string, boolean>>) => string | null) | undefined, alreadyVisitedBase?: Record<string, Record<string, boolean>>) => {
2
+ [k: string]: string;
3
+ };
4
+ export declare const translateLegacyFromComponents: (fromComponents: Record<string, Record<string, string>>) => {
5
+ [k: string]: string;
6
+ };
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ var __read = this && this.__read || function (o, n) {
4
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
5
+ if (!m) return o;
6
+ var i = m.call(o),
7
+ r,
8
+ ar = [],
9
+ e;
10
+
11
+ try {
12
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
13
+ } catch (error) {
14
+ e = {
15
+ error: error
16
+ };
17
+ } finally {
18
+ try {
19
+ if (r && !r.done && (m = i["return"])) m.call(i);
20
+ } finally {
21
+ if (e) throw e.error;
22
+ }
23
+ }
24
+
25
+ return ar;
26
+ };
27
+
28
+ exports.__esModule = true;
29
+ exports.translateLegacyFromComponents = exports.resolveReferences = void 0;
30
+
31
+ var lodash_1 = require("lodash");
32
+
33
+ var REGEX = /\$\{(([^:]+):)?([^}]+)}/gm;
34
+
35
+ var resolveReferences = function (vars, getOtherVariables, alreadyVisitedBase) {
36
+ if (alreadyVisitedBase === void 0) {
37
+ alreadyVisitedBase = {};
38
+ }
39
+
40
+ var replaceSingleValue = function (value, alreadyVisited) {
41
+ if (alreadyVisited === void 0) {
42
+ alreadyVisited = alreadyVisitedBase;
43
+ }
44
+
45
+ if (REGEX.test(value)) {
46
+ return value.replace(REGEX, function (match, _, componentName, variableName) {
47
+ var _a, _b;
48
+
49
+ var _c, _d;
50
+
51
+ if ((_c = alreadyVisited[componentName]) === null || _c === void 0 ? void 0 : _c[variableName]) {
52
+ return match; // prevent endless loop
53
+ }
54
+
55
+ var newAlreadyVisited = (0, lodash_1.merge)({}, alreadyVisited, (_a = {}, _a[componentName] = (_b = {}, _b[variableName] = true, _b), _a));
56
+ var result = componentName ? (_d = getOtherVariables === null || getOtherVariables === void 0 ? void 0 : getOtherVariables(componentName, variableName, newAlreadyVisited)) !== null && _d !== void 0 ? _d : null : vars[variableName]; // is self reference
57
+
58
+ var replaced = result !== null && result !== undefined ? replaceSingleValue(result, newAlreadyVisited) : match;
59
+ return replaced;
60
+ });
61
+ } else {
62
+ return value;
63
+ }
64
+ };
65
+
66
+ return Object.fromEntries(Object.entries(vars).map(function (_a) {
67
+ var _b = __read(_a, 2),
68
+ key = _b[0],
69
+ value = _b[1];
70
+
71
+ return [key, replaceSingleValue(value)];
72
+ }));
73
+ };
74
+
75
+ exports.resolveReferences = resolveReferences;
76
+
77
+ var translateLegacyFromComponents = function (fromComponents) {
78
+ return Object.fromEntries(Object.entries(fromComponents).flatMap(function (_a) {
79
+ var _b = __read(_a, 2),
80
+ componentName = _b[0],
81
+ variables = _b[1];
82
+
83
+ return Object.entries(variables).map(function (_a) {
84
+ var _b = __read(_a, 2),
85
+ ourName = _b[0],
86
+ otherName = _b[1];
87
+
88
+ return [ourName, "${" + componentName + ":" + otherName + "}"];
89
+ });
90
+ }));
91
+ };
92
+
93
+ exports.translateLegacyFromComponents = translateLegacyFromComponents;
@@ -0,0 +1 @@
1
+ export {};