@catladder/pipeline 1.12.0 → 1.13.0
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/dist/build/base/createBuildJob.d.ts +3 -2
- package/dist/build/base/createBuildJob.js +11 -17
- package/dist/build/docker.d.ts +3 -2
- package/dist/build/docker.js +24 -27
- package/dist/build/index.d.ts +2 -2
- package/dist/build/node/buildJob.d.ts +2 -2
- package/dist/build/node/index.d.ts +4 -4
- package/dist/build/node/meteor.d.ts +2 -2
- package/dist/build/node/testJob.d.ts +2 -2
- package/dist/build/node/testJob.js +20 -29
- package/dist/build/tests/storybook.test.js +10 -23
- package/dist/catladder-gitlab.js +33 -2
- package/dist/constants.js +1 -1
- package/dist/deploy/base.d.ts +3 -4
- package/dist/deploy/base.js +27 -33
- package/dist/deploy/index.d.ts +2 -2
- package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
- package/dist/deploy/kubernetes/deployJob.js +32 -38
- package/dist/pipeline/createChildPipeline.d.ts +2 -11
- package/dist/pipeline/createChildPipeline.js +24 -18
- package/dist/pipeline/createChildPipeline.test.js +3 -14
- package/dist/pipeline/createJobs.d.ts +2 -2
- package/dist/pipeline/createJobs.js +24 -18
- package/dist/pipeline/gitlab/makeGitlabJob.d.ts +8 -0
- package/dist/pipeline/gitlab/makeGitlabJob.js +45 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/gitlab-types.d.ts +10 -22
- package/dist/types/gitlab-types.js +1 -3
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +3 -1
- package/dist/types/jobs.d.ts +75 -0
- package/dist/types/jobs.js +5 -0
- package/dist/types/pipeline.d.ts +4 -0
- package/dist/types/pipeline.js +3 -0
- package/package.json +1 -1
- package/src/build/base/createBuildJob.ts +28 -32
- package/src/build/docker.ts +49 -51
- package/src/build/index.ts +3 -2
- package/src/build/node/buildJob.ts +3 -3
- package/src/build/node/index.ts +4 -4
- package/src/build/node/meteor.ts +5 -7
- package/src/build/node/testJob.ts +31 -40
- package/src/build/tests/storybook.test.ts +4 -2
- package/src/catladder-gitlab.ts +9 -5
- package/src/deploy/base.ts +40 -45
- package/src/deploy/index.ts +2 -2
- package/src/deploy/kubernetes/deployJob.ts +43 -48
- package/src/pipeline/createChildPipeline.test.ts +2 -1
- package/src/pipeline/createChildPipeline.ts +23 -21
- package/src/pipeline/createJobs.ts +47 -38
- package/src/pipeline/gitlab/makeGitlabJob.ts +16 -0
- package/src/types/gitlab-types.ts +10 -30
- package/src/types/index.ts +1 -0
- package/src/types/jobs.ts +88 -0
- package/src/types/pipeline.ts +11 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Artifacts, GitlabEnvironment, GitlabJobCache, GitlabRule, GitlabVariables, Service } from "./gitlab-types";
|
|
2
|
+
export declare const BASE_STAGES: readonly ["setup", "test", "build", "deploy", "verify", "stop"];
|
|
3
|
+
export declare type BaseStage = typeof BASE_STAGES[number];
|
|
4
|
+
export declare type CatladderJob<S = BaseStage> = {
|
|
5
|
+
/**
|
|
6
|
+
* the name of the job (without any env or app prefix and suffix)
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* envMode sets the behavior of the job regarding multiple envs:
|
|
11
|
+
* - none: the job does not run per env, but once for all envs
|
|
12
|
+
* - jobPerEnv: the job runs once per env
|
|
13
|
+
* - 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`
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
envMode: "jobPerEnv" | "stagePerEnv" | "none";
|
|
17
|
+
/**
|
|
18
|
+
* the stage of the job
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
stage: S;
|
|
22
|
+
/**
|
|
23
|
+
* does this require another stage?
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* script to run
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
script: (string | undefined)[];
|
|
31
|
+
needsStages?: {
|
|
32
|
+
stage: S;
|
|
33
|
+
artifacts?: boolean;
|
|
34
|
+
}[];
|
|
35
|
+
/**
|
|
36
|
+
* does this require another job?
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
needs?: Array<string | {
|
|
40
|
+
job: string;
|
|
41
|
+
artifacts: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* cache config, we use here the same shape as gitlab itself
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
cache?: GitlabJobCache | GitlabJobCache[];
|
|
48
|
+
/**
|
|
49
|
+
* job artifacts, we also use gitlab shape here
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
artifacts?: Artifacts;
|
|
53
|
+
/**
|
|
54
|
+
* additional services, mainly used for docker
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
services?: Service[];
|
|
58
|
+
/**
|
|
59
|
+
* image to use
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
image?: string;
|
|
63
|
+
/**
|
|
64
|
+
* variables to pass
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
variables: GitlabVariables;
|
|
68
|
+
/**
|
|
69
|
+
* whether failures are allowed
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
allow_failure?: boolean;
|
|
73
|
+
environment?: GitlabEnvironment;
|
|
74
|
+
rules?: GitlabRule[];
|
|
75
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GitlabJobDef, GitlabPipeline } from "./gitlab-types";
|
|
2
|
+
export declare type PipelineType = "gitlab";
|
|
3
|
+
export declare type PipelineJob<T extends PipelineType> = T extends "gitlab" ? GitlabJobDef : never;
|
|
4
|
+
export declare type Pipeline<T extends PipelineType> = T extends "gitlab" ? GitlabPipeline : never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { merge } from "lodash";
|
|
2
|
-
import { Context, getRunnerImage
|
|
3
|
-
import {
|
|
2
|
+
import { Context, getRunnerImage } from "../..";
|
|
3
|
+
import { CatladderJob } from "../../types/jobs";
|
|
4
4
|
import { ensureArray } from "../../utils";
|
|
5
5
|
import {
|
|
6
6
|
APP_BUILD_JOB_NAME,
|
|
@@ -10,36 +10,32 @@ import { getBuildInfo } from "./getBuildInfo";
|
|
|
10
10
|
|
|
11
11
|
export const createBuildJob = (
|
|
12
12
|
context: Context,
|
|
13
|
-
{ script, variables, ...def }: Partial<
|
|
14
|
-
):
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
retry: BASE_RETRY,
|
|
31
|
-
interruptible: true,
|
|
13
|
+
{ script, variables, ...def }: Partial<CatladderJob>
|
|
14
|
+
): CatladderJob => {
|
|
15
|
+
return merge(
|
|
16
|
+
{
|
|
17
|
+
name: APP_BUILD_JOB_NAME,
|
|
18
|
+
envMode: "jobPerEnv",
|
|
19
|
+
stage: "build",
|
|
20
|
+
image: getRunnerImage("jobs-default"),
|
|
21
|
+
needs: [],
|
|
22
|
+
cache: [],
|
|
23
|
+
variables: {
|
|
24
|
+
...RUNNER_BUILD_RESOURCE_VARIABLES,
|
|
25
|
+
...(variables ?? {}),
|
|
26
|
+
...context.environment.envVars,
|
|
27
|
+
...(context.componentConfig.build.extraVars ?? {}),
|
|
28
|
+
},
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
30
|
+
script: [
|
|
31
|
+
...getBuildInfo(context),
|
|
32
|
+
`cd ${context.componentConfig.dir}`,
|
|
33
|
+
...(ensureArray(script) ?? []),
|
|
34
|
+
],
|
|
35
|
+
artifacts: {
|
|
36
|
+
paths: [context.componentConfig.dir + "/__build_info.json"],
|
|
41
37
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
},
|
|
39
|
+
def
|
|
40
|
+
);
|
|
45
41
|
};
|
package/src/build/docker.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getRunnerImage } from "../runner";
|
|
2
|
-
import { GitlabJobDef, Context, GitlabJob } from "../types";
|
|
3
|
-
|
|
4
1
|
import { merge } from "lodash";
|
|
2
|
+
import { getRunnerImage } from "../runner";
|
|
3
|
+
import { Context } from "../types";
|
|
4
|
+
import { CatladderJob } from "../types/jobs";
|
|
5
5
|
|
|
6
6
|
const DOCKER_RUNNER_BUILD_VARIABLES = {
|
|
7
7
|
KUBERNETES_CPU_REQUEST: "0.5",
|
|
@@ -14,55 +14,53 @@ export const DOCKER_BUILD_JOB_NAME = "🔨 docker";
|
|
|
14
14
|
|
|
15
15
|
export const createDockerBuildJob = (
|
|
16
16
|
context: Context,
|
|
17
|
-
{ script, variables, ...def }: Partial<
|
|
18
|
-
):
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
image: getRunnerImage("docker-build"),
|
|
26
|
-
interruptible: true,
|
|
27
|
-
services: [
|
|
28
|
-
{
|
|
29
|
-
name: "docker:20-dind", // see see https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300#note_466755332
|
|
30
|
-
command: ["--tls=false"],
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
variables: {
|
|
34
|
-
...DOCKER_RUNNER_BUILD_VARIABLES,
|
|
35
|
-
DOCKER_BUILDKIT: "1", // see https://docs.docker.com/develop/develop-images/build_enhancements/
|
|
36
|
-
DOCKERFILE_ADDITIONS:
|
|
37
|
-
context.componentConfig.build.docker?.additionsBegin?.join("\n"),
|
|
38
|
-
DOCKERFILE_ADDITIONS_END:
|
|
39
|
-
context.componentConfig.build.docker?.additionsEnd?.join("\n"),
|
|
40
|
-
APP_DIR: context.componentConfig.dir,
|
|
41
|
-
DOCKER_HOST: "tcp://0.0.0.0:2375",
|
|
42
|
-
DOCKER_TLS_CERTDIR: "",
|
|
43
|
-
DOCKER_DIR: ".", // relative to componentdir
|
|
44
|
-
IMAGE_TAG: "$CI_COMMIT_SHA",
|
|
45
|
-
DOCKER_DRIVER: "overlay2",
|
|
17
|
+
{ script, variables, ...def }: Partial<CatladderJob>
|
|
18
|
+
): CatladderJob => {
|
|
19
|
+
return merge(
|
|
20
|
+
{
|
|
21
|
+
name: DOCKER_BUILD_JOB_NAME,
|
|
22
|
+
envMode: "jobPerEnv",
|
|
23
|
+
stage: "build",
|
|
24
|
+
image: getRunnerImage("docker-build"),
|
|
46
25
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
context.componentName,
|
|
52
|
-
|
|
53
|
-
CACHE_IMAGE: "$CI_REGISTRY_IMAGE/caches/" + context.componentName,
|
|
54
|
-
...(variables ?? {}),
|
|
26
|
+
services: [
|
|
27
|
+
{
|
|
28
|
+
name: "docker:20-dind", // see see https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300#note_466755332
|
|
29
|
+
command: ["--tls=false"],
|
|
55
30
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
31
|
+
],
|
|
32
|
+
variables: {
|
|
33
|
+
...DOCKER_RUNNER_BUILD_VARIABLES,
|
|
34
|
+
DOCKER_BUILDKIT: "1", // see https://docs.docker.com/develop/develop-images/build_enhancements/
|
|
35
|
+
DOCKERFILE_ADDITIONS:
|
|
36
|
+
context.componentConfig.build.docker?.additionsBegin?.join("\n"),
|
|
37
|
+
DOCKERFILE_ADDITIONS_END:
|
|
38
|
+
context.componentConfig.build.docker?.additionsEnd?.join("\n"),
|
|
39
|
+
APP_DIR: context.componentConfig.dir,
|
|
40
|
+
DOCKER_HOST: "tcp://0.0.0.0:2375",
|
|
41
|
+
DOCKER_TLS_CERTDIR: "",
|
|
42
|
+
DOCKER_DIR: ".", // relative to componentdir
|
|
43
|
+
IMAGE_TAG: "$CI_COMMIT_SHA",
|
|
44
|
+
DOCKER_DRIVER: "overlay2",
|
|
45
|
+
|
|
46
|
+
IMAGE_NAME:
|
|
47
|
+
"$CI_REGISTRY_IMAGE/" +
|
|
48
|
+
context.environment.shortName +
|
|
49
|
+
"/" +
|
|
50
|
+
context.componentName,
|
|
51
|
+
|
|
52
|
+
CACHE_IMAGE: "$CI_REGISTRY_IMAGE/caches/" + context.componentName,
|
|
53
|
+
...(variables ?? {}),
|
|
64
54
|
},
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
script: [
|
|
56
|
+
...(script || []),
|
|
57
|
+
"docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY",
|
|
58
|
+
"docker build --network host --cache-from $CACHE_IMAGE --tag $IMAGE_NAME:$IMAGE_TAG -f $APP_DIR/Dockerfile . --build-arg BUILDKIT_INLINE_CACHE=1", //BUILDKIT_INLINE_CACHE, see https://testdriven.io/blog/faster-ci-builds-with-docker-cache/
|
|
59
|
+
"docker push $IMAGE_NAME:$IMAGE_TAG",
|
|
60
|
+
"docker tag $IMAGE_NAME:$IMAGE_TAG $CACHE_IMAGE",
|
|
61
|
+
"docker push $CACHE_IMAGE",
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
def
|
|
65
|
+
);
|
|
68
66
|
};
|
package/src/build/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Context } from "../types/context";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { CatladderJob } from "../types/jobs";
|
|
3
4
|
import { createNodeJobs, createStorybookJobs, createMeteorJobs } from "./node";
|
|
4
5
|
|
|
5
6
|
import { BuildConfig } from "./types";
|
|
@@ -8,7 +9,7 @@ export * from "./node";
|
|
|
8
9
|
|
|
9
10
|
export type BuildTypes = {
|
|
10
11
|
[type in BuildConfig["type"]]: {
|
|
11
|
-
jobs: (context: Context) =>
|
|
12
|
+
jobs: (context: Context) => CatladderJob[];
|
|
12
13
|
defaults: () => Partial<Extract<BuildConfig, { type: type }>>;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Context } from "../../types/context";
|
|
2
|
-
import { GitlabJob, GitlabJobs } from "../../types/gitlab-types";
|
|
3
2
|
import { ensureArray } from "../../utils";
|
|
4
3
|
import { APP_BUILD_JOB_NAME } from "../base/constants";
|
|
5
4
|
import { createBuildJob } from "../base/createBuildJob";
|
|
@@ -9,8 +8,9 @@ import { isOfBuildType } from "../types";
|
|
|
9
8
|
import { getNextCache, getNodeCache, getYarnCache } from "./cache";
|
|
10
9
|
import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
|
|
11
10
|
import { getYarnInstall, getYarnInstallCommand } from "./yarn";
|
|
11
|
+
import { CatladderJob } from "../../types/jobs";
|
|
12
12
|
|
|
13
|
-
export const createNodeBuildJobs = (context: Context):
|
|
13
|
+
export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
|
|
14
14
|
const buildConfig = context.componentConfig.build;
|
|
15
15
|
|
|
16
16
|
if (!isOfBuildType(buildConfig, "node", "node-static", "storybook")) {
|
|
@@ -18,7 +18,7 @@ export const createNodeBuildJobs = (context: Context): GitlabJobs => {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const yarnInstall = getYarnInstall(context);
|
|
21
|
-
const appBuildJob:
|
|
21
|
+
const appBuildJob: CatladderJob | null =
|
|
22
22
|
buildConfig.buildCommand !== null
|
|
23
23
|
? createBuildJob(context, {
|
|
24
24
|
variables: {
|
package/src/build/node/index.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Context } from "../../types/context";
|
|
2
|
-
import
|
|
2
|
+
import { CatladderJob } from "../../types/jobs";
|
|
3
3
|
import { createNodeBuildJobs } from "./buildJob";
|
|
4
4
|
import { createMeteorBuildJobs } from "./meteor";
|
|
5
5
|
import { createNodeTestJobs } from "./testJob";
|
|
6
6
|
|
|
7
|
-
export const createNodeJobs = (context: Context):
|
|
7
|
+
export const createNodeJobs = (context: Context): CatladderJob[] => {
|
|
8
8
|
return [...createNodeTestJobs(context), ...createNodeBuildJobs(context)];
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export const createStorybookJobs = (context: Context):
|
|
11
|
+
export const createStorybookJobs = (context: Context): CatladderJob[] => {
|
|
12
12
|
return [...createNodeBuildJobs(context)];
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
export const createMeteorJobs = (context: Context):
|
|
15
|
+
export const createMeteorJobs = (context: Context): CatladderJob[] => {
|
|
16
16
|
return [...createNodeTestJobs(context), ...createMeteorBuildJobs(context)];
|
|
17
17
|
};
|
package/src/build/node/meteor.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
2
|
import { getRunnerImage } from "../../runner";
|
|
3
|
+
import { GitlabJobCache } from "../../types";
|
|
3
4
|
import type { Context } from "../../types/context";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
GitlabJobCache,
|
|
7
|
-
GitlabJobs,
|
|
8
|
-
} from "../../types/gitlab-types";
|
|
5
|
+
|
|
6
|
+
import { CatladderJob } from "../../types/jobs";
|
|
9
7
|
|
|
10
8
|
import { APP_BUILD_JOB_NAME } from "../base/constants";
|
|
11
9
|
import { createBuildJob } from "../base/createBuildJob";
|
|
@@ -29,7 +27,7 @@ const getMeteorCache = (context: Context): GitlabJobCache[] => [
|
|
|
29
27
|
],
|
|
30
28
|
},
|
|
31
29
|
];
|
|
32
|
-
export const createMeteorBuildJobs = (context: Context):
|
|
30
|
+
export const createMeteorBuildJobs = (context: Context): CatladderJob[] => {
|
|
33
31
|
const buildConfig = context.componentConfig.build;
|
|
34
32
|
|
|
35
33
|
if (!isOfBuildType(buildConfig, "meteor")) {
|
|
@@ -37,7 +35,7 @@ export const createMeteorBuildJobs = (context: Context): GitlabJobs => {
|
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
const yarnInstall = getYarnInstall(context);
|
|
40
|
-
const appBuildJob:
|
|
38
|
+
const appBuildJob: CatladderJob | null =
|
|
41
39
|
buildConfig.buildCommand !== null
|
|
42
40
|
? createBuildJob(context, {
|
|
43
41
|
cache: [...getNodeCache(context), ...getMeteorCache(context)],
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { BASE_RETRY } from "../../defaults";
|
|
2
1
|
import { Context } from "../../types/context";
|
|
3
|
-
import {
|
|
2
|
+
import { CatladderJob } from "../../types/jobs";
|
|
4
3
|
import { ensureArray, notNil } from "../../utils";
|
|
5
4
|
import { getNodeCache } from "./cache";
|
|
6
5
|
import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
|
|
7
6
|
import { getYarnInstall } from "./yarn";
|
|
8
7
|
|
|
9
|
-
export const createNodeTestJobs = (context: Context):
|
|
8
|
+
export const createNodeTestJobs = (context: Context): CatladderJob[] => {
|
|
10
9
|
// don't run tests after release
|
|
11
10
|
if (context.commitInfo?.trigger === "taggedRelease") {
|
|
12
11
|
return [];
|
|
@@ -14,66 +13,58 @@ export const createNodeTestJobs = (context: Context): GitlabJobs => {
|
|
|
14
13
|
|
|
15
14
|
const buildConfig = context.componentConfig.build;
|
|
16
15
|
|
|
17
|
-
const base: Omit<
|
|
16
|
+
const base: Omit<CatladderJob, "script" | "name"> = {
|
|
18
17
|
variables: {
|
|
19
18
|
APP_PATH: context.componentConfig.dir,
|
|
20
19
|
...NODE_RUNNER_BUILD_VARIABLES,
|
|
21
20
|
...(buildConfig.extraVars ?? {}),
|
|
22
21
|
},
|
|
23
|
-
|
|
24
22
|
stage: "test",
|
|
25
|
-
interruptible: true,
|
|
26
23
|
needs: [],
|
|
27
|
-
|
|
24
|
+
envMode: "none",
|
|
28
25
|
};
|
|
29
26
|
const yarnInstall = getYarnInstall(context);
|
|
30
|
-
const auditJob:
|
|
27
|
+
const auditJob: CatladderJob | null =
|
|
31
28
|
buildConfig.audit !== false
|
|
32
29
|
? {
|
|
33
30
|
name: "🛡 audit",
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
allow_failure: true,
|
|
43
|
-
},
|
|
31
|
+
|
|
32
|
+
...base,
|
|
33
|
+
cache: undefined, // audit does not need yarn install and no cache
|
|
34
|
+
script: [
|
|
35
|
+
`cd ${context.componentConfig.dir}`,
|
|
36
|
+
...(ensureArray(buildConfig.audit?.command) ?? ["yarn audit"]),
|
|
37
|
+
],
|
|
38
|
+
allow_failure: true,
|
|
44
39
|
}
|
|
45
40
|
: null;
|
|
46
41
|
|
|
47
|
-
const lintJob:
|
|
42
|
+
const lintJob: CatladderJob | null =
|
|
48
43
|
buildConfig.lint !== false
|
|
49
44
|
? {
|
|
50
45
|
name: "👮 lint",
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
],
|
|
60
|
-
},
|
|
46
|
+
|
|
47
|
+
...base,
|
|
48
|
+
cache: getNodeCache(context),
|
|
49
|
+
script: [
|
|
50
|
+
`cd ${context.componentConfig.dir}`,
|
|
51
|
+
...yarnInstall,
|
|
52
|
+
...(ensureArray(buildConfig.lint?.command) ?? ["yarn lint"]),
|
|
53
|
+
],
|
|
61
54
|
}
|
|
62
55
|
: null;
|
|
63
|
-
const testJob:
|
|
56
|
+
const testJob: CatladderJob | null =
|
|
64
57
|
buildConfig.test !== false
|
|
65
58
|
? {
|
|
66
59
|
name: "🧪 test",
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
],
|
|
76
|
-
},
|
|
60
|
+
|
|
61
|
+
...base,
|
|
62
|
+
cache: getNodeCache(context),
|
|
63
|
+
script: [
|
|
64
|
+
`cd ${context.componentConfig.dir}`,
|
|
65
|
+
...yarnInstall,
|
|
66
|
+
...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
|
|
67
|
+
],
|
|
77
68
|
}
|
|
78
69
|
: null;
|
|
79
70
|
return [auditJob, lintJob, testJob].filter(notNil);
|
|
@@ -26,7 +26,8 @@ describe("storybook build", () => {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
it("creates a pipeline for storybook that does not contain test stages", async () => {
|
|
29
|
-
const {
|
|
29
|
+
const { jobs } = await createChildPipeline(
|
|
30
|
+
"gitlab",
|
|
30
31
|
"mainBranch",
|
|
31
32
|
config
|
|
32
33
|
);
|
|
@@ -40,7 +41,8 @@ describe("storybook build", () => {
|
|
|
40
41
|
});
|
|
41
42
|
|
|
42
43
|
it("runs build and renames folder", async () => {
|
|
43
|
-
const {
|
|
44
|
+
const { jobs } = await createChildPipeline(
|
|
45
|
+
"gitlab",
|
|
44
46
|
"mainBranch",
|
|
45
47
|
config
|
|
46
48
|
);
|
package/src/catladder-gitlab.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { writeFileSync } from "fs";
|
|
2
|
+
import { dump } from "js-yaml";
|
|
2
3
|
import { readConfigSync } from "./config";
|
|
3
4
|
import { PIPELINE_IMAGE_TAG } from "./constants";
|
|
4
5
|
import { createChildPipeline } from "./pipeline";
|
|
@@ -32,11 +33,14 @@ if (trigger) {
|
|
|
32
33
|
if (!config) {
|
|
33
34
|
throw new Error("no catladder config found");
|
|
34
35
|
}
|
|
35
|
-
createChildPipeline(trigger, config).then(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
createChildPipeline("gitlab", trigger, config).then(
|
|
37
|
+
({ jobs, ...mainPipeline }) => {
|
|
38
|
+
// need to spread out the jobs
|
|
39
|
+
writeFileSync(`__pipeline.yml`, dump({ ...jobs, ...mainPipeline }), {
|
|
40
|
+
encoding: "utf-8",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
);
|
|
40
44
|
} else {
|
|
41
45
|
throw new Error(
|
|
42
46
|
"no matching trigger: " +
|
package/src/deploy/base.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context } from "../types";
|
|
2
|
+
import { CatladderJob } from "../types/jobs";
|
|
2
3
|
|
|
3
4
|
export const DEPLOY_JOB_NAME = "🚀 Deploy";
|
|
4
5
|
export const STOP_JOB_NAME = "🛑 Stop ⚠️";
|
|
@@ -9,9 +10,7 @@ const DEPLOY_RUNNER_VARIABLES = {
|
|
|
9
10
|
KUBERNETES_MEMORY_REQUEST: "200Mi",
|
|
10
11
|
KUBERNETES_MEMORY_LIMIT: "500Mi",
|
|
11
12
|
};
|
|
12
|
-
type JobWithoutScript = Omit<
|
|
13
|
-
job: Omit<GitlabJobDef, "script">;
|
|
14
|
-
};
|
|
13
|
+
type JobWithoutScript = Omit<CatladderJob, "script">;
|
|
15
14
|
export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
|
|
16
15
|
const environment = {
|
|
17
16
|
name: context.environment.fullName,
|
|
@@ -45,26 +44,24 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
|
|
|
45
44
|
artifacts: false,
|
|
46
45
|
},
|
|
47
46
|
], // workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/220758
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
environment
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
auto_stop_in: autoStop,
|
|
67
|
-
},
|
|
47
|
+
|
|
48
|
+
rules: [
|
|
49
|
+
autoDeploy
|
|
50
|
+
? {
|
|
51
|
+
when: "on_success",
|
|
52
|
+
}
|
|
53
|
+
: {
|
|
54
|
+
when: "manual",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
stage: "deploy",
|
|
58
|
+
variables: {
|
|
59
|
+
...DEPLOY_RUNNER_VARIABLES,
|
|
60
|
+
},
|
|
61
|
+
environment: {
|
|
62
|
+
...environment,
|
|
63
|
+
on_stop: STOP_JOB_NAME,
|
|
64
|
+
auto_stop_in: autoStop,
|
|
68
65
|
},
|
|
69
66
|
};
|
|
70
67
|
};
|
|
@@ -79,29 +76,27 @@ export const getBaseDeploymentStopJob = (
|
|
|
79
76
|
return {
|
|
80
77
|
name: STOP_JOB_NAME,
|
|
81
78
|
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
when: "manual",
|
|
92
|
-
allow_failure: true,
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
variables: {
|
|
96
|
-
...DEPLOY_RUNNER_VARIABLES,
|
|
97
|
-
GIT_STRATEGY: "none",
|
|
79
|
+
|
|
80
|
+
needs: [DEPLOY_JOB_NAME],
|
|
81
|
+
rules: [
|
|
82
|
+
{
|
|
83
|
+
if: "$CI_COMMIT_BRANCH =~ /^[0-9]+\\.([0-9]+|x)\\.x$/", // automatic on hotfix branches
|
|
84
|
+
when: "on_success",
|
|
85
|
+
allow_failure: true,
|
|
98
86
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
...environment,
|
|
103
|
-
action: "stop",
|
|
87
|
+
{
|
|
88
|
+
when: "manual",
|
|
89
|
+
allow_failure: true,
|
|
104
90
|
},
|
|
91
|
+
],
|
|
92
|
+
variables: {
|
|
93
|
+
...DEPLOY_RUNNER_VARIABLES,
|
|
94
|
+
GIT_STRATEGY: "none",
|
|
95
|
+
},
|
|
96
|
+
stage: "stop",
|
|
97
|
+
environment: {
|
|
98
|
+
...environment,
|
|
99
|
+
action: "stop",
|
|
105
100
|
},
|
|
106
101
|
};
|
|
107
102
|
};
|