@catladder/pipeline 0.0.6 → 1.0.1

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 (208) 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 -8
  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 +17 -4
  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} +12 -11
  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 -10
  136. package/dist/scripts/magic/build/node.d.ts +0 -5
  137. package/dist/scripts/magic/build/node.js +0 -137
  138. package/dist/scripts/magic/build/types.d.ts +0 -12
  139. package/dist/scripts/magic/build/types.js +0 -7
  140. package/dist/scripts/magic/createChildPipeline/index.d.ts +0 -5
  141. package/dist/scripts/magic/createChildPipeline/index.js +0 -153
  142. package/dist/scripts/magic/createPipeline.d.ts +0 -14
  143. package/dist/scripts/magic/createPipeline.js +0 -80
  144. package/dist/scripts/magic/deploy/index.d.ts +0 -9
  145. package/dist/scripts/magic/deploy/index.js +0 -12
  146. package/dist/scripts/magic/deploy/kubernetes.d.ts +0 -5
  147. package/dist/scripts/magic/deploy/kubernetes.js +0 -62
  148. package/dist/scripts/magic/deploy/types.d.ts +0 -41
  149. package/dist/scripts/magic/deploy/types.js +0 -7
  150. package/dist/scripts/magic/index.d.ts +0 -2
  151. package/dist/scripts/magic/index.js +0 -16
  152. package/dist/scripts/magic/sample-config.d.ts +0 -3
  153. package/dist/scripts/magic/sample-config.js +0 -77
  154. package/dist/scripts/magic/tests/createPipeline.test.d.ts +0 -1
  155. package/dist/scripts/magic/tests/createPipeline.test.js +0 -89
  156. package/dist/scripts/magic/types/config.d.ts +0 -49
  157. package/dist/scripts/magic/types/config.js +0 -17
  158. package/dist/scripts/magic/types/context.d.ts +0 -19
  159. package/dist/scripts/magic/types/context.js +0 -2
  160. package/dist/scripts/magic/types/gitlab-types.d.ts +0 -57
  161. package/dist/scripts/magic/types/gitlab-types.js +0 -2
  162. package/dist/scripts/magic/types/index.js +0 -15
  163. package/dist/scripts/magic.d.ts +0 -2
  164. package/dist/scripts/magic.js +0 -43
  165. package/dist/scripts/monorepoGenerate.d.ts +0 -2
  166. package/dist/scripts/monorepoGenerate.js +0 -164
  167. package/dist/scripts/printAllValues.d.ts +0 -2
  168. package/dist/scripts/printAllValues.js +0 -58
  169. package/dist/scripts/printBuildEnv.d.ts +0 -2
  170. package/dist/scripts/printBuildEnv.js +0 -77
  171. package/dist/scripts/utils/extractAllValues.d.ts +0 -1
  172. package/dist/scripts/utils/extractAllValues.js +0 -78
  173. package/dist/scripts/utils/extractBuildEnv.d.ts +0 -5
  174. package/dist/scripts/utils/extractBuildEnv.js +0 -152
  175. package/dist/scripts/utils/extractValuesFromEnvVars.d.ts +0 -2
  176. package/dist/scripts/utils/extractValuesFromEnvVars.js +0 -63
  177. package/dist/scripts/utils/extractValuesFromMr.d.ts +0 -2
  178. package/dist/scripts/utils/extractValuesFromMr.js +0 -86
  179. package/dist/tests/extractValuesFromMr.test.d.ts +0 -1
  180. package/dist/tests/extractValuesFromMr.test.js +0 -68
  181. package/scripts/createSamplePipeline.ts +0 -10
  182. package/scripts/getCommitInfo +0 -11
  183. package/scripts/kubernetesCreateSecret +0 -9
  184. package/scripts/kubernetesDelete +0 -4
  185. package/scripts/kubernetesDeploy +0 -55
  186. package/scripts/kubernetesEnsureNamespace +0 -3
  187. package/scripts/magic/build/index.ts +0 -16
  188. package/scripts/magic/build/node.ts +0 -130
  189. package/scripts/magic/build/types.ts +0 -17
  190. package/scripts/magic/createChildPipeline/index.ts +0 -176
  191. package/scripts/magic/createPipeline.ts +0 -52
  192. package/scripts/magic/deploy/index.ts +0 -19
  193. package/scripts/magic/deploy/kubernetes.ts +0 -65
  194. package/scripts/magic/deploy/types.ts +0 -29
  195. package/scripts/magic/index.ts +0 -2
  196. package/scripts/magic/sample-config.ts +0 -78
  197. package/scripts/magic/types/config.ts +0 -54
  198. package/scripts/magic/types/context.ts +0 -21
  199. package/scripts/magic/types/gitlab-types.ts +0 -69
  200. package/scripts/magic.ts +0 -51
  201. package/scripts/monorepoGenerate.ts +0 -104
  202. package/scripts/printAllValues.ts +0 -17
  203. package/scripts/printBuildEnv.ts +0 -22
  204. package/scripts/utils/extractAllValues.ts +0 -32
  205. package/scripts/utils/extractBuildEnv.ts +0 -94
  206. package/scripts/utils/extractValuesFromEnvVars.ts +0 -21
  207. package/scripts/utils/extractValuesFromMr.ts +0 -39
  208. package/tests/extractValuesFromMr.test.ts +0 -156
