@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
@@ -0,0 +1,94 @@
1
+ export type Artifacts = {
2
+ paths: string[];
3
+ };
4
+ export type GitlabJobCache = {
5
+ key: string;
6
+ policy?: string;
7
+ paths: string[];
8
+ };
9
+ export type GitlabRule = {
10
+ if?: string;
11
+ when?: "always" | "on_success" | "manual" | "never"; // todo
12
+ allow_failure?: boolean;
13
+ };
14
+ export type Retry = {
15
+ max: number;
16
+ when: string[];
17
+ };
18
+
19
+ export type Service = {
20
+ name: string;
21
+ command: string[];
22
+ };
23
+
24
+ export type GitlabEnvironment = {
25
+ url: string;
26
+ name: string;
27
+ kubernetes?: {
28
+ namespace?: string;
29
+ };
30
+ action?: "stop" | "start" | "prepare"; // defaults to start
31
+ on_stop?: string; // other job to run on stop
32
+ auto_stop_in?: string;
33
+ };
34
+ export type GitlabJobDef = {
35
+ stage: string;
36
+ before_script?: string[];
37
+ script: (string | undefined)[];
38
+ interruptible?: boolean;
39
+ needs?: Array<string | { job: string; artifacts: boolean }>;
40
+ rules?: GitlabRule[];
41
+ cache?: GitlabJobCache | GitlabJobCache[];
42
+ artifacts?: Artifacts;
43
+ retry?: Retry;
44
+ services?: Service[];
45
+ image?: string;
46
+ variables?: GitlabVariables;
47
+ dependencies?: string[];
48
+ environment?: GitlabEnvironment;
49
+ allow_failure?: boolean;
50
+ trigger?: {
51
+ strategy: "depend";
52
+ include: Array<{
53
+ artifact: string;
54
+ job: string;
55
+ }>;
56
+ };
57
+ };
58
+
59
+ export const GITLAB_BASE_STAGES = [
60
+ "setup",
61
+ "test",
62
+ "build",
63
+ "deploy",
64
+ "verify",
65
+ "stop",
66
+ ] as const;
67
+ export type GitlabBaseStage = typeof GITLAB_BASE_STAGES[number];
68
+ export type GitlabVariables = Record<string, string | undefined>;
69
+
70
+ export type GitlabJob = {
71
+ /**
72
+ * the name of the job (without any env or app prefix and suffix)
73
+ */
74
+ name: string;
75
+ /**
76
+ * envMode sets the behavior of the job regarding multiple envs:
77
+ * - none: the job does not run per env, but once for all envs
78
+ * - jobPerEnv: the job runs once per env
79
+ * - stagePerEnv: the job runs once per env and is organized in its own stage. This mproves usability in gitlab, but works the same as `jobPerEnv`
80
+ */
81
+ envMode: "jobPerEnv" | "stagePerEnv" | "none";
82
+ job: GitlabJobDef;
83
+ needsStages?: {
84
+ stage: GitlabBaseStage;
85
+ artifacts?: boolean;
86
+ }[];
87
+ };
88
+ export type GitlabJobs = GitlabJob[];
89
+
90
+ export type GitlabPipeline = {
91
+ variables: GitlabVariables;
92
+ stages: string[];
93
+ jobs: GitlabJobs;
94
+ };
File without changes
@@ -0,0 +1,10 @@
1
+ import { isNil } from "lodash";
2
+
3
+ export function notNil<TValue>(
4
+ value: TValue | null | undefined
5
+ ): value is TValue {
6
+ return value !== null && value !== undefined;
7
+ }
8
+
9
+ export const ensureArray = <T>(s: T | T[]): T[] | null =>
10
+ isNil(s) ? null : Array.isArray(s) ? s : [s];
package/tsconfig.json CHANGED
@@ -5,6 +5,8 @@
5
5
  "downlevelIteration": true,
6
6
  "declaration": true,
7
7
  "outDir": "dist",
8
- "esModuleInterop": true
9
- }
8
+ "esModuleInterop": true,
9
+ "incremental": true
10
+ },
11
+ "include": ["./src"]
10
12
  }
