@catladder/pipeline 0.0.7 → 1.0.2

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 (211) hide show
  1. package/babel-inline.json +11 -0
  2. package/bin/catladder-gitlab.js +3 -0
  3. package/dist/build/base/constants.d.ts +7 -0
  4. package/dist/build/base/constants.js +11 -0
  5. package/dist/build/base/createBuildJob.d.ts +5 -0
  6. package/dist/build/base/createBuildJob.js +99 -0
  7. package/dist/build/docker.d.ts +5 -0
  8. package/dist/build/docker.js +95 -0
  9. package/dist/build/index.d.ts +12 -0
  10. package/dist/build/index.js +63 -0
  11. package/dist/build/node/buildJob.d.ts +3 -0
  12. package/dist/build/node/buildJob.js +97 -0
  13. package/dist/build/node/cache.d.ts +4 -0
  14. package/dist/build/node/cache.js +67 -0
  15. package/dist/build/node/constants.d.ts +6 -0
  16. package/dist/build/node/constants.js +10 -0
  17. package/dist/build/node/index.d.ts +5 -0
  18. package/dist/build/node/index.js +63 -0
  19. package/dist/build/node/meteor.d.ts +3 -0
  20. package/dist/build/node/meteor.js +103 -0
  21. package/dist/build/node/testJob.d.ts +3 -0
  22. package/dist/build/node/testJob.js +112 -0
  23. package/dist/build/node/yarn.d.ts +2 -0
  24. package/dist/build/node/yarn.js +12 -0
  25. package/dist/build/tests/storybook.test.d.ts +1 -0
  26. package/dist/build/tests/storybook.test.js +221 -0
  27. package/dist/build/types.d.ts +63 -0
  28. package/dist/build/types.js +16 -0
  29. package/dist/catladder-gitlab.d.ts +1 -0
  30. package/dist/catladder-gitlab.js +44 -0
  31. package/dist/config/configruedEnvs.d.ts +4 -0
  32. package/dist/config/configruedEnvs.js +86 -0
  33. package/dist/config/configruedEnvs.test.d.ts +1 -0
  34. package/dist/config/configruedEnvs.test.js +103 -0
  35. package/dist/config/index.d.ts +2 -0
  36. package/dist/config/index.js +24 -0
  37. package/dist/config/readConfig.d.ts +2 -0
  38. package/dist/config/readConfig.js +47 -0
  39. package/dist/constants.d.ts +2 -0
  40. package/dist/constants.js +6 -0
  41. package/dist/context/index.d.ts +5 -0
  42. package/dist/context/index.js +211 -0
  43. package/dist/defaults/index.d.ts +2 -0
  44. package/dist/defaults/index.js +8 -0
  45. package/dist/deploy/base.d.ts +9 -0
  46. package/dist/deploy/base.js +94 -0
  47. package/dist/deploy/index.d.ts +11 -0
  48. package/dist/deploy/index.js +34 -0
  49. package/dist/deploy/kubernetes/cloudsql.d.ts +6 -0
  50. package/dist/deploy/kubernetes/cloudsql.js +16 -0
  51. package/dist/deploy/kubernetes/deployJob.d.ts +3 -0
  52. package/dist/deploy/kubernetes/deployJob.js +148 -0
  53. package/dist/deploy/kubernetes/index.d.ts +1 -0
  54. package/dist/deploy/kubernetes/index.js +22 -0
  55. package/dist/deploy/kubernetes/mongodb.d.ts +15 -0
  56. package/dist/deploy/kubernetes/mongodb.js +23 -0
  57. package/dist/deploy/types.d.ts +92 -0
  58. package/dist/deploy/types.js +16 -0
  59. package/dist/index.d.ts +8 -0
  60. package/dist/index.js +36 -0
  61. package/dist/pipeline/createChildPipeline.d.ts +9 -0
  62. package/dist/pipeline/createChildPipeline.js +266 -0
  63. package/dist/pipeline/createChildPipeline.test.d.ts +1 -0
  64. package/dist/pipeline/createChildPipeline.test.js +199 -0
  65. package/dist/pipeline/createJobs.d.ts +3 -0
  66. package/dist/pipeline/createJobs.js +331 -0
  67. package/dist/pipeline/index.d.ts +2 -0
  68. package/dist/pipeline/index.js +24 -0
  69. package/dist/pipeline/yarnInfo.d.ts +2 -0
  70. package/dist/pipeline/yarnInfo.js +296 -0
  71. package/dist/rules/index.d.ts +3 -0
  72. package/dist/rules/index.js +27 -0
  73. package/dist/runner/index.d.ts +3 -0
  74. package/dist/runner/index.js +12 -0
  75. package/dist/tsconfig.tsbuildinfo +1 -0
  76. package/dist/types/config.d.ts +73 -0
  77. package/dist/types/config.js +80 -0
  78. package/dist/types/context.d.ts +36 -0
  79. package/dist/types/context.js +3 -0
  80. package/dist/types/gitlab-types.d.ts +86 -0
  81. package/dist/types/gitlab-types.js +5 -0
  82. package/dist/{scripts/magic/types → types}/index.d.ts +1 -1
  83. package/dist/types/index.js +26 -0
  84. package/dist/utils/index.d.ts +2 -0
  85. package/dist/utils/index.js +18 -0
  86. package/package.json +30 -9
  87. package/src/build/base/constants.ts +7 -0
  88. package/src/build/base/createBuildJob.ts +46 -0
  89. package/{scripts/magic → src}/build/docker.ts +15 -2
  90. package/src/build/index.ts +42 -0
  91. package/src/build/node/buildJob.ts +54 -0
  92. package/src/build/node/cache.ts +36 -0
  93. package/src/build/node/constants.ts +6 -0
  94. package/src/build/node/index.ts +17 -0
  95. package/src/build/node/meteor.ts +75 -0
  96. package/src/build/node/testJob.ts +80 -0
  97. package/src/build/node/yarn.ts +8 -0
  98. package/src/build/tests/storybook.test.ts +46 -0
  99. package/src/build/types.ts +75 -0
  100. package/src/catladder-gitlab.ts +52 -0
  101. package/src/config/configruedEnvs.test.ts +97 -0
  102. package/src/config/configruedEnvs.ts +56 -0
  103. package/src/config/index.ts +2 -0
  104. package/src/config/readConfig.ts +36 -0
  105. package/src/constants.ts +2 -0
  106. package/src/context/index.ts +194 -0
  107. package/src/defaults/index.ts +6 -0
  108. package/src/deploy/base.ts +101 -0
  109. package/src/deploy/index.ts +19 -0
  110. package/src/deploy/kubernetes/cloudsql.ts +13 -0
  111. package/src/deploy/kubernetes/deployJob.ts +116 -0
  112. package/src/deploy/kubernetes/index.ts +1 -0
  113. package/src/deploy/kubernetes/mongodb.ts +20 -0
  114. package/src/deploy/types.ts +60 -0
  115. package/src/index.ts +8 -0
  116. package/{scripts/magic/tests/createPipeline.test.ts → src/pipeline/createChildPipeline.test.ts} +5 -4
  117. package/src/pipeline/createChildPipeline.ts +51 -0
  118. package/src/pipeline/createJobs.ts +158 -0
  119. package/src/pipeline/index.ts +2 -0
  120. package/src/pipeline/yarnInfo.ts +54 -0
  121. package/src/rules/index.ts +37 -0
  122. package/src/runner/index.ts +10 -0
  123. package/src/types/config.ts +88 -0
  124. package/src/types/context.ts +36 -0
  125. package/src/types/gitlab-types.ts +94 -0
  126. package/{scripts/magic → src}/types/index.ts +0 -0
  127. package/src/utils/index.ts +10 -0
  128. package/tsconfig.json +4 -2
  129. package/Dockerfile +0 -84
  130. package/dist/scripts/createSamplePipeline.d.ts +0 -2
  131. package/dist/scripts/createSamplePipeline.js +0 -14
  132. package/dist/scripts/magic/build/docker.d.ts +0 -2
  133. package/dist/scripts/magic/build/docker.js +0 -68
  134. package/dist/scripts/magic/build/index.d.ts +0 -9
  135. package/dist/scripts/magic/build/index.js +0 -12
  136. package/dist/scripts/magic/build/node.d.ts +0 -6
  137. package/dist/scripts/magic/build/node.js +0 -150
  138. package/dist/scripts/magic/build/types.d.ts +0 -18
  139. package/dist/scripts/magic/build/types.js +0 -7
  140. package/dist/scripts/magic/context/index.d.ts +0 -3
  141. package/dist/scripts/magic/context/index.js +0 -122
  142. package/dist/scripts/magic/createChildPipeline/index.d.ts +0 -3
  143. package/dist/scripts/magic/createChildPipeline/index.js +0 -68
  144. package/dist/scripts/magic/createPipeline.d.ts +0 -14
  145. package/dist/scripts/magic/createPipeline.js +0 -80
  146. package/dist/scripts/magic/deploy/index.d.ts +0 -9
  147. package/dist/scripts/magic/deploy/index.js +0 -12
  148. package/dist/scripts/magic/deploy/kubernetes.d.ts +0 -5
  149. package/dist/scripts/magic/deploy/kubernetes.js +0 -62
  150. package/dist/scripts/magic/deploy/types.d.ts +0 -41
  151. package/dist/scripts/magic/deploy/types.js +0 -7
  152. package/dist/scripts/magic/index.d.ts +0 -2
  153. package/dist/scripts/magic/index.js +0 -16
  154. package/dist/scripts/magic/sample-config.d.ts +0 -3
  155. package/dist/scripts/magic/sample-config.js +0 -77
  156. package/dist/scripts/magic/tests/createPipeline.test.d.ts +0 -1
  157. package/dist/scripts/magic/tests/createPipeline.test.js +0 -89
  158. package/dist/scripts/magic/types/config.d.ts +0 -49
  159. package/dist/scripts/magic/types/config.js +0 -17
  160. package/dist/scripts/magic/types/context.d.ts +0 -19
  161. package/dist/scripts/magic/types/context.js +0 -2
  162. package/dist/scripts/magic/types/gitlab-types.d.ts +0 -57
  163. package/dist/scripts/magic/types/gitlab-types.js +0 -2
  164. package/dist/scripts/magic/types/index.js +0 -15
  165. package/dist/scripts/magic.d.ts +0 -2
  166. package/dist/scripts/magic.js +0 -43
  167. package/dist/scripts/monorepoGenerate.d.ts +0 -2
  168. package/dist/scripts/monorepoGenerate.js +0 -164
  169. package/dist/scripts/printAllValues.d.ts +0 -2
  170. package/dist/scripts/printAllValues.js +0 -58
  171. package/dist/scripts/printBuildEnv.d.ts +0 -2
  172. package/dist/scripts/printBuildEnv.js +0 -77
  173. package/dist/scripts/utils/extractAllValues.d.ts +0 -1
  174. package/dist/scripts/utils/extractAllValues.js +0 -78
  175. package/dist/scripts/utils/extractBuildEnv.d.ts +0 -5
  176. package/dist/scripts/utils/extractBuildEnv.js +0 -152
  177. package/dist/scripts/utils/extractValuesFromEnvVars.d.ts +0 -2
  178. package/dist/scripts/utils/extractValuesFromEnvVars.js +0 -63
  179. package/dist/scripts/utils/extractValuesFromMr.d.ts +0 -2
  180. package/dist/scripts/utils/extractValuesFromMr.js +0 -86
  181. package/dist/tests/extractValuesFromMr.test.d.ts +0 -1
  182. package/dist/tests/extractValuesFromMr.test.js +0 -68
  183. package/scripts/createSamplePipeline.ts +0 -10
  184. package/scripts/getCommitInfo +0 -11
  185. package/scripts/kubernetesCreateSecret +0 -9
  186. package/scripts/kubernetesDelete +0 -4
  187. package/scripts/kubernetesDeploy +0 -55
  188. package/scripts/kubernetesEnsureNamespace +0 -3
  189. package/scripts/magic/build/index.ts +0 -18
  190. package/scripts/magic/build/node.ts +0 -143
  191. package/scripts/magic/build/types.ts +0 -21
  192. package/scripts/magic/context/index.ts +0 -127
  193. package/scripts/magic/createChildPipeline/index.ts +0 -60
  194. package/scripts/magic/createPipeline.ts +0 -52
  195. package/scripts/magic/deploy/index.ts +0 -19
  196. package/scripts/magic/deploy/kubernetes.ts +0 -65
  197. package/scripts/magic/deploy/types.ts +0 -29
  198. package/scripts/magic/index.ts +0 -2
  199. package/scripts/magic/sample-config.ts +0 -78
  200. package/scripts/magic/types/config.ts +0 -54
  201. package/scripts/magic/types/context.ts +0 -21
  202. package/scripts/magic/types/gitlab-types.ts +0 -69
  203. package/scripts/magic.ts +0 -51
  204. package/scripts/monorepoGenerate.ts +0 -104
  205. package/scripts/printAllValues.ts +0 -17
  206. package/scripts/printBuildEnv.ts +0 -22
  207. package/scripts/utils/extractAllValues.ts +0 -32
  208. package/scripts/utils/extractBuildEnv.ts +0 -94
  209. package/scripts/utils/extractValuesFromEnvVars.ts +0 -21
  210. package/scripts/utils/extractValuesFromMr.ts +0 -39
  211. package/tests/extractValuesFromMr.test.ts +0 -156