@@ -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,16 +0,0 @@
1
- import { GitlabJobs } from "../types/gitlab-types";
2
- import { Context } from "../types/context";
3
- import { createNodeJobs, getNodeDefaults } 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
- };
11
-
12
- export const getBuildDefaults: {
13
- [type in BuildConfig["type"]]: () => Partial<BuildConfig>;
14
- } = {
15
- node: getNodeDefaults,
16
- };
@@ -1,130 +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, 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 createNodeTestJobs = (context: Context): GitlabJobs => {
22
- const cache: GitlabJobCache[] = [
23
- {
24
- key: "node-modules",
25
- policy: "pull-push",
26
- paths: ["node_modules", "**/node_modules/"],
27
- },
28
- ];
29
-
30
- const base: Omit<GitlabJobDef, "script"> = {
31
- variables: {
32
- APP_PATH: context.componentConfig.dir,
33
- },
34
- cache,
35
- stage: "test",
36
- interruptible: true,
37
- needs: [],
38
- retry: baseRetry,
39
- };
40
- const yarnInstall = getYarnInstall(context);
41
- return [
42
- {
43
- name: "audit",
44
- perEnv: false,
45
- job: {
46
- ...base,
47
- script: [...yarnInstall, "yarn audit"],
48
- allow_failure: true,
49
- },
50
- },
51
- {
52
- name: "lint",
53
- perEnv: false,
54
- job: {
55
- ...base,
56
- script: [...yarnInstall, "yarn lint"],
57
- },
58
- },
59
- {
60
- name: "test",
61
- perEnv: false,
62
- job: {
63
- ...base,
64
- script: [...yarnInstall, "yarn test"],
65
- },
66
- },
67
- ];
68
- };
69
-
70
- const createNodeBuildJobs = (context: Context): GitlabJobs => {
71
- const buildConfig = context.componentConfig.build;
72
- if (!isOfType(buildConfig, "node")) {
73
- // should not happen
74
- throw new Error("deploy config is not kubernetes");
75
- }
76
-
77
- const buildInfo = [
78
- ". getCommitInfo", // TODO: inline
79
- `echo '{"id":"'$BUILD_ID'","commit":"'$BUILD_COMMIT'","tag":"'$BUILD_TAG'","time":"'$BUILD_TIME'"}' > ${context.componentConfig.dir}/__build_info.json`,
80
- ];
81
-
82
- const yarnInstall = getYarnInstall(context);
83
-
84
- return [
85
- {
86
- name: "app-build",
87
- job: {
88
- needs: [],
89
- variables: context.environment.variables,
90
- retry: baseRetry,
91
- interruptible: true,
92
- stage: "build",
93
- script: [...buildInfo, ...yarnInstall, buildConfig.buildCommand!],
94
- artifacts: {
95
- paths: [
96
- context.componentConfig.dir + "/__build_info.json",
97
- context.componentConfig.dir + "/dist",
98
- context.componentConfig.dir + "/.next",
99
- ],
100
- },
101
- },
102
- },
103
- {
104
- name: "docker-build",
105
-
106
- job: {
107
- ...createDockerBuildJob(context, {
108
- script: [
109
- buildConfig.runtime === "static"
110
- ? "ensureNginxDockerfile"
111
- : "ensureNodeDockerfile",
112
- ], // TOOD: inline
113
- }),
114
- needs: ["app-build"],
115
- },
116
- },
117
- ];
118
- };
119
-
120
- export const createNodeJobs = (context: Context): GitlabJobs => {
121
- return [...createNodeTestJobs(context), ...createNodeBuildJobs(context)];
122
- };
123
-
124
- export const getNodeDefaults = (): Partial<BuildConfigNode> => {
125
- return {
126
- startCommand: "yarn start",
127
- runtime: "dynamic",
128
- buildCommand: "yarn build",
129
- };
130
- };
@@ -1,17 +0,0 @@
1
- export type BuildConfigBase = {
2
- startCommand?: string;
3
- };
4
- export type BuildConfigNode = {
5
- type: "node";
6
- runtime?: "dynamic" | "static"; // defaults to dynamic
7
- buildCommand?: string;
8
- } & BuildConfigBase;
9
-
10
- export type BuildConfig = BuildConfigNode;
11
-
12
- export const isOfType = <T extends BuildConfig["type"]>(
13
- t: BuildConfig,
14
- type: T
15
- ): t is Extract<BuildConfig, { type: T }> => {
16
- return t.type === type;
17
- };
@@ -1,176 +0,0 @@
1
- import { merge } from "lodash";
2
- import slugify from "slugify";
3
- import { GitlabJobDef, GitlabJobs } from "../types/gitlab-types";
4
-
5
- import { Config, DefaultEnvConfig } from "../types/config";
6
- import { CommitInfo, Context, Environment } from "../types/context";
7
- import { deployJobCreators, getDeployDefaults } from "../deploy";
8
- import { buildJobCreators, getBuildDefaults } from "../build";
9
- import { BuildConfig } from "../build/types";
10
- import { DeployConfig } from "../deploy/types";
11
-
12
- const createRawJobs = (context: Context): GitlabJobs => {
13
- const buildJobs =
14
- buildJobCreators[context.componentConfig.build.type](context);
15
- const deployJobs =
16
- deployJobCreators[context.componentConfig.deploy.type](context);
17
-
18
- return [...buildJobs, ...deployJobs];
19
- };
20
-
21
- const getEnvironment = (
22
- config: Config,
23
- componentName: string,
24
- env: string,
25
- commitInfo: CommitInfo
26
- ): Environment => {
27
- const componentConfig = config.components[componentName];
28
- if (!componentConfig) {
29
- throw new Error("unknown component " + componentName);
30
- }
31
-
32
- const defaultConfig = componentConfig;
33
- const envConfig = componentConfig.env?.[env] ?? {};
34
-
35
- const mergedConfig = merge({}, defaultConfig, envConfig);
36
-
37
- const publicEnvVars = mergedConfig.vars?.public ?? {};
38
- const secretEnvVarsRaw = mergedConfig.vars?.secret ?? {}; // TODO, map to gl secrets?
39
- const secretEnvVars = {}; // TODO
40
- const referencedRaw = mergedConfig.vars?.fromComponents ?? {};
41
-
42
- const referenced = Object.entries(referencedRaw).reduce(
43
- (acc, [otherApp, mapping]) => {
44
- // TODO: prevent infinit looop
45
- const { variables } = getEnvironment(config, otherApp, env, commitInfo);
46
-
47
- return Object.fromEntries(
48
- Object.entries(mapping).map(([ourKey, otherKey]) => [
49
- ourKey,
50
- variables[otherKey],
51
- ])
52
- );
53
- },
54
- {}
55
- );
56
-
57
- const envType = componentConfig.env?.[env]?.type ?? env;
58
- const environmentName =
59
- envType === "review"
60
- ? `${env}-${componentName}/${commitInfo.refName}`
61
- : `${env}-${componentName}`;
62
-
63
- const KUBE_APP_NAME =
64
- envType === "review"
65
- ? `${componentName}-${commitInfo.refSlug}`
66
- : componentName;
67
-
68
- const KUBE_NAMESPACE = `${config.customerName}-${config.appName}-${env}`;
69
-
70
- const APP_SLUG = slugify(KUBE_APP_NAME);
71
-
72
- const HOST_CANONICAL = `${config.appName}-${APP_SLUG}.${config.customerName}.panter.cloud`;
73
-
74
- const hostname = mergedConfig.hostname ?? HOST_CANONICAL;
75
- const url = `https://${hostname}`;
76
-
77
- const predefinedVariables = {
78
- HOST_CANONICAL,
79
- ROOT_URL: url,
80
- KUBE_NAMESPACE,
81
- KUBE_APP_NAME,
82
- ENV_SHORT: env,
83
- };
84
- const variables = {
85
- ...predefinedVariables,
86
- ...publicEnvVars,
87
- ...secretEnvVars,
88
- ...referenced,
89
- };
90
-
91
- return {
92
- hostname,
93
- fullName: environmentName,
94
- shortName: env,
95
- url: url,
96
- variables,
97
- };
98
- };
99
-
100
- export const createContext = (
101
- componentName: string,
102
- config: Config,
103
- env: string
104
- ): Context => {
105
- const rawConfig = config.components[componentName];
106
- if (!rawConfig) {
107
- throw new Error("unknown component " + componentName);
108
- }
109
- // envs can override the config
110
- const envConfig = rawConfig.env?.[env] ?? {};
111
- const componentConfigWithoutDefaults = merge({}, rawConfig, envConfig);
112
- // fill in defaults of build and deploy
113
- const defaults: {
114
- build: Partial<BuildConfig>;
115
- deploy: Partial<DeployConfig>;
116
- } = {
117
- build: getBuildDefaults[componentConfigWithoutDefaults.build.type](),
118
- deploy: getDeployDefaults[componentConfigWithoutDefaults.deploy.type](),
119
- };
120
- const componentConfig = merge({}, componentConfigWithoutDefaults, defaults);
121
- const commit = {
122
- refName: process.env.CI_COMMIT_REF_NAME ?? "unknown",
123
- refSlug: process.env.CI_COMMIT_REF_SLUG ?? "unknown",
124
- };
125
- return {
126
- fullConfig: config,
127
- componentConfig,
128
- componentName,
129
- environment: getEnvironment(config, componentName, env, commit),
130
- commit: commit,
131
- };
132
- };
133
-
134
- const getFullJobName = (name: string, componentName: string, env?: string) => {
135
- if (env) {
136
- return `${env} ${componentName} ${name}`;
137
- }
138
- return `${componentName} ${name}`;
139
- };
140
-
141
- const replaceReferences = (
142
- def: GitlabJobDef,
143
- componentName: string,
144
- env?: string
145
- ): GitlabJobDef => {
146
- return {
147
- ...def,
148
- needs: def.needs?.map((n) => getFullJobName(n, componentName, env)),
149
- dependencies: def.dependencies?.map((n) =>
150
- getFullJobName(n, componentName, env)
151
- ),
152
- };
153
- };
154
-
155
- export const createJobs = (
156
- envs: string[],
157
- config: Config,
158
- componentName: string
159
- ): Record<string, GitlabJobDef> => {
160
- return envs.reduce((acc, env) => {
161
- const context = createContext(componentName, config, env);
162
- const jobs = createRawJobs(context);
163
- return {
164
- ...acc,
165
- ...jobs.reduce((acc, { name, job, perEnv = true }) => {
166
- const def = job;
167
-
168
- return {
169
- ...acc,
170
- [getFullJobName(name, componentName, perEnv ? env : undefined)]:
171
- replaceReferences(def, componentName, perEnv ? env : undefined),
172
- };
173
- }, {}),
174
- };
175
- }, {});
176
- };
@@ -1,52 +0,0 @@
1
- import { createJobs } from "./createChildPipeline";
2
- import { Config, ENV_TYPES, PipelineTrigger } from "./types/config";
3
- import { GitlabJobDef } from "./types/gitlab-types";
4
-
5
- export const createPipeline = async (
6
- trigger: PipelineTrigger,
7
- config: Config
8
- ) => {
9
- const envs = Object.keys(ENV_TYPES).filter(
10
- (e) => ENV_TYPES[e as keyof typeof ENV_TYPES].trigger === trigger
11
- );
12
- const components = Object.keys(config.components);
13
-
14
- // 2. write the triggering pipeline
15
-
16
- const jobs = components.reduce<Record<string, GitlabJobDef>>(
17
- (acc, componentName) => {
18
- return {
19
- ...acc,
20
- ...createJobs(envs, config, componentName),
21
- };
22
- },
23
- {}
24
- );
25
-
26
- const rules = [
27
- // same as rules "always", but with `changes` to only trigger changed branches
28
- { if: "$CI_COMMIT_TAG" },
29
- {
30
- if: "$CI_COMMIT_MESSAGE =~ /^chore(release).*/",
31
- when: "never",
32
- },
33
- { if: "$CI_COMMIT_BRANCH =~ /^[0-9]+.([0-9]+|x).x$/" },
34
- {
35
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH",
36
- },
37
-
38
- { if: "$CI_MERGE_REQUEST_ID" },
39
- ];
40
-
41
- const mainPipeline = {
42
- image:
43
- "git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG",
44
- workflow: {
45
- rules,
46
- },
47
- stages: ["setup", "test", "build", "deploy", "verify", "actions"],
48
- ...jobs,
49
- };
50
-
51
- return mainPipeline;
52
- };
@@ -1,19 +0,0 @@
1
- import { GitlabJobs } from "../types/gitlab-types";
2
- import { ComponentConfig } from "../types/config";
3
- import { Context } from "../types/context";
4
- import { createKubernetesDeployJobs, getKubernetesDefault } from "./kubernetes";
5
- import { DeployConfig } from "./types";
6
-
7
- export const deployJobCreators: {
8
- [type in DeployConfig["type"]]: (context: Context) => GitlabJobs;
9
- } = {
10
- kubernetes: createKubernetesDeployJobs,
11
- serverless: () => [],
12
- };
13
-
14
- export const getDeployDefaults: {
15
- [type in DeployConfig["type"]]: () => Partial<DeployConfig>;
16
- } = {
17
- kubernetes: getKubernetesDefault,
18
- serverless: () => ({}),
19
- };