@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.
- package/babel-inline.json +11 -0
- package/bin/catladder-gitlab.js +3 -0
- package/dist/build/base/constants.d.ts +7 -0
- package/dist/build/base/constants.js +11 -0
- package/dist/build/base/createBuildJob.d.ts +5 -0
- package/dist/build/base/createBuildJob.js +99 -0
- package/dist/build/docker.d.ts +5 -0
- package/dist/build/docker.js +95 -0
- package/dist/build/index.d.ts +12 -0
- package/dist/build/index.js +63 -0
- package/dist/build/node/buildJob.d.ts +3 -0
- package/dist/build/node/buildJob.js +97 -0
- package/dist/build/node/cache.d.ts +4 -0
- package/dist/build/node/cache.js +67 -0
- package/dist/build/node/constants.d.ts +6 -0
- package/dist/build/node/constants.js +10 -0
- package/dist/build/node/index.d.ts +5 -0
- package/dist/build/node/index.js +63 -0
- package/dist/build/node/meteor.d.ts +3 -0
- package/dist/build/node/meteor.js +103 -0
- package/dist/build/node/testJob.d.ts +3 -0
- package/dist/build/node/testJob.js +112 -0
- package/dist/build/node/yarn.d.ts +2 -0
- package/dist/build/node/yarn.js +12 -0
- package/dist/build/tests/storybook.test.d.ts +1 -0
- package/dist/build/tests/storybook.test.js +221 -0
- package/dist/build/types.d.ts +63 -0
- package/dist/build/types.js +16 -0
- package/dist/catladder-gitlab.d.ts +1 -0
- package/dist/catladder-gitlab.js +44 -0
- package/dist/config/configruedEnvs.d.ts +4 -0
- package/dist/config/configruedEnvs.js +86 -0
- package/dist/config/configruedEnvs.test.d.ts +1 -0
- package/dist/config/configruedEnvs.test.js +103 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +24 -0
- package/dist/config/readConfig.d.ts +2 -0
- package/dist/config/readConfig.js +47 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +6 -0
- package/dist/context/index.d.ts +5 -0
- package/dist/context/index.js +211 -0
- package/dist/defaults/index.d.ts +2 -0
- package/dist/defaults/index.js +8 -0
- package/dist/deploy/base.d.ts +9 -0
- package/dist/deploy/base.js +94 -0
- package/dist/deploy/index.d.ts +11 -0
- package/dist/deploy/index.js +34 -0
- package/dist/deploy/kubernetes/cloudsql.d.ts +6 -0
- package/dist/deploy/kubernetes/cloudsql.js +16 -0
- package/dist/deploy/kubernetes/deployJob.d.ts +3 -0
- package/dist/deploy/kubernetes/deployJob.js +148 -0
- package/dist/deploy/kubernetes/index.d.ts +1 -0
- package/dist/deploy/kubernetes/index.js +22 -0
- package/dist/deploy/kubernetes/mongodb.d.ts +15 -0
- package/dist/deploy/kubernetes/mongodb.js +23 -0
- package/dist/deploy/types.d.ts +92 -0
- package/dist/deploy/types.js +16 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +36 -0
- package/dist/pipeline/createChildPipeline.d.ts +9 -0
- package/dist/pipeline/createChildPipeline.js +266 -0
- package/dist/pipeline/createChildPipeline.test.d.ts +1 -0
- package/dist/pipeline/createChildPipeline.test.js +199 -0
- package/dist/pipeline/createJobs.d.ts +3 -0
- package/dist/pipeline/createJobs.js +331 -0
- package/dist/pipeline/index.d.ts +2 -0
- package/dist/pipeline/index.js +24 -0
- package/dist/pipeline/yarnInfo.d.ts +2 -0
- package/dist/pipeline/yarnInfo.js +296 -0
- package/dist/rules/index.d.ts +3 -0
- package/dist/rules/index.js +27 -0
- package/dist/runner/index.d.ts +3 -0
- package/dist/runner/index.js +12 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/config.d.ts +73 -0
- package/dist/types/config.js +80 -0
- package/dist/types/context.d.ts +36 -0
- package/dist/types/context.js +3 -0
- package/dist/types/gitlab-types.d.ts +86 -0
- package/dist/types/gitlab-types.js +5 -0
- package/dist/{scripts/magic/types โ types}/index.d.ts +1 -1
- package/dist/types/index.js +26 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +18 -0
- package/package.json +30 -9
- package/src/build/base/constants.ts +7 -0
- package/src/build/base/createBuildJob.ts +46 -0
- package/{scripts/magic โ src}/build/docker.ts +15 -2
- package/src/build/index.ts +42 -0
- package/src/build/node/buildJob.ts +54 -0
- package/src/build/node/cache.ts +36 -0
- package/src/build/node/constants.ts +6 -0
- package/src/build/node/index.ts +17 -0
- package/src/build/node/meteor.ts +75 -0
- package/src/build/node/testJob.ts +80 -0
- package/src/build/node/yarn.ts +8 -0
- package/src/build/tests/storybook.test.ts +46 -0
- package/src/build/types.ts +75 -0
- package/src/catladder-gitlab.ts +52 -0
- package/src/config/configruedEnvs.test.ts +97 -0
- package/src/config/configruedEnvs.ts +56 -0
- package/src/config/index.ts +2 -0
- package/src/config/readConfig.ts +36 -0
- package/src/constants.ts +2 -0
- package/src/context/index.ts +194 -0
- package/src/defaults/index.ts +6 -0
- package/src/deploy/base.ts +101 -0
- package/src/deploy/index.ts +19 -0
- package/src/deploy/kubernetes/cloudsql.ts +13 -0
- package/src/deploy/kubernetes/deployJob.ts +116 -0
- package/src/deploy/kubernetes/index.ts +1 -0
- package/src/deploy/kubernetes/mongodb.ts +20 -0
- package/src/deploy/types.ts +60 -0
- package/src/index.ts +8 -0
- package/{scripts/magic/tests/createPipeline.test.ts โ src/pipeline/createChildPipeline.test.ts} +5 -4
- package/src/pipeline/createChildPipeline.ts +51 -0
- package/src/pipeline/createJobs.ts +158 -0
- package/src/pipeline/index.ts +2 -0
- package/src/pipeline/yarnInfo.ts +54 -0
- package/src/rules/index.ts +37 -0
- package/src/runner/index.ts +10 -0
- package/src/types/config.ts +88 -0
- package/src/types/context.ts +36 -0
- package/src/types/gitlab-types.ts +94 -0
- package/{scripts/magic โ src}/types/index.ts +0 -0
- package/src/utils/index.ts +10 -0
- package/tsconfig.json +4 -2
- package/Dockerfile +0 -84
- package/dist/scripts/createSamplePipeline.d.ts +0 -2
- package/dist/scripts/createSamplePipeline.js +0 -14
- package/dist/scripts/magic/build/docker.d.ts +0 -2
- package/dist/scripts/magic/build/docker.js +0 -68
- package/dist/scripts/magic/build/index.d.ts +0 -9
- package/dist/scripts/magic/build/index.js +0 -12
- package/dist/scripts/magic/build/node.d.ts +0 -6
- package/dist/scripts/magic/build/node.js +0 -150
- package/dist/scripts/magic/build/types.d.ts +0 -18
- package/dist/scripts/magic/build/types.js +0 -7
- package/dist/scripts/magic/context/index.d.ts +0 -3
- package/dist/scripts/magic/context/index.js +0 -122
- package/dist/scripts/magic/createChildPipeline/index.d.ts +0 -3
- package/dist/scripts/magic/createChildPipeline/index.js +0 -68
- package/dist/scripts/magic/createPipeline.d.ts +0 -14
- package/dist/scripts/magic/createPipeline.js +0 -80
- package/dist/scripts/magic/deploy/index.d.ts +0 -9
- package/dist/scripts/magic/deploy/index.js +0 -12
- package/dist/scripts/magic/deploy/kubernetes.d.ts +0 -5
- package/dist/scripts/magic/deploy/kubernetes.js +0 -62
- package/dist/scripts/magic/deploy/types.d.ts +0 -41
- package/dist/scripts/magic/deploy/types.js +0 -7
- package/dist/scripts/magic/index.d.ts +0 -2
- package/dist/scripts/magic/index.js +0 -16
- package/dist/scripts/magic/sample-config.d.ts +0 -3
- package/dist/scripts/magic/sample-config.js +0 -77
- package/dist/scripts/magic/tests/createPipeline.test.d.ts +0 -1
- package/dist/scripts/magic/tests/createPipeline.test.js +0 -89
- package/dist/scripts/magic/types/config.d.ts +0 -49
- package/dist/scripts/magic/types/config.js +0 -17
- package/dist/scripts/magic/types/context.d.ts +0 -19
- package/dist/scripts/magic/types/context.js +0 -2
- package/dist/scripts/magic/types/gitlab-types.d.ts +0 -57
- package/dist/scripts/magic/types/gitlab-types.js +0 -2
- package/dist/scripts/magic/types/index.js +0 -15
- package/dist/scripts/magic.d.ts +0 -2
- package/dist/scripts/magic.js +0 -43
- package/dist/scripts/monorepoGenerate.d.ts +0 -2
- package/dist/scripts/monorepoGenerate.js +0 -164
- package/dist/scripts/printAllValues.d.ts +0 -2
- package/dist/scripts/printAllValues.js +0 -58
- package/dist/scripts/printBuildEnv.d.ts +0 -2
- package/dist/scripts/printBuildEnv.js +0 -77
- package/dist/scripts/utils/extractAllValues.d.ts +0 -1
- package/dist/scripts/utils/extractAllValues.js +0 -78
- package/dist/scripts/utils/extractBuildEnv.d.ts +0 -5
- package/dist/scripts/utils/extractBuildEnv.js +0 -152
- package/dist/scripts/utils/extractValuesFromEnvVars.d.ts +0 -2
- package/dist/scripts/utils/extractValuesFromEnvVars.js +0 -63
- package/dist/scripts/utils/extractValuesFromMr.d.ts +0 -2
- package/dist/scripts/utils/extractValuesFromMr.js +0 -86
- package/dist/tests/extractValuesFromMr.test.d.ts +0 -1
- package/dist/tests/extractValuesFromMr.test.js +0 -68
- package/scripts/createSamplePipeline.ts +0 -10
- package/scripts/getCommitInfo +0 -11
- package/scripts/kubernetesCreateSecret +0 -9
- package/scripts/kubernetesDelete +0 -4
- package/scripts/kubernetesDeploy +0 -55
- package/scripts/kubernetesEnsureNamespace +0 -3
- package/scripts/magic/build/index.ts +0 -18
- package/scripts/magic/build/node.ts +0 -143
- package/scripts/magic/build/types.ts +0 -21
- package/scripts/magic/context/index.ts +0 -127
- package/scripts/magic/createChildPipeline/index.ts +0 -60
- package/scripts/magic/createPipeline.ts +0 -52
- package/scripts/magic/deploy/index.ts +0 -19
- package/scripts/magic/deploy/kubernetes.ts +0 -65
- package/scripts/magic/deploy/types.ts +0 -29
- package/scripts/magic/index.ts +0 -2
- package/scripts/magic/sample-config.ts +0 -78
- package/scripts/magic/types/config.ts +0 -54
- package/scripts/magic/types/context.ts +0 -21
- package/scripts/magic/types/gitlab-types.ts +0 -69
- package/scripts/magic.ts +0 -51
- package/scripts/monorepoGenerate.ts +0 -104
- package/scripts/printAllValues.ts +0 -17
- package/scripts/printBuildEnv.ts +0 -22
- package/scripts/utils/extractAllValues.ts +0 -32
- package/scripts/utils/extractBuildEnv.ts +0 -94
- package/scripts/utils/extractValuesFromEnvVars.ts +0 -21
- package/scripts/utils/extractValuesFromMr.ts +0 -39
- package/tests/extractValuesFromMr.test.ts +0 -156
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export declare type Artifacts = {
|
|
2
|
+
paths: string[];
|
|
3
|
+
};
|
|
4
|
+
export declare type GitlabJobCache = {
|
|
5
|
+
key: string;
|
|
6
|
+
policy?: string;
|
|
7
|
+
paths: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare type GitlabRule = {
|
|
10
|
+
if?: string;
|
|
11
|
+
when?: "always" | "on_success" | "manual" | "never";
|
|
12
|
+
allow_failure?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare type Retry = {
|
|
15
|
+
max: number;
|
|
16
|
+
when: string[];
|
|
17
|
+
};
|
|
18
|
+
export declare type Service = {
|
|
19
|
+
name: string;
|
|
20
|
+
command: string[];
|
|
21
|
+
};
|
|
22
|
+
export declare type GitlabEnvironment = {
|
|
23
|
+
url: string;
|
|
24
|
+
name: string;
|
|
25
|
+
kubernetes?: {
|
|
26
|
+
namespace?: string;
|
|
27
|
+
};
|
|
28
|
+
action?: "stop" | "start" | "prepare";
|
|
29
|
+
on_stop?: string;
|
|
30
|
+
auto_stop_in?: string;
|
|
31
|
+
};
|
|
32
|
+
export declare type GitlabJobDef = {
|
|
33
|
+
stage: string;
|
|
34
|
+
before_script?: string[];
|
|
35
|
+
script: (string | undefined)[];
|
|
36
|
+
interruptible?: boolean;
|
|
37
|
+
needs?: Array<string | {
|
|
38
|
+
job: string;
|
|
39
|
+
artifacts: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
rules?: GitlabRule[];
|
|
42
|
+
cache?: GitlabJobCache | GitlabJobCache[];
|
|
43
|
+
artifacts?: Artifacts;
|
|
44
|
+
retry?: Retry;
|
|
45
|
+
services?: Service[];
|
|
46
|
+
image?: string;
|
|
47
|
+
variables?: GitlabVariables;
|
|
48
|
+
dependencies?: string[];
|
|
49
|
+
environment?: GitlabEnvironment;
|
|
50
|
+
allow_failure?: boolean;
|
|
51
|
+
trigger?: {
|
|
52
|
+
strategy: "depend";
|
|
53
|
+
include: Array<{
|
|
54
|
+
artifact: string;
|
|
55
|
+
job: string;
|
|
56
|
+
}>;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export declare const GITLAB_BASE_STAGES: readonly ["setup", "test", "build", "deploy", "verify", "stop"];
|
|
60
|
+
export declare type GitlabBaseStage = typeof GITLAB_BASE_STAGES[number];
|
|
61
|
+
export declare type GitlabVariables = Record<string, string | undefined>;
|
|
62
|
+
export declare type GitlabJob = {
|
|
63
|
+
/**
|
|
64
|
+
* the name of the job (without any env or app prefix and suffix)
|
|
65
|
+
*/
|
|
66
|
+
name: string;
|
|
67
|
+
/**
|
|
68
|
+
* envMode sets the behavior of the job regarding multiple envs:
|
|
69
|
+
* - none: the job does not run per env, but once for all envs
|
|
70
|
+
* - jobPerEnv: the job runs once per env
|
|
71
|
+
* - 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`
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
envMode: "jobPerEnv" | "stagePerEnv" | "none";
|
|
75
|
+
job: GitlabJobDef;
|
|
76
|
+
needsStages?: {
|
|
77
|
+
stage: GitlabBaseStage;
|
|
78
|
+
artifacts?: boolean;
|
|
79
|
+
}[];
|
|
80
|
+
};
|
|
81
|
+
export declare type GitlabJobs = GitlabJob[];
|
|
82
|
+
export declare type GitlabPipeline = {
|
|
83
|
+
variables: GitlabVariables;
|
|
84
|
+
stages: string[];
|
|
85
|
+
jobs: GitlabJobs;
|
|
86
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
Object.defineProperty(o, k2, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function () {
|
|
8
|
+
return m[k];
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
} : function (o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var __exportStar = this && this.__exportStar || function (m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.__esModule = true;
|
|
21
|
+
|
|
22
|
+
__exportStar(require("./config"), exports);
|
|
23
|
+
|
|
24
|
+
__exportStar(require("./gitlab-types"), exports);
|
|
25
|
+
|
|
26
|
+
__exportStar(require("./context"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.ensureArray = exports.notNil = void 0;
|
|
5
|
+
|
|
6
|
+
var lodash_1 = require("lodash");
|
|
7
|
+
|
|
8
|
+
function notNil(value) {
|
|
9
|
+
return value !== null && value !== undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.notNil = notNil;
|
|
13
|
+
|
|
14
|
+
var ensureArray = function (s) {
|
|
15
|
+
return (0, lodash_1.isNil)(s) ? null : Array.isArray(s) ? s : [s];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.ensureArray = ensureArray;
|
package/package.json
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catladder/pipeline",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"
|
|
5
|
+
"build:tsc": "yarn tsc",
|
|
6
|
+
"build": "yarn tsc && yarn build:inline-variables",
|
|
7
|
+
"build:watch": "yarn tsc -w",
|
|
8
|
+
"build:inline-variables": "yarn babel --keep-file-extension --extensions \".ts,.js\" --config-file ./babel-inline.json dist --out-dir dist",
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
11
|
+
"lint:fix": "eslint \"src/**/*.ts\" --fix"
|
|
12
|
+
},
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"bin": {
|
|
16
|
+
"catladder-gitlab": "./bin/catladder-gitlab.js"
|
|
6
17
|
},
|
|
7
|
-
"main": "dist/scripts/magic/index.js",
|
|
8
|
-
"types": "dist/scripts/magic/index.d.ts",
|
|
9
18
|
"devDependencies": {
|
|
19
|
+
"@babel/cli": "^7.16.0",
|
|
20
|
+
"@babel/core": "^7.0.0-0",
|
|
21
|
+
"@babel/plugin-syntax-typescript": "^7.16.7",
|
|
22
|
+
"@babel/preset-typescript": "^7.16.5",
|
|
23
|
+
"@types/child-process-promise": "^2.2.2",
|
|
24
|
+
"@types/jest": "^27.4.0",
|
|
10
25
|
"@types/lodash": "^4.14.172",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"typescript": "^4.5.4"
|
|
26
|
+
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
|
|
27
|
+
"eslint": "^8.7.0"
|
|
14
28
|
},
|
|
15
29
|
"dependencies": {
|
|
16
30
|
"@gitbeaker/node": "^32.1.2",
|
|
31
|
+
"@types/node": "^17.0.10",
|
|
32
|
+
"child-process-promise": "^2.2.1",
|
|
33
|
+
"js-yaml": "^4.1.0",
|
|
17
34
|
"lodash": "^4.17.21",
|
|
35
|
+
"memoizee": "^0.4.15",
|
|
36
|
+
"path-equal": "^1.1.3",
|
|
37
|
+
"prettier": "^2.5.1",
|
|
18
38
|
"slugify": "^1.6.3",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
39
|
+
"ts-node": "^10.4.0",
|
|
40
|
+
"type-fest": "^2.10.0",
|
|
41
|
+
"typescript": "^4.5.4"
|
|
21
42
|
}
|
|
22
43
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { merge } from "lodash";
|
|
2
|
+
import { Context, GitlabJob, GitlabJobDef } from "../..";
|
|
3
|
+
import { BASE_RETRY } from "../../defaults";
|
|
4
|
+
import { ensureArray } from "../../utils";
|
|
5
|
+
import {
|
|
6
|
+
APP_BUILD_JOB_NAME,
|
|
7
|
+
RUNNER_BUILD_RESOURCE_VARIABLES,
|
|
8
|
+
} from "./constants";
|
|
9
|
+
|
|
10
|
+
export const createBuildJob = (
|
|
11
|
+
context: Context,
|
|
12
|
+
{ script, ...def }: Partial<GitlabJobDef>
|
|
13
|
+
): GitlabJob => {
|
|
14
|
+
const buildInfo = [
|
|
15
|
+
". getCommitInfo", // TODO: inline
|
|
16
|
+
`echo '{"id":"'$BUILD_ID'","commit":"'$BUILD_COMMIT'","tag":"'$BUILD_TAG'","time":"'$BUILD_TIME'"}' > ${context.componentConfig.dir}/__build_info.json`,
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
name: APP_BUILD_JOB_NAME,
|
|
21
|
+
envMode: "jobPerEnv",
|
|
22
|
+
job: merge(
|
|
23
|
+
{
|
|
24
|
+
needs: [],
|
|
25
|
+
cache: [],
|
|
26
|
+
variables: {
|
|
27
|
+
...RUNNER_BUILD_RESOURCE_VARIABLES,
|
|
28
|
+
...context.environment.envVars,
|
|
29
|
+
...(context.componentConfig.build.extraVars ?? {}),
|
|
30
|
+
},
|
|
31
|
+
retry: BASE_RETRY,
|
|
32
|
+
interruptible: true,
|
|
33
|
+
stage: "build",
|
|
34
|
+
script: [
|
|
35
|
+
...buildInfo,
|
|
36
|
+
`cd ${context.componentConfig.dir}`,
|
|
37
|
+
...(ensureArray(script) ?? []),
|
|
38
|
+
],
|
|
39
|
+
artifacts: {
|
|
40
|
+
paths: [context.componentConfig.dir + "/__build_info.json"],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
def
|
|
44
|
+
),
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
import { getRunnerImage } from "../runner";
|
|
1
2
|
import { GitlabJobDef, Context } from "../types";
|
|
2
3
|
|
|
4
|
+
const DOCKER_RUNNER_BUILD_VARIABLES = {
|
|
5
|
+
KUBERNETES_CPU_REQUEST: "0.5",
|
|
6
|
+
KUBERNETES_CPU_LIMIT: "1",
|
|
7
|
+
KUBERNETES_MEMORY_REQUEST: "1Gi",
|
|
8
|
+
KUBERNETES_MEMORY_LIMIT: "2Gi",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const DOCKER_BUILD_JOB_NAME = "๐จ docker";
|
|
3
12
|
export const createDockerBuildJob = (
|
|
4
13
|
context: Context,
|
|
5
14
|
{ script }: Pick<GitlabJobDef, "script">
|
|
6
15
|
): GitlabJobDef => {
|
|
7
16
|
const base: Omit<GitlabJobDef, "script"> = {
|
|
8
17
|
stage: "build",
|
|
9
|
-
image:
|
|
10
|
-
"git.panter.ch:5001/catladder/gitlab-ci/docker-build:$PIPELINE_IMAGE_TAG",
|
|
18
|
+
image: getRunnerImage("docker-build"),
|
|
11
19
|
interruptible: true,
|
|
12
20
|
services: [
|
|
13
21
|
{
|
|
@@ -16,6 +24,11 @@ export const createDockerBuildJob = (
|
|
|
16
24
|
},
|
|
17
25
|
],
|
|
18
26
|
variables: {
|
|
27
|
+
...DOCKER_RUNNER_BUILD_VARIABLES,
|
|
28
|
+
DOCKERFILE_ADDITIONS:
|
|
29
|
+
context.componentConfig.build.docker?.additionsBegin?.join("\n"),
|
|
30
|
+
DOCKERFILE_ADDITIONS_END:
|
|
31
|
+
context.componentConfig.build.docker?.additionsEnd?.join("\n"),
|
|
19
32
|
APP_DIR: context.componentConfig.dir,
|
|
20
33
|
DOCKER_HOST: "tcp://0.0.0.0:2375",
|
|
21
34
|
DOCKER_TLS_CERTDIR: "",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Context } from "../types/context";
|
|
2
|
+
import { GitlabJobs } from "../types/gitlab-types";
|
|
3
|
+
import { createNodeJobs, createStorybookJobs, createMeteorJobs } from "./node";
|
|
4
|
+
|
|
5
|
+
import { BuildConfig } from "./types";
|
|
6
|
+
export * from "./types";
|
|
7
|
+
export * from "./node";
|
|
8
|
+
|
|
9
|
+
export type BuildTypes = {
|
|
10
|
+
[type in BuildConfig["type"]]: {
|
|
11
|
+
jobs: (context: Context) => GitlabJobs;
|
|
12
|
+
defaults: () => Partial<Extract<BuildConfig, { type: type }>>;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const BUILD_TYPES: BuildTypes = {
|
|
17
|
+
node: {
|
|
18
|
+
jobs: createNodeJobs,
|
|
19
|
+
defaults: () => ({
|
|
20
|
+
buildCommand: "yarn build",
|
|
21
|
+
startCommand: "yarn start",
|
|
22
|
+
}),
|
|
23
|
+
},
|
|
24
|
+
"node-static": {
|
|
25
|
+
jobs: createNodeJobs,
|
|
26
|
+
defaults: () => ({
|
|
27
|
+
buildCommand: "yarn build",
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
storybook: {
|
|
31
|
+
jobs: createStorybookJobs,
|
|
32
|
+
defaults: () => ({
|
|
33
|
+
buildCommand: ["yarn storybook", "mv ./storybook-out /dist"],
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
meteor: {
|
|
37
|
+
jobs: createMeteorJobs,
|
|
38
|
+
defaults: () => ({
|
|
39
|
+
startCommand: "node main.js",
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Context } from "../../types/context";
|
|
2
|
+
import { GitlabJob, GitlabJobs } from "../../types/gitlab-types";
|
|
3
|
+
import { ensureArray } from "../../utils";
|
|
4
|
+
import { APP_BUILD_JOB_NAME } from "../base/constants";
|
|
5
|
+
import { createBuildJob } from "../base/createBuildJob";
|
|
6
|
+
import { createDockerBuildJob, DOCKER_BUILD_JOB_NAME } from "../docker";
|
|
7
|
+
import { isOfBuildType } from "../types";
|
|
8
|
+
import { getNextCache, getNodeCache } from "./cache";
|
|
9
|
+
import { getYarnInstall } from "./yarn";
|
|
10
|
+
|
|
11
|
+
export const createNodeBuildJobs = (context: Context): GitlabJobs => {
|
|
12
|
+
const buildConfig = context.componentConfig.build;
|
|
13
|
+
|
|
14
|
+
if (!isOfBuildType(buildConfig, "node", "node-static", "storybook")) {
|
|
15
|
+
throw new Error("deploy config is not node, node-static or storybook");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const yarnInstall = getYarnInstall(context);
|
|
19
|
+
const appBuildJob: GitlabJob | null =
|
|
20
|
+
buildConfig.buildCommand !== null
|
|
21
|
+
? createBuildJob(context, {
|
|
22
|
+
cache: [...getNodeCache(context), ...getNextCache(context)],
|
|
23
|
+
script: [
|
|
24
|
+
...yarnInstall,
|
|
25
|
+
...(ensureArray(buildConfig.buildCommand) ?? []),
|
|
26
|
+
],
|
|
27
|
+
artifacts: {
|
|
28
|
+
paths: [
|
|
29
|
+
context.componentConfig.dir + "/__build_info.json",
|
|
30
|
+
context.componentConfig.dir + "/dist",
|
|
31
|
+
context.componentConfig.dir + "/.next",
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
: null;
|
|
36
|
+
return [
|
|
37
|
+
...(appBuildJob ? [appBuildJob] : []),
|
|
38
|
+
{
|
|
39
|
+
name: DOCKER_BUILD_JOB_NAME,
|
|
40
|
+
envMode: "jobPerEnv",
|
|
41
|
+
job: {
|
|
42
|
+
...createDockerBuildJob(context, {
|
|
43
|
+
script: [
|
|
44
|
+
buildConfig.type === "node-static" ||
|
|
45
|
+
buildConfig.type === "storybook"
|
|
46
|
+
? "ensureNginxDockerfile"
|
|
47
|
+
: "ensureNodeDockerfile",
|
|
48
|
+
],
|
|
49
|
+
}),
|
|
50
|
+
needs: appBuildJob ? [APP_BUILD_JOB_NAME] : [],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { Context } from "../../types/context";
|
|
3
|
+
import { GitlabJobCache } from "../../types/gitlab-types";
|
|
4
|
+
|
|
5
|
+
export const getNodeCache = (context: Context): GitlabJobCache[] => {
|
|
6
|
+
const componentIsInWorkspace = context.yarnInfo?.componentIsInWorkspace;
|
|
7
|
+
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
// if component is in a shared workspace, use workspace cache. use individual cache else
|
|
11
|
+
key: componentIsInWorkspace
|
|
12
|
+
? "node-modules-workspace"
|
|
13
|
+
: context.componentName + "-node-modules",
|
|
14
|
+
policy: "pull-push",
|
|
15
|
+
paths: [
|
|
16
|
+
".yarn",
|
|
17
|
+
...(componentIsInWorkspace
|
|
18
|
+
? [
|
|
19
|
+
"node_modules",
|
|
20
|
+
...(context.yarnInfo?.workspaces.map((w) =>
|
|
21
|
+
join(w.location, "node_modules")
|
|
22
|
+
) ?? []),
|
|
23
|
+
]
|
|
24
|
+
: [join(context.componentConfig.dir, "node_modules")]),
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const getNextCache = (context: Context): GitlabJobCache[] => [
|
|
31
|
+
{
|
|
32
|
+
key: context.componentName + "-next-cache",
|
|
33
|
+
policy: "pull-push",
|
|
34
|
+
paths: [context.componentConfig.dir + "/.next/cache/"],
|
|
35
|
+
},
|
|
36
|
+
];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Context } from "../../types/context";
|
|
2
|
+
import type { GitlabJobs } from "../../types/gitlab-types";
|
|
3
|
+
import { createNodeBuildJobs } from "./buildJob";
|
|
4
|
+
import { createMeteorBuildJobs } from "./meteor";
|
|
5
|
+
import { createNodeTestJobs } from "./testJob";
|
|
6
|
+
|
|
7
|
+
export const createNodeJobs = (context: Context): GitlabJobs => {
|
|
8
|
+
return [...createNodeTestJobs(context), ...createNodeBuildJobs(context)];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const createStorybookJobs = (context: Context): GitlabJobs => {
|
|
12
|
+
return [...createNodeBuildJobs(context)];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const createMeteorJobs = (context: Context): GitlabJobs => {
|
|
16
|
+
return [...createNodeTestJobs(context), ...createMeteorBuildJobs(context)];
|
|
17
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import type { Context } from "../../types/context";
|
|
3
|
+
import type {
|
|
4
|
+
GitlabJob,
|
|
5
|
+
GitlabJobCache,
|
|
6
|
+
GitlabJobs,
|
|
7
|
+
} from "../../types/gitlab-types";
|
|
8
|
+
|
|
9
|
+
import { APP_BUILD_JOB_NAME } from "../base/constants";
|
|
10
|
+
import { createBuildJob } from "../base/createBuildJob";
|
|
11
|
+
import { createDockerBuildJob, DOCKER_BUILD_JOB_NAME } from "../docker";
|
|
12
|
+
import { isOfBuildType } from "../types";
|
|
13
|
+
import { getNodeCache } from "./cache";
|
|
14
|
+
import { getYarnInstall } from "./yarn";
|
|
15
|
+
|
|
16
|
+
const getMeteorCache = (context: Context): GitlabJobCache[] => [
|
|
17
|
+
{
|
|
18
|
+
key: context.componentName + "meteor-build-cache",
|
|
19
|
+
policy: "pull-push",
|
|
20
|
+
paths: [
|
|
21
|
+
join(
|
|
22
|
+
context.componentConfig.dir,
|
|
23
|
+
".meteor/local/resolver-result-cache.json"
|
|
24
|
+
),
|
|
25
|
+
join(context.componentConfig.dir, ".meteor/local/plugin-cache"),
|
|
26
|
+
join(context.componentConfig.dir, ".meteor/local/isopacks"),
|
|
27
|
+
join(context.componentConfig.dir, ".meteor/local/bundler-cache/scanner"),
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
export const createMeteorBuildJobs = (context: Context): GitlabJobs => {
|
|
32
|
+
const buildConfig = context.componentConfig.build;
|
|
33
|
+
|
|
34
|
+
if (!isOfBuildType(buildConfig, "meteor")) {
|
|
35
|
+
throw new Error("deploy config is not meteor");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const yarnInstall = getYarnInstall(context);
|
|
39
|
+
const appBuildJob: GitlabJob | null =
|
|
40
|
+
buildConfig.buildCommand !== null
|
|
41
|
+
? createBuildJob(context, {
|
|
42
|
+
cache: [...getNodeCache(context), ...getMeteorCache(context)],
|
|
43
|
+
script: [
|
|
44
|
+
...yarnInstall,
|
|
45
|
+
|
|
46
|
+
'echo "add healthcheck package"',
|
|
47
|
+
"meteor add panter:healthroute --allow-superuser",
|
|
48
|
+
"meteor add qualia:prod-shell --allow-superuser",
|
|
49
|
+
|
|
50
|
+
'TOOL_NODE_FLAGS="--max_old_space_size=3584 --min_semi_space_size=8 --max_semi_space_size=256 --optimize_for_size" meteor build ./dist --architecture os.linux.x86_64 --allow-superuser --server-only --directory',
|
|
51
|
+
|
|
52
|
+
"cp ./__build_info.json ./dist/bundle/programs/server",
|
|
53
|
+
],
|
|
54
|
+
artifacts: {
|
|
55
|
+
paths: [
|
|
56
|
+
context.componentConfig.dir + "/__build_info.json",
|
|
57
|
+
context.componentConfig.dir + "/dist",
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
: null;
|
|
62
|
+
return [
|
|
63
|
+
...(appBuildJob ? [appBuildJob] : []),
|
|
64
|
+
{
|
|
65
|
+
name: DOCKER_BUILD_JOB_NAME,
|
|
66
|
+
envMode: "jobPerEnv",
|
|
67
|
+
job: {
|
|
68
|
+
...createDockerBuildJob(context, {
|
|
69
|
+
script: ["ensureMeteorDockerfile"],
|
|
70
|
+
}),
|
|
71
|
+
needs: appBuildJob ? [APP_BUILD_JOB_NAME] : [],
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { BASE_RETRY } from "../../defaults";
|
|
2
|
+
import { Context } from "../../types/context";
|
|
3
|
+
import { GitlabJob, GitlabJobDef, GitlabJobs } from "../../types/gitlab-types";
|
|
4
|
+
import { ensureArray, notNil } from "../../utils";
|
|
5
|
+
import { getNodeCache } from "./cache";
|
|
6
|
+
import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
|
|
7
|
+
import { getYarnInstall } from "./yarn";
|
|
8
|
+
|
|
9
|
+
export const createNodeTestJobs = (context: Context): GitlabJobs => {
|
|
10
|
+
// don't run tests after release
|
|
11
|
+
if (context.commitInfo?.trigger === "taggedRelease") {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const buildConfig = context.componentConfig.build;
|
|
16
|
+
|
|
17
|
+
const base: Omit<GitlabJobDef, "script"> = {
|
|
18
|
+
variables: {
|
|
19
|
+
APP_PATH: context.componentConfig.dir,
|
|
20
|
+
...NODE_RUNNER_BUILD_VARIABLES,
|
|
21
|
+
...(buildConfig.extraVars ?? {}),
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
stage: "test",
|
|
25
|
+
interruptible: true,
|
|
26
|
+
needs: [],
|
|
27
|
+
retry: BASE_RETRY,
|
|
28
|
+
};
|
|
29
|
+
const yarnInstall = getYarnInstall(context);
|
|
30
|
+
const auditJob: GitlabJob | null =
|
|
31
|
+
buildConfig.audit !== false
|
|
32
|
+
? {
|
|
33
|
+
name: "๐ก audit",
|
|
34
|
+
envMode: "none",
|
|
35
|
+
job: {
|
|
36
|
+
...base,
|
|
37
|
+
cache: undefined, // audit does not need yarn install and no cache
|
|
38
|
+
script: [
|
|
39
|
+
`cd ${context.componentConfig.dir}`,
|
|
40
|
+
...(ensureArray(buildConfig.audit?.command) ?? ["yarn audit"]),
|
|
41
|
+
],
|
|
42
|
+
allow_failure: true,
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
: null;
|
|
46
|
+
|
|
47
|
+
const lintJob: GitlabJob | null =
|
|
48
|
+
buildConfig.lint !== false
|
|
49
|
+
? {
|
|
50
|
+
name: "๐ฎ lint",
|
|
51
|
+
envMode: "none",
|
|
52
|
+
job: {
|
|
53
|
+
...base,
|
|
54
|
+
cache: getNodeCache(context),
|
|
55
|
+
script: [
|
|
56
|
+
`cd ${context.componentConfig.dir}`,
|
|
57
|
+
...yarnInstall,
|
|
58
|
+
...(ensureArray(buildConfig.lint?.command) ?? ["yarn lint"]),
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
: null;
|
|
63
|
+
const testJob: GitlabJob | null =
|
|
64
|
+
buildConfig.test !== false
|
|
65
|
+
? {
|
|
66
|
+
name: "๐งช test",
|
|
67
|
+
envMode: "none",
|
|
68
|
+
job: {
|
|
69
|
+
...base,
|
|
70
|
+
cache: getNodeCache(context),
|
|
71
|
+
script: [
|
|
72
|
+
`cd ${context.componentConfig.dir}`,
|
|
73
|
+
...yarnInstall,
|
|
74
|
+
...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
: null;
|
|
79
|
+
return [auditJob, lintJob, testJob].filter(notNil);
|
|
80
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Context } from "../../types";
|
|
2
|
+
|
|
3
|
+
export const getYarnInstall = (context: Context) => [
|
|
4
|
+
"if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi",
|
|
5
|
+
context.yarnInfo?.isClassic
|
|
6
|
+
? "yarn install --frozen-lockfile"
|
|
7
|
+
: "yarn install --immutable",
|
|
8
|
+
];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Config } from "../../types";
|
|
2
|
+
import { createChildPipeline } from "../../";
|
|
3
|
+
|
|
4
|
+
describe("storybook build", () => {
|
|
5
|
+
describe("creates two build jobs", () => {
|
|
6
|
+
const config: Config = {
|
|
7
|
+
appName: "test",
|
|
8
|
+
customerName: "pan",
|
|
9
|
+
components: {
|
|
10
|
+
"my-app": {
|
|
11
|
+
dir: "myapp",
|
|
12
|
+
build: {
|
|
13
|
+
type: "storybook",
|
|
14
|
+
},
|
|
15
|
+
deploy: {
|
|
16
|
+
type: "kubernetes",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
it("creates a pipeline for storybook that does not contain test stages", async () => {
|
|
23
|
+
const { image, stages, workflow, ...jobs } = await createChildPipeline(
|
|
24
|
+
"mainBranch",
|
|
25
|
+
config
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect(Object.keys(jobs)).toEqual([
|
|
29
|
+
"dev my-app app-build",
|
|
30
|
+
"dev my-app docker-build",
|
|
31
|
+
"dev my-app deploy-to-kubernetes",
|
|
32
|
+
"dev my-app kubernetes-stop",
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("runs build and renames folder", async () => {
|
|
37
|
+
const { image, stages, workflow, ...jobs } = await createChildPipeline(
|
|
38
|
+
"mainBranch",
|
|
39
|
+
config
|
|
40
|
+
);
|
|
41
|
+
const buildJob = jobs["dev my-app app-build"];
|
|
42
|
+
expect(buildJob.script).toContain("yarn storybook");
|
|
43
|
+
expect(buildJob.script).toContain("mv ./storybook-out /dist");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|