@@ -1,63 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- "use strict";
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), r, ar = [], e;
7
- try {
8
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
9
- }
10
- catch (error) { e = { error: error }; }
11
- finally {
12
- try {
13
- if (r && !r.done && (m = i["return"])) m.call(i);
14
- }
15
- finally { if (e) throw e.error; }
16
- }
17
- return ar;
18
- };
19
- var __values = (this && this.__values) || function(o) {
20
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
21
- if (m) return m.call(o);
22
- if (o && typeof o.length === "number") return {
23
- next: function () {
24
- if (o && i >= o.length) o = void 0;
25
- return { value: o && o[i++], done: !o };
26
- }
27
- };
28
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
29
- };
30
- exports.__esModule = true;
31
- exports.extractValuesFromEnvVars = void 0;
32
- var lodash_1 = require("lodash");
33
- var extractValuesFromEnvVars = function () {
34
- var e_1, _a;
35
- var values = {};
36
- var PREFIX = "DEFAULT_VALUE_";
37
- try {
38
- for (var _b = __values(Object.entries(process.env).filter(function (_a) {
39
- var _b = __read(_a, 1), key = _b[0];
40
- return key.startsWith(PREFIX);
41
- })), _c = _b.next(); !_c.done; _c = _b.next()) {
42
- var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
43
- var path = key.replace(PREFIX, "").split("_");
44
- var theValue = void 0;
45
- try {
46
- theValue = JSON.parse(value !== null && value !== void 0 ? value : "");
47
- }
48
- catch (e) {
49
- theValue = value;
50
- }
51
- lodash_1.set(values, path, theValue);
52
- }
53
- }
54
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
55
- finally {
56
- try {
57
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
58
- }
59
- finally { if (e_1) throw e_1.error; }
60
- }
61
- return values;
62
- };
63
- exports.extractValuesFromEnvVars = extractValuesFromEnvVars;
@@ -1,2 +0,0 @@
1
- export declare const extractValuesFromMRMessage: (mrMessage: string) => {} | undefined;
2
- export declare const extractValuesFromMr: (projectId: string, mergeRequestId: number) => Promise<{} | undefined>;
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- exports.__esModule = true;
39
- exports.extractValuesFromMr = exports.extractValuesFromMRMessage = void 0;
40
- var node_1 = require("@gitbeaker/node"); // Just the Project Resource
41
- var yaml_1 = require("yaml");
42
- var lodash_1 = require("lodash");
43
- var _a = process.env, GL_TOKEN = _a.GL_TOKEN, CI_SERVER_URL = _a.CI_SERVER_URL;
44
- var gitlabApi = new node_1.Gitlab({
45
- token: GL_TOKEN,
46
- host: CI_SERVER_URL
47
- });
48
- var getMRInfo = function (projectId, mrId) { return __awaiter(void 0, void 0, void 0, function () {
49
- return __generator(this, function (_a) {
50
- switch (_a.label) {
51
- case 0: return [4 /*yield*/, gitlabApi.MergeRequests.show(projectId, mrId)];
52
- case 1: return [2 /*return*/, _a.sent()];
53
- }
54
- });
55
- }); };
56
- var extractValuesFromMRMessage = function (mrMessage) {
57
- var codeBlocks = Array.from(mrMessage.matchAll(/```.*([^`]+)```/gm)).map(function (match) { return match[1]; });
58
- return codeBlocks.reduce(function (values, block) {
59
- if (values === void 0) { values = {}; }
60
- if (block.includes("$env") || block.includes("$values"))
61
- try {
62
- var _a = yaml_1.parse(block), $values = _a.$values, $env = _a.$env;
63
- if ($values)
64
- lodash_1.merge(values, $values);
65
- if ($env)
66
- lodash_1.merge(values, { env: { public: $env } });
67
- return values;
68
- }
69
- catch (e) {
70
- console.warn(e);
71
- }
72
- }, {});
73
- };
74
- exports.extractValuesFromMRMessage = extractValuesFromMRMessage;
75
- var extractValuesFromMr = function (projectId, mergeRequestId) { return __awaiter(void 0, void 0, void 0, function () {
76
- var mrInfo;
77
- return __generator(this, function (_a) {
78
- switch (_a.label) {
79
- case 0: return [4 /*yield*/, getMRInfo(projectId, mergeRequestId)];
80
- case 1:
81
- mrInfo = _a.sent();
82
- return [2 /*return*/, exports.extractValuesFromMRMessage(mrInfo.description)];
83
- }
84
- });
85
- }); };
86
- exports.extractValuesFromMr = extractValuesFromMr;
@@ -1 +0,0 @@
1
- export {};
@@ -1,68 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- var extractValuesFromMr_1 = require("../scripts/utils/extractValuesFromMr");
4
- describe("extractValuesFromMr", function () {
5
- describe("extractValuesFromMRMessage", function () {
6
- it("can extract $values yaml", function () {
7
- var result = extractValuesFromMr_1.extractValuesFromMRMessage("\n \n blabla\n\n test\n\n ```\n $values:\n application:\n host: www.foo.com\n env:\n public:\n API_KEY: fooooxxx\n BLA: \"blubb\"\n ```\n ");
8
- expect(result).toEqual({
9
- application: {
10
- host: "www.foo.com"
11
- },
12
- env: {
13
- public: {
14
- API_KEY: "fooooxxx",
15
- BLA: "blubb"
16
- }
17
- }
18
- });
19
- });
20
- it("can handle $env as shortcut", function () {
21
- var result = extractValuesFromMr_1.extractValuesFromMRMessage("\n \n blabla\n\n test\n\n ```\n $env:\n API_KEY: fooooxxx\n BLA: \"blubb\"\n \n ```\n ");
22
- expect(result).toEqual({
23
- env: {
24
- public: {
25
- API_KEY: "fooooxxx",
26
- BLA: "blubb"
27
- }
28
- }
29
- });
30
- });
31
- it("ignores language in backticks", function () {
32
- var result = extractValuesFromMr_1.extractValuesFromMRMessage("\n \n blabla\n\n test\n\n ```yaml\n $env:\n API_KEY: fooooxxx\n BLA: \"blubb\"\n \n ```\n ");
33
- expect(result).toEqual({
34
- env: {
35
- public: {
36
- API_KEY: "fooooxxx",
37
- BLA: "blubb"
38
- }
39
- }
40
- });
41
- });
42
- it("can handle mixed blocks", function () {
43
- var result = extractValuesFromMr_1.extractValuesFromMRMessage("\n \n blabla\n\n test\n\n ```\n $values:\n env:\n public:\n FOO: \"bar\"\n\n $env:\n API_KEY: fooooxxx\n BLA: \"blubb\"\n \n ```\n ");
44
- expect(result).toEqual({
45
- env: {
46
- public: {
47
- FOO: "bar",
48
- API_KEY: "fooooxxx",
49
- BLA: "blubb"
50
- }
51
- }
52
- });
53
- });
54
- it("can handle multiple blocks", function () {
55
- var result = extractValuesFromMr_1.extractValuesFromMRMessage("\n \n blabla\n\n test\n\n ```\n $values:\n env:\n public:\n FOO: \"bar\"\n\n $env:\n API_KEY: fooooxxx\n BLA: \"blubb\"\n \n ```\n\n\n fooo\n\n ```\n $values:\n env:\n public:\n FOO: \"blubb\"\n\n $env:\n TEST: test\n \n ```\n ");
56
- expect(result).toEqual({
57
- env: {
58
- public: {
59
- FOO: "blubb",
60
- API_KEY: "fooooxxx",
61
- BLA: "blubb",
62
- TEST: "test"
63
- }
64
- }
65
- });
66
- });
67
- });
68
- });
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- import { writeFileSync } from "fs";
3
- import { createPipeline } from "./magic/createPipeline";
4
- import sampleConfig from "./magic/sample-config";
5
-
6
- createPipeline("taggedRelease", sampleConfig).then((mainPipeline) => {
7
- writeFileSync(`__pipeline.yml`, JSON.stringify(mainPipeline, null, 2), {
8
- encoding: "utf-8",
9
- });
10
- });
@@ -1,11 +0,0 @@
1
- #!/bin/bash
2
-
3
- export BUILD_TAG="$(git describe --tags || git rev-parse HEAD)"
4
- export BUILD_ID="$BUILD_TAG"
5
- export BUILD_COMMIT="$(git rev-parse HEAD)"
6
- export BUILD_TIME="$(date)"
7
- echo "BUILD_TAG=$BUILD_TAG" >>build.env
8
- echo "BUILD_ID=$BUILD_ID" >>build.env
9
- echo "BUILD_COMMIT=$BUILD_COMMIT" >>build.env
10
- echo "BUILD_TIME=$BUILD_TIME" >>build.env
11
- echo '{"id":"'$BUILD_ID'","commit":"'$BUILD_COMMIT'","tag":"'$BUILD_TAG'","time":"'$BUILD_TIME'"}' >__build_info.json
@@ -1,9 +0,0 @@
1
- #!/bin/bash
2
- echo "KUBE_NAMESPACE: '$KUBE_NAMESPACE', IMAGE_PULL_SECRET: '$IMAGE_PULL_SECRET'"
3
- kubectl create secret -n "$KUBE_NAMESPACE" \
4
- docker-registry $IMAGE_PULL_SECRET \
5
- --docker-server="$CI_REGISTRY" \
6
- --docker-username="${CI_DEPLOY_USER:-$CI_REGISTRY_USER}" \
7
- --docker-password="${CI_DEPLOY_PASSWORD:-$CI_REGISTRY_PASSWORD}" \
8
- --docker-email="$GITLAB_USER_EMAIL" \
9
- -o yaml --dry-run | kubectl replace -n "$KUBE_NAMESPACE" --force -f -
@@ -1,4 +0,0 @@
1
- #!/bin/bash
2
- RELEASE_NAME=${CUSTOMER_NAME}-${APP_NAME}-${CI_ENVIRONMENT_SLUG}
3
- echo "Delete $RELEASE_NAME"
4
- helm3 uninstall "$RELEASE_NAME" --namespace "$KUBE_NAMESPACE"
@@ -1,55 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo "Deploy to kubernetes"
4
- echo "Release: $RELEASE_NAME"
5
- echo "URL (canonical): $HOST_CANONICAL"
6
- #helm3 init --client-only --stable-repo-url=https://charts.helm.sh/stable
7
- helm3 chart pull $CI_REGISTRY/$HELM_GITLAB_CHART_PATH/$HELM_GITLAB_CHART_NAME:v$HELM_GITLAB_CHART_VERSION
8
- helm3 chart export $CI_REGISTRY/$HELM_GITLAB_CHART_PATH/$HELM_GITLAB_CHART_NAME:v$HELM_GITLAB_CHART_VERSION -d /tmp/
9
- # use helmArgs defined in variables
10
- helmArgsEvaluated=$(echo $helmArgs | envsubst)
11
-
12
- # this bash-brainfuck simply splits $helmArgs by newline to an array...
13
- readarray -t helmArgsArray <<<"$helmArgsEvaluated"
14
-
15
- #Log the time until selfdestruct in case of review environment
16
- if [[ ${ENV_SHORT} == "review" ]]; then echo "NOTE - This deployment will stop itself after 2 weeks"; fi
17
-
18
- echo "all values"
19
- echo "$KUBE_VALUES"
20
- echo $KUBE_VALUES >__all_values.yml
21
-
22
- echo "doing helm upgrade"
23
- helm3 upgrade --install "$RELEASE_NAME" /tmp/$HELM_GITLAB_CHART_NAME \
24
- --wait \
25
- --timeout 15m0s \
26
- --cleanup-on-fail \
27
- --set global.componentName="$KUBE_APP_NAME" \
28
- --set global.ENV_SHORT="$ENV_SHORT" \
29
- --set global.CI_COMMIT_REF_SLUG="$CI_COMMIT_REF_SLUG" \
30
- --set global.BUILD_ID="$BUILD_ID" \
31
- --set image.repository="$CI_REGISTRY_IMAGE" \
32
- --set image.pullSecret="$IMAGE_PULL_SECRET" \
33
- --set image.name="$COMPONENT_NAME" \
34
- --set image.tag="$IMAGE_TAG" \
35
- --set image.pullPolicy=IfNotPresent \
36
- --set storybook.enabled=$STORYBOOK \
37
- --set application.hostCanonical="$HOST_CANONICAL" \
38
- --set mongodb.enabled=$MONGODB_ENABLED \
39
- --set mongodb.backup.enabled=$MONGODB_BACKUP_ENABLED \
40
- --set mongodb-replicaset.replicas=$MONGODB_REPLICAS \
41
- --set mongodb-replicaset.fullnameOverride=$KUBE_APP_NAME-mongodb-replicaset \
42
- --set mongodb-replicaset.persistentVolume.storageClass="$MONGODB_STORAGE_CLASS" \
43
- --set mailhog.fullnameOverride=$KUBE_APP_NAME-mailhog \
44
- --set prisma.enabled=$PRISMA_ENABLED \
45
- --set gitlab.visualReviewEnabled="$GITLAB_VISUAL_REVIEW_ENABLED" \
46
- --set gitlab.app="$CI_PROJECT_PATH_SLUG" \
47
- --set gitlab.projectPath="$CI_PROJECT_PATH" \
48
- --set gitlab.mergeRequestId="$CI_MERGE_REQUEST_IID" \
49
- --set gitlab.projectId="$CI_PROJECT_ID" \
50
- --set gitlab.env="$CI_ENVIRONMENT_SLUG" \
51
- --set namespace="$KUBE_NAMESPACE" \
52
- --namespace="$KUBE_NAMESPACE" \
53
- ${helmArgsArray[@]} \
54
- --values __all_values.yml
55
- echo "Deployment successful 😻"
@@ -1,3 +0,0 @@
1
- #!/bin/bash
2
- echo "Ensure Namespace $KUBE_NAMESPACE"
3
- kubectl describe namespace "$KUBE_NAMESPACE" || kubectl create namespace "$KUBE_NAMESPACE"
@@ -1,18 +0,0 @@
1
- import { GitlabJobs } from "../types/gitlab-types";
2
- import { Context } from "../types/context";
3
- import { createNodeJobs, getNodeDefaults, getNodeStaticDefaults } from "./node";
4
- import { BuildConfig } from "./types";
5
-
6
- export const buildJobCreators: {
7
- [type in BuildConfig["type"]]: (context: Context) => GitlabJobs;
8
- } = {
9
- node: createNodeJobs,
10
- "node-static": createNodeJobs,
11
- };
12
-
13
- export const getBuildDefaults: {
14
- [type in BuildConfig["type"]]: () => Partial<BuildConfig>;
15
- } = {
16
- node: getNodeDefaults,
17
- "node-static": getNodeStaticDefaults,
18
- };
@@ -1,143 +0,0 @@
1
- import {
2
- GitlabJobDef,
3
- GitlabJobCache,
4
- GitlabJobs,
5
- Retry,
6
- } from "../types/gitlab-types";
7
- import { Context } from "../types/context";
8
- import { createDockerBuildJob } from "./docker";
9
- import { BuildConfigNode, BuildConfigNodeStatic, isOfType } from "./types";
10
-
11
- const baseRetry: Retry = {
12
- max: 2,
13
- when: ["runner_system_failure", "stuck_or_timeout_failure"],
14
- };
15
-
16
- const getYarnInstall = (context: Context) => [
17
- `cd ${context.componentConfig.dir}`,
18
- "if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi",
19
- "yarn install --frozen-lockfile",
20
- ];
21
- const getNodeCache = (context: Context): GitlabJobCache[] => [
22
- {
23
- key: "node-modules",
24
- policy: "pull-push",
25
- paths: ["node_modules", "**/node_modules/"],
26
- },
27
- ];
28
-
29
- const getNextCache = (context: Context): GitlabJobCache[] => [
30
- {
31
- key: "next-cache",
32
- policy: "pull-push",
33
- paths: [context.componentConfig.dir + "/.next/cache/"],
34
- },
35
- ];
36
- const createNodeTestJobs = (context: Context): GitlabJobs => {
37
- const base: Omit<GitlabJobDef, "script"> = {
38
- variables: {
39
- APP_PATH: context.componentConfig.dir,
40
- },
41
- cache: getNodeCache(context),
42
- stage: "test",
43
- interruptible: true,
44
- needs: [],
45
- retry: baseRetry,
46
- };
47
- const yarnInstall = getYarnInstall(context);
48
- return [
49
- {
50
- name: "audit",
51
- perEnv: false,
52
- job: {
53
- ...base,
54
- script: [...yarnInstall, "yarn audit"],
55
- allow_failure: true,
56
- },
57
- },
58
- {
59
- name: "lint",
60
- perEnv: false,
61
- job: {
62
- ...base,
63
- script: [...yarnInstall, "yarn lint"],
64
- },
65
- },
66
- {
67
- name: "test",
68
- perEnv: false,
69
- job: {
70
- ...base,
71
- script: [...yarnInstall, "yarn test"],
72
- },
73
- },
74
- ];
75
- };
76
-
77
- const createNodeBuildJobs = (context: Context): GitlabJobs => {
78
- const buildConfig = context.componentConfig.build;
79
- if (!isOfType(buildConfig, "node") && !isOfType(buildConfig, "node-static")) {
80
- // should not happen
81
- throw new Error("deploy config is not kubernetes");
82
- }
83
-
84
- const buildInfo = [
85
- ". getCommitInfo", // TODO: inline
86
- `echo '{"id":"'$BUILD_ID'","commit":"'$BUILD_COMMIT'","tag":"'$BUILD_TAG'","time":"'$BUILD_TIME'"}' > ${context.componentConfig.dir}/__build_info.json`,
87
- ];
88
-
89
- const yarnInstall = getYarnInstall(context);
90
-
91
- return [
92
- {
93
- name: "app-build",
94
- job: {
95
- needs: [],
96
- cache: [...getNodeCache(context), ...getNextCache(context)],
97
- variables: context.environment.variables,
98
- retry: baseRetry,
99
- interruptible: true,
100
- stage: "build",
101
- script: [...buildInfo, ...yarnInstall, buildConfig.buildCommand!],
102
- artifacts: {
103
- paths: [
104
- context.componentConfig.dir + "/__build_info.json",
105
- context.componentConfig.dir + "/dist",
106
- context.componentConfig.dir + "/.next",
107
- ],
108
- },
109
- },
110
- },
111
- {
112
- name: "docker-build",
113
-
114
- job: {
115
- ...createDockerBuildJob(context, {
116
- script: [
117
- buildConfig.type === "node-static"
118
- ? "ensureNginxDockerfile"
119
- : "ensureNodeDockerfile",
120
- ], // TOOD: inline
121
- }),
122
- needs: ["app-build"],
123
- },
124
- },
125
- ];
126
- };
127
-
128
- export const createNodeJobs = (context: Context): GitlabJobs => {
129
- return [...createNodeTestJobs(context), ...createNodeBuildJobs(context)];
130
- };
131
-
132
- export const getNodeDefaults = (): Partial<BuildConfigNode> => {
133
- return {
134
- startCommand: "yarn start",
135
- buildCommand: "yarn build",
136
- };
137
- };
138
-
139
- export const getNodeStaticDefaults = (): Partial<BuildConfigNodeStatic> => {
140
- return {
141
- buildCommand: "yarn build",
142
- };
143
- };
@@ -1,21 +0,0 @@
1
- export type BuildConfigBase = {
2
- startCommand?: string;
3
- };
4
- export type BuildConfigNode = {
5
- type: "node";
6
- buildCommand?: string;
7
- } & BuildConfigBase;
8
-
9
- export type BuildConfigNodeStatic = {
10
- type: "node-static";
11
- buildCommand?: string;
12
- startCommand: never;
13
- };
14
- export type BuildConfig = BuildConfigNode | BuildConfigNodeStatic;
15
-
16
- export const isOfType = <T extends BuildConfig["type"]>(
17
- t: BuildConfig,
18
- type: T
19
- ): t is Extract<BuildConfig, { type: T }> => {
20
- return t.type === type;
21
- };
@@ -1,127 +0,0 @@
1
- import { merge } from "lodash";
2
- import slugify from "slugify";
3
- import { getBuildDefaults } from "../build";
4
- import { BuildConfig } from "../build/types";
5
- import { getDeployDefaults } from "../deploy";
6
- import { DeployConfig } from "../deploy/types";
7
- import { Config } from "../types/config";
8
- import { CommitInfo, Context, Environment } from "../types/context";
9
-
10
- const getEnvironment = (
11
- config: Config,
12
- componentName: string,
13
- env: string,
14
- commitInfo: CommitInfo
15
- ): Environment => {
16
- const componentConfig = config.components[componentName];
17
- if (!componentConfig) {
18
- throw new Error("unknown component " + componentName);
19
- }
20
-
21
- const defaultConfig = componentConfig;
22
- const envConfig = componentConfig.env?.[env] ?? {};
23
-
24
- const mergedConfig = merge({}, defaultConfig, envConfig);
25
-
26
- const publicEnvVars = mergedConfig.vars?.public ?? {};
27
- const secretEnvVarsRaw = mergedConfig.vars?.secret ?? {}; // TODO, map to gl secrets?
28
- const secretEnvVars = {}; // TODO
29
- const referencedRaw = mergedConfig.vars?.fromComponents ?? {};
30
-
31
- const referenced = Object.entries(referencedRaw).reduce(
32
- (acc, [otherApp, mapping]) => {
33
- // TODO: prevent infinit looop
34
- const { variables } = getEnvironment(config, otherApp, env, commitInfo);
35
-
36
- return Object.fromEntries(
37
- Object.entries(mapping).map(([ourKey, otherKey]) => [
38
- ourKey,
39
- variables[otherKey],
40
- ])
41
- );
42
- },
43
- {}
44
- );
45
-
46
- const envType = componentConfig.env?.[env]?.type ?? env;
47
- const environmentName =
48
- envType === "review"
49
- ? `${env}/${componentName}/${commitInfo.refName}`
50
- : `${env}/${componentName}`;
51
-
52
- const KUBE_APP_NAME =
53
- envType === "review"
54
- ? `${componentName}-${commitInfo.refSlug}`
55
- : componentName;
56
-
57
- const KUBE_NAMESPACE = `${config.customerName}-${config.appName}-${env}`;
58
-
59
- const APP_SLUG = slugify(KUBE_APP_NAME);
60
-
61
- const HOST_CANONICAL = `${config.appName}-${APP_SLUG}.${config.customerName}.panter.cloud`;
62
-
63
- const hostname = mergedConfig.hostname ?? HOST_CANONICAL;
64
- const url = `https://${hostname}`;
65
-
66
- const predefinedVariables = {
67
- HOST_CANONICAL,
68
- ROOT_URL: url,
69
- KUBE_NAMESPACE,
70
- KUBE_APP_NAME,
71
- ENV_SHORT: env,
72
- APP_DIR: componentConfig.dir,
73
- };
74
- const variables = {
75
- ...predefinedVariables,
76
- ...publicEnvVars,
77
- ...secretEnvVars,
78
- ...referenced,
79
- };
80
-
81
- return {
82
- hostname,
83
- fullName: environmentName,
84
- shortName: env,
85
- url: url,
86
- variables,
87
- };
88
- };
89
-
90
- export const createContext = (
91
- componentName: string,
92
- config: Config,
93
- env: string
94
- ): Context => {
95
- if (!/^[a-z0-9-]+$/.test(componentName)) {
96
- throw new Error(
97
- "componentName may only contain lower case letters, numbers and -"
98
- );
99
- }
100
- const rawConfig = config.components[componentName];
101
- if (!rawConfig) {
102
- throw new Error("unknown component " + componentName);
103
- }
104
- // envs can override the config
105
- const envConfig = rawConfig.env?.[env] ?? {};
106
- const componentConfigWithoutDefaults = merge({}, rawConfig, envConfig);
107
- // fill in defaults of build and deploy
108
- const defaults: {
109
- build: Partial<BuildConfig>;
110
- deploy: Partial<DeployConfig>;
111
- } = {
112
- build: getBuildDefaults[componentConfigWithoutDefaults.build.type](),
113
- deploy: getDeployDefaults[componentConfigWithoutDefaults.deploy.type](),
114
- };
115
- const componentConfig = merge({}, defaults, componentConfigWithoutDefaults);
116
- const commit = {
117
- refName: process.env.CI_COMMIT_REF_NAME ?? "unknown",
118
- refSlug: process.env.CI_COMMIT_REF_SLUG ?? "unknown",
119
- };
120
- return {
121
- fullConfig: config,
122
- componentConfig,
123
- componentName,
124
- environment: getEnvironment(config, componentName, env, commit),
125
- commit: commit,
126
- };
127
- };