package/Dockerfile DELETED
@@ -1,84 +0,0 @@
1
-
2
- FROM node:14
3
-
4
- RUN rm /bin/sh && \
5
- ln -s /bin/bash /bin/sh && \
6
- mkdir -p /root/.nvm
7
-
8
- # add sources
9
- # Google Chrome (for testing purposes)
10
- RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
11
- sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
12
-
13
- # install some sources
14
- RUN apt-get update && apt-get install -y \
15
- git ssh-client \
16
- openssl \
17
- curl \
18
- bash \
19
- apt-transport-https \
20
- ca-certificates \
21
- git \
22
- gettext-base \
23
- libxss1 \
24
- google-chrome-stable
25
-
26
-
27
-
28
- # set high timeout for yarn, see https://github.com/dhis2/notes/issues/29
29
- RUN yarn config set network-timeout 600000 -g
30
-
31
- # add semantic release
32
- RUN yarn global add \
33
- semantic-release \
34
- @semantic-release/commit-analyzer \
35
- @semantic-release/release-notes-generator \
36
- @semantic-release/git \
37
- @semantic-release/changelog \
38
- @semantic-release/gitlab;
39
-
40
- # kubernetes & helm
41
- ENV KUBERNETES_VERSION 1.18.20
42
- RUN curl -L -o /usr/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl" ;\
43
- chmod +x /usr/bin/kubectl ;\
44
- kubectl version --client
45
-
46
- # helm 2 for legacy reasons
47
- ENV HELM_2_VERSION 2.14.3
48
- RUN curl "https://get.helm.sh/helm-v${HELM_2_VERSION}-linux-amd64.tar.gz" | tar zx ;\
49
- mv linux-amd64/helm /usr/bin/ ;\
50
- helm version --client
51
- RUN cp /usr/bin/helm /usr/bin/helm2
52
- # helm3
53
- ENV HELM_VERSION 3.6.3
54
- RUN curl "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar zx ;\
55
- mv linux-amd64/helm /usr/bin/helm3 ;\
56
- helm3 version --client
57
-
58
- # install nvm && some common node versions
59
- RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash && \
60
- source /root/.nvm/nvm.sh && \
61
- chmod +x /root/.nvm/nvm.sh && \
62
- /root/.nvm/nvm.sh install 10 && \
63
- /root/.nvm/nvm.sh install 12 && \
64
- /root/.nvm/nvm.sh install 14 && \
65
- /root/.nvm/nvm.sh install 16
66
-
67
- # add meteor (used by some apps)
68
- # install also additional used released (should theoretically speed up ci-builds)
69
- RUN curl https://install.meteor.com/ | sh && \
70
- meteor update --release 2.2 --allow-superuser
71
-
72
- # scripts
73
-
74
- RUN yarn global add ts-node typescript
75
-
76
- COPY ./scripts /scripts
77
- RUN chmod +x /scripts/*
78
-
79
- COPY package.json /scripts/
80
- COPY yarn.lock /scripts/
81
-
82
- WORKDIR /scripts
83
- RUN yarn
84
- ENV PATH="/scripts:${PATH}"
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- export {};
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- exports.__esModule = true;
7
- var fs_1 = require("fs");
8
- var createPipeline_1 = require("./magic/createPipeline");
9
- var sample_config_1 = __importDefault(require("./magic/sample-config"));
10
- createPipeline_1.createPipeline("taggedRelease", sample_config_1["default"]).then(function (mainPipeline) {
11
- fs_1.writeFileSync("__pipeline.yml", JSON.stringify(mainPipeline, null, 2), {
12
- encoding: "utf-8"
13
- });
14
- });
@@ -1,2 +0,0 @@
1
- import { GitlabJobDef, Context } from "../types";
2
- export declare const createDockerBuildJob: (context: Context, { script }: Pick<GitlabJobDef, "script">) => GitlabJobDef;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __read = (this && this.__read) || function (o, n) {
14
- var m = typeof Symbol === "function" && o[Symbol.iterator];
15
- if (!m) return o;
16
- var i = m.call(o), r, ar = [], e;
17
- try {
18
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
- }
20
- catch (error) { e = { error: error }; }
21
- finally {
22
- try {
23
- if (r && !r.done && (m = i["return"])) m.call(i);
24
- }
25
- finally { if (e) throw e.error; }
26
- }
27
- return ar;
28
- };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
30
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
31
- to[j] = from[i];
32
- return to;
33
- };
34
- exports.__esModule = true;
35
- exports.createDockerBuildJob = void 0;
36
- var createDockerBuildJob = function (context, _a) {
37
- var script = _a.script;
38
- var base = {
39
- stage: "build",
40
- image: "git.panter.ch:5001/catladder/gitlab-ci/docker-build:$PIPELINE_IMAGE_TAG",
41
- interruptible: true,
42
- services: [
43
- {
44
- name: "docker:20-dind",
45
- command: ["--tls=false"]
46
- },
47
- ],
48
- variables: {
49
- APP_DIR: context.componentConfig.dir,
50
- DOCKER_HOST: "tcp://0.0.0.0:2375",
51
- DOCKER_TLS_CERTDIR: "",
52
- DOCKER_DIR: ".",
53
- IMAGE_TAG: "$CI_COMMIT_SHA",
54
- DOCKER_DRIVER: "overlay2",
55
- IMAGE_NAME: "$CI_REGISTRY_IMAGE/" + context.componentName,
56
- CACHE_IMAGE: "$CI_REGISTRY_IMAGE/" + context.componentName + "/cache:cache"
57
- }
58
- };
59
- return __assign(__assign({}, base), { script: __spreadArray(__spreadArray([], __read(script)), [
60
- "docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY",
61
- "docker pull $CACHE_IMAGE || true",
62
- "docker build --network host --cache-from $CACHE_IMAGE --tag $IMAGE_NAME:$IMAGE_TAG -f $APP_DIR/Dockerfile .",
63
- "docker push $IMAGE_NAME:$IMAGE_TAG",
64
- "docker tag $IMAGE_NAME:$IMAGE_TAG $CACHE_IMAGE",
65
- "docker push $CACHE_IMAGE",
66
- ]) });
67
- };
68
- exports.createDockerBuildJob = createDockerBuildJob;
@@ -1,9 +0,0 @@
1
- import { GitlabJobs } from "../types/gitlab-types";
2
- import { Context } from "../types/context";
3
- import { BuildConfig } from "./types";
4
- export declare const buildJobCreators: {
5
- [type in BuildConfig["type"]]: (context: Context) => GitlabJobs;
6
- };
7
- export declare const getBuildDefaults: {
8
- [type in BuildConfig["type"]]: () => Partial<BuildConfig>;
9
- };
@@ -1,12 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.getBuildDefaults = exports.buildJobCreators = void 0;
4
- var node_1 = require("./node");
5
- exports.buildJobCreators = {
6
- node: node_1.createNodeJobs,
7
- "node-static": node_1.createNodeJobs
8
- };
9
- exports.getBuildDefaults = {
10
- node: node_1.getNodeDefaults,
11
- "node-static": node_1.getNodeStaticDefaults
12
- };
@@ -1,6 +0,0 @@
1
- import { GitlabJobs } from "../types/gitlab-types";
2
- import { Context } from "../types/context";
3
- import { BuildConfigNode, BuildConfigNodeStatic } from "./types";
4
- export declare const createNodeJobs: (context: Context) => GitlabJobs;
5
- export declare const getNodeDefaults: () => Partial<BuildConfigNode>;
6
- export declare const getNodeStaticDefaults: () => Partial<BuildConfigNodeStatic>;
@@ -1,150 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __read = (this && this.__read) || function (o, n) {
14
- var m = typeof Symbol === "function" && o[Symbol.iterator];
15
- if (!m) return o;
16
- var i = m.call(o), r, ar = [], e;
17
- try {
18
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
- }
20
- catch (error) { e = { error: error }; }
21
- finally {
22
- try {
23
- if (r && !r.done && (m = i["return"])) m.call(i);
24
- }
25
- finally { if (e) throw e.error; }
26
- }
27
- return ar;
28
- };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
30
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
31
- to[j] = from[i];
32
- return to;
33
- };
34
- exports.__esModule = true;
35
- exports.getNodeStaticDefaults = exports.getNodeDefaults = exports.createNodeJobs = void 0;
36
- var docker_1 = require("./docker");
37
- var types_1 = require("./types");
38
- var baseRetry = {
39
- max: 2,
40
- when: ["runner_system_failure", "stuck_or_timeout_failure"]
41
- };
42
- var getYarnInstall = function (context) { return [
43
- "cd " + context.componentConfig.dir,
44
- "if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi",
45
- "yarn install --frozen-lockfile",
46
- ]; };
47
- var getNodeCache = function (context) { return [
48
- {
49
- key: "node-modules",
50
- policy: "pull-push",
51
- paths: ["node_modules", "**/node_modules/"]
52
- },
53
- ]; };
54
- var getNextCache = function (context) { return [
55
- {
56
- key: "next-cache",
57
- policy: "pull-push",
58
- paths: [context.componentConfig.dir + "/.next/cache/"]
59
- },
60
- ]; };
61
- var createNodeTestJobs = function (context) {
62
- var base = {
63
- variables: {
64
- APP_PATH: context.componentConfig.dir
65
- },
66
- cache: getNodeCache(context),
67
- stage: "test",
68
- interruptible: true,
69
- needs: [],
70
- retry: baseRetry
71
- };
72
- var yarnInstall = getYarnInstall(context);
73
- return [
74
- {
75
- name: "audit",
76
- perEnv: false,
77
- job: __assign(__assign({}, base), { script: __spreadArray(__spreadArray([], __read(yarnInstall)), ["yarn audit"]), allow_failure: true })
78
- },
79
- {
80
- name: "lint",
81
- perEnv: false,
82
- job: __assign(__assign({}, base), { script: __spreadArray(__spreadArray([], __read(yarnInstall)), ["yarn lint"]) })
83
- },
84
- {
85
- name: "test",
86
- perEnv: false,
87
- job: __assign(__assign({}, base), { script: __spreadArray(__spreadArray([], __read(yarnInstall)), ["yarn test"]) })
88
- },
89
- ];
90
- };
91
- var createNodeBuildJobs = function (context) {
92
- var buildConfig = context.componentConfig.build;
93
- if (!types_1.isOfType(buildConfig, "node") && !types_1.isOfType(buildConfig, "node-static")) {
94
- // should not happen
95
- throw new Error("deploy config is not kubernetes");
96
- }
97
- var buildInfo = [
98
- ". getCommitInfo",
99
- "echo '{\"id\":\"'$BUILD_ID'\",\"commit\":\"'$BUILD_COMMIT'\",\"tag\":\"'$BUILD_TAG'\",\"time\":\"'$BUILD_TIME'\"}' > " + context.componentConfig.dir + "/__build_info.json",
100
- ];
101
- var yarnInstall = getYarnInstall(context);
102
- return [
103
- {
104
- name: "app-build",
105
- job: {
106
- needs: [],
107
- cache: __spreadArray(__spreadArray([], __read(getNodeCache(context))), __read(getNextCache(context))),
108
- variables: context.environment.variables,
109
- retry: baseRetry,
110
- interruptible: true,
111
- stage: "build",
112
- script: __spreadArray(__spreadArray(__spreadArray([], __read(buildInfo)), __read(yarnInstall)), [buildConfig.buildCommand]),
113
- artifacts: {
114
- paths: [
115
- context.componentConfig.dir + "/__build_info.json",
116
- context.componentConfig.dir + "/dist",
117
- context.componentConfig.dir + "/.next",
118
- ]
119
- }
120
- }
121
- },
122
- {
123
- name: "docker-build",
124
- job: __assign(__assign({}, docker_1.createDockerBuildJob(context, {
125
- script: [
126
- buildConfig.type === "node-static"
127
- ? "ensureNginxDockerfile"
128
- : "ensureNodeDockerfile",
129
- ]
130
- })), { needs: ["app-build"] })
131
- },
132
- ];
133
- };
134
- var createNodeJobs = function (context) {
135
- return __spreadArray(__spreadArray([], __read(createNodeTestJobs(context))), __read(createNodeBuildJobs(context)));
136
- };
137
- exports.createNodeJobs = createNodeJobs;
138
- var getNodeDefaults = function () {
139
- return {
140
- startCommand: "yarn start",
141
- buildCommand: "yarn build"
142
- };
143
- };
144
- exports.getNodeDefaults = getNodeDefaults;
145
- var getNodeStaticDefaults = function () {
146
- return {
147
- buildCommand: "yarn build"
148
- };
149
- };
150
- exports.getNodeStaticDefaults = getNodeStaticDefaults;
@@ -1,18 +0,0 @@
1
- export declare type BuildConfigBase = {
2
- startCommand?: string;
3
- };
4
- export declare type BuildConfigNode = {
5
- type: "node";
6
- buildCommand?: string;
7
- } & BuildConfigBase;
8
- export declare type BuildConfigNodeStatic = {
9
- type: "node-static";
10
- buildCommand?: string;
11
- startCommand: never;
12
- };
13
- export declare type BuildConfig = BuildConfigNode | BuildConfigNodeStatic;
14
- export declare const isOfType: <T extends "node" | "node-static">(t: BuildConfig, type: T) => t is Extract<BuildConfigNode, {
15
- type: T;
16
- }> | Extract<BuildConfigNodeStatic, {
17
- type: T;
18
- }>;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.isOfType = void 0;
4
- var isOfType = function (t, type) {
5
- return t.type === type;
6
- };
7
- exports.isOfType = isOfType;
@@ -1,3 +0,0 @@
1
- import { Config } from "../types/config";
2
- import { Context } from "../types/context";
3
- export declare const createContext: (componentName: string, config: Config, env: string) => Context;
@@ -1,122 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __read = (this && this.__read) || function (o, n) {
14
- var m = typeof Symbol === "function" && o[Symbol.iterator];
15
- if (!m) return o;
16
- var i = m.call(o), r, ar = [], e;
17
- try {
18
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
- }
20
- catch (error) { e = { error: error }; }
21
- finally {
22
- try {
23
- if (r && !r.done && (m = i["return"])) m.call(i);
24
- }
25
- finally { if (e) throw e.error; }
26
- }
27
- return ar;
28
- };
29
- var __importDefault = (this && this.__importDefault) || function (mod) {
30
- return (mod && mod.__esModule) ? mod : { "default": mod };
31
- };
32
- exports.__esModule = true;
33
- exports.createContext = void 0;
34
- var lodash_1 = require("lodash");
35
- var slugify_1 = __importDefault(require("slugify"));
36
- var build_1 = require("../build");
37
- var deploy_1 = require("../deploy");
38
- var getEnvironment = function (config, componentName, env, commitInfo) {
39
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
40
- var componentConfig = config.components[componentName];
41
- if (!componentConfig) {
42
- throw new Error("unknown component " + componentName);
43
- }
44
- var defaultConfig = componentConfig;
45
- var envConfig = (_b = (_a = componentConfig.env) === null || _a === void 0 ? void 0 : _a[env]) !== null && _b !== void 0 ? _b : {};
46
- var mergedConfig = lodash_1.merge({}, defaultConfig, envConfig);
47
- var publicEnvVars = (_d = (_c = mergedConfig.vars) === null || _c === void 0 ? void 0 : _c.public) !== null && _d !== void 0 ? _d : {};
48
- var secretEnvVarsRaw = (_f = (_e = mergedConfig.vars) === null || _e === void 0 ? void 0 : _e.secret) !== null && _f !== void 0 ? _f : {}; // TODO, map to gl secrets?
49
- var secretEnvVars = {}; // TODO
50
- var referencedRaw = (_h = (_g = mergedConfig.vars) === null || _g === void 0 ? void 0 : _g.fromComponents) !== null && _h !== void 0 ? _h : {};
51
- var referenced = Object.entries(referencedRaw).reduce(function (acc, _a) {
52
- var _b = __read(_a, 2), otherApp = _b[0], mapping = _b[1];
53
- // TODO: prevent infinit looop
54
- var variables = getEnvironment(config, otherApp, env, commitInfo).variables;
55
- return Object.fromEntries(Object.entries(mapping).map(function (_a) {
56
- var _b = __read(_a, 2), ourKey = _b[0], otherKey = _b[1];
57
- return [
58
- ourKey,
59
- variables[otherKey],
60
- ];
61
- }));
62
- }, {});
63
- var envType = (_l = (_k = (_j = componentConfig.env) === null || _j === void 0 ? void 0 : _j[env]) === null || _k === void 0 ? void 0 : _k.type) !== null && _l !== void 0 ? _l : env;
64
- var environmentName = envType === "review"
65
- ? env + "/" + componentName + "/" + commitInfo.refName
66
- : env + "/" + componentName;
67
- var KUBE_APP_NAME = envType === "review"
68
- ? componentName + "-" + commitInfo.refSlug
69
- : componentName;
70
- var KUBE_NAMESPACE = config.customerName + "-" + config.appName + "-" + env;
71
- var APP_SLUG = slugify_1["default"](KUBE_APP_NAME);
72
- var HOST_CANONICAL = config.appName + "-" + APP_SLUG + "." + config.customerName + ".panter.cloud";
73
- var hostname = (_m = mergedConfig.hostname) !== null && _m !== void 0 ? _m : HOST_CANONICAL;
74
- var url = "https://" + hostname;
75
- var predefinedVariables = {
76
- HOST_CANONICAL: HOST_CANONICAL,
77
- ROOT_URL: url,
78
- KUBE_NAMESPACE: KUBE_NAMESPACE,
79
- KUBE_APP_NAME: KUBE_APP_NAME,
80
- ENV_SHORT: env,
81
- APP_DIR: componentConfig.dir
82
- };
83
- var variables = __assign(__assign(__assign(__assign({}, predefinedVariables), publicEnvVars), secretEnvVars), referenced);
84
- return {
85
- hostname: hostname,
86
- fullName: environmentName,
87
- shortName: env,
88
- url: url,
89
- variables: variables
90
- };
91
- };
92
- var createContext = function (componentName, config, env) {
93
- var _a, _b, _c, _d;
94
- if (!/^[a-z0-9-]+$/.test(componentName)) {
95
- throw new Error("componentName may only contain lower case letters, numbers and -");
96
- }
97
- var rawConfig = config.components[componentName];
98
- if (!rawConfig) {
99
- throw new Error("unknown component " + componentName);
100
- }
101
- // envs can override the config
102
- var envConfig = (_b = (_a = rawConfig.env) === null || _a === void 0 ? void 0 : _a[env]) !== null && _b !== void 0 ? _b : {};
103
- var componentConfigWithoutDefaults = lodash_1.merge({}, rawConfig, envConfig);
104
- // fill in defaults of build and deploy
105
- var defaults = {
106
- build: build_1.getBuildDefaults[componentConfigWithoutDefaults.build.type](),
107
- deploy: deploy_1.getDeployDefaults[componentConfigWithoutDefaults.deploy.type]()
108
- };
109
- var componentConfig = lodash_1.merge({}, defaults, componentConfigWithoutDefaults);
110
- var commit = {
111
- refName: (_c = process.env.CI_COMMIT_REF_NAME) !== null && _c !== void 0 ? _c : "unknown",
112
- refSlug: (_d = process.env.CI_COMMIT_REF_SLUG) !== null && _d !== void 0 ? _d : "unknown"
113
- };
114
- return {
115
- fullConfig: config,
116
- componentConfig: componentConfig,
117
- componentName: componentName,
118
- environment: getEnvironment(config, componentName, env, commit),
119
- commit: commit
120
- };
121
- };
122
- exports.createContext = createContext;
@@ -1,3 +0,0 @@
1
- import { Config } from "../types/config";
2
- import { GitlabJobDef } from "../types/gitlab-types";
3
- export declare const createJobs: (envs: string[], config: Config, componentName: string) => Record<string, GitlabJobDef>;