@catladder/pipeline 0.0.0-refactor-deploy-5f0bbd8a → 0.0.0-refactor-image-ca767657
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/createAppBuildJob.d.ts +8 -0
- package/dist/build/base/{createBuildJob.js → createAppBuildJob.js} +3 -3
- package/dist/build/base/index.d.ts +8 -0
- package/dist/build/base/index.js +57 -0
- package/dist/build/custom/buildJob.js +19 -22
- package/dist/build/docker.d.ts +2 -4
- package/dist/build/docker.js +4 -39
- package/dist/build/node/buildJob.js +30 -32
- package/dist/build/node/meteor.js +19 -21
- package/dist/build/rails/build.js +12 -19
- package/dist/build/types.d.ts +4 -3
- package/dist/bundles/catladder-gitlab/index.js +387 -300
- package/dist/constants.js +1 -1
- package/dist/context/getLabels.d.ts +1 -0
- package/dist/context/getLabels.js +1 -0
- package/dist/deploy/base/deploy.d.ts +5 -0
- package/dist/deploy/base/deploy.js +106 -0
- package/dist/deploy/base/index.d.ts +10 -8
- package/dist/deploy/base/index.js +7 -106
- package/dist/deploy/base/rollback.d.ts +4 -2
- package/dist/deploy/base/rollback.js +10 -8
- package/dist/deploy/base/stop.d.ts +5 -0
- package/dist/deploy/base/stop.js +41 -0
- package/dist/deploy/cloudRun/deployJob.js +29 -27
- package/dist/deploy/custom/deployJob.js +14 -11
- package/dist/deploy/dockerTag/deployJob.js +15 -5
- package/dist/deploy/kubernetes/deployJob.js +14 -26
- package/dist/deploy/kubernetes/mongodb.d.ts +1 -1
- package/dist/deploy/kubernetes/mongodb.js +8 -7
- package/dist/deploy/types/index.d.ts +1 -1
- package/dist/pipeline/gitlab/createGitlabJobs.d.ts +1 -0
- package/dist/pipeline/gitlab/createGitlabJobs.js +4 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/gitlab-ci-yml.d.ts +769 -0
- package/dist/types/gitlab-ci-yml.js +9 -0
- package/dist/types/gitlab-types.d.ts +12 -85
- package/dist/types/jobs.d.ts +3 -3
- package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +16 -16
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +16 -16
- package/examples/__snapshots__/cloud-run-non-public.ts.snap +16 -16
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +32 -32
- package/examples/__snapshots__/cloud-run-with-sql.ts.snap +48 -48
- package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +16 -16
- package/examples/__snapshots__/custom-build-job.ts.snap +16 -16
- package/examples/__snapshots__/custom-sbom-java.ts.snap +16 -16
- package/examples/__snapshots__/kubernetes-application-customization.ts.snap +0 -36
- package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +0 -36
- package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +0 -36
- package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +0 -72
- package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +0 -36
- package/examples/__snapshots__/meteor-kubernetes.ts.snap +0 -36
- package/examples/__snapshots__/native-app.ts.snap +16 -16
- package/examples/__snapshots__/node-build-with-custom-image.ts.snap +16 -16
- package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +0 -36
- package/package.json +4 -2
- package/scripts/generate-gitlab-ci-types.ts +51 -0
- package/src/build/base/{createBuildJob.ts → createAppBuildJob.ts} +3 -2
- package/src/build/base/index.ts +35 -0
- package/src/build/custom/buildJob.ts +32 -45
- package/src/build/docker.ts +14 -17
- package/src/build/node/buildJob.ts +50 -61
- package/src/build/node/meteor.ts +31 -36
- package/src/build/rails/build.ts +8 -10
- package/src/build/types.ts +4 -8
- package/src/context/getLabels.ts +1 -0
- package/src/deploy/base/deploy.ts +114 -0
- package/src/deploy/base/index.ts +21 -133
- package/src/deploy/base/rollback.ts +15 -3
- package/src/deploy/base/stop.ts +44 -0
- package/src/deploy/cloudRun/deployJob.ts +14 -16
- package/src/deploy/custom/deployJob.ts +17 -20
- package/src/deploy/dockerTag/deployJob.ts +6 -7
- package/src/deploy/kubernetes/deployJob.ts +17 -34
- package/src/deploy/kubernetes/mongodb.ts +3 -2
- package/src/pipeline/gitlab/createGitlabJobs.ts +3 -0
- package/src/types/gitlab-ci-yml.ts +892 -0
- package/src/types/gitlab-types.ts +49 -86
- package/src/types/jobs.ts +3 -4
- package/dist/build/base/createBuildJob.d.ts +0 -7
package/src/build/docker.ts
CHANGED
|
@@ -57,6 +57,7 @@ export const getDockerBuildVariables = (context: Context) => {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
export const DOCKER_BUILD_JOB_NAME = "🔨 docker";
|
|
60
|
+
|
|
60
61
|
export const getDockerJobBaseProps = (context: Context) => {
|
|
61
62
|
return {
|
|
62
63
|
image: getRunnerImage("docker-build"),
|
|
@@ -69,6 +70,8 @@ export const getDockerJobBaseProps = (context: Context) => {
|
|
|
69
70
|
variables: getDockerBaseVariables(),
|
|
70
71
|
};
|
|
71
72
|
};
|
|
73
|
+
|
|
74
|
+
export type DockerBuildJobDefinition = Partial<CatladderJob>;
|
|
72
75
|
export const createDockerBuildJobBase = (
|
|
73
76
|
context: Context,
|
|
74
77
|
{ script, ...def }: Partial<CatladderJob>
|
|
@@ -90,20 +93,14 @@ export const createDockerBuildJobBase = (
|
|
|
90
93
|
|
|
91
94
|
export const gitlabDockerLogin =
|
|
92
95
|
"docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY";
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
"docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG $DOCKER_CACHE_IMAGE",
|
|
105
|
-
"docker push $DOCKER_CACHE_IMAGE",
|
|
106
|
-
],
|
|
107
|
-
...def,
|
|
108
|
-
});
|
|
109
|
-
};
|
|
96
|
+
|
|
97
|
+
export const getDockerBuildDefaultScript = (ensureDockerFileScript?: string) =>
|
|
98
|
+
[
|
|
99
|
+
ensureDockerFileScript,
|
|
100
|
+
gitlabDockerLogin,
|
|
101
|
+
"docker version",
|
|
102
|
+
"docker build --network host --cache-from $DOCKER_CACHE_IMAGE --tag $DOCKER_IMAGE:$DOCKER_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/
|
|
103
|
+
"docker push $DOCKER_IMAGE:$DOCKER_IMAGE_TAG",
|
|
104
|
+
"docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG $DOCKER_CACHE_IMAGE",
|
|
105
|
+
"docker push $DOCKER_CACHE_IMAGE",
|
|
106
|
+
].filter(Boolean);
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { getRunnerImage } from "../../runner";
|
|
1
3
|
import type { Context } from "../../types/context";
|
|
4
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
2
5
|
import { ensureArray } from "../../utils";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { createDockerBuildJobDefault, requiresDockerBuild } from "../docker";
|
|
6
|
-
import { join } from "path";
|
|
6
|
+
import { createBuildJobs } from "../base";
|
|
7
|
+
import { getDockerBuildDefaultScript, requiresDockerBuild } from "../docker";
|
|
7
8
|
import { isOfBuildType } from "../types";
|
|
8
9
|
import { getNextCache, getNodeCache, getYarnCache } from "./cache";
|
|
9
10
|
import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
|
|
10
11
|
import { getDockerAppCopyAndBuildScript, getYarnInstall } from "./yarn";
|
|
11
|
-
import type { CatladderJob } from "../../types/jobs";
|
|
12
|
-
import { getRunnerImage } from "../../runner";
|
|
13
|
-
import { createSbomBuildJob } from "../sbom";
|
|
14
|
-
import { sbomDeactivated } from "../../deploy/sbom";
|
|
15
12
|
|
|
16
13
|
export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
|
|
17
14
|
const buildConfig = context.componentConfig.build;
|
|
@@ -22,62 +19,54 @@ export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
22
19
|
|
|
23
20
|
const defaultImage = getRunnerImage("jobs-default");
|
|
24
21
|
const yarnInstall = getYarnInstall(context);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
...yarnInstall,
|
|
39
|
-
...(ensureArray(buildConfig.buildCommand) ?? []),
|
|
40
|
-
],
|
|
41
|
-
artifacts: {
|
|
42
|
-
paths: [
|
|
43
|
-
join(context.componentConfig.dir, "__build_info.json"),
|
|
44
|
-
join(context.componentConfig.dir, "dist"),
|
|
45
|
-
join(context.componentConfig.dir, ".next"),
|
|
46
|
-
...(buildConfig.artifactsPaths?.map((path) =>
|
|
47
|
-
join(context.componentConfig.dir, path)
|
|
48
|
-
) ?? []),
|
|
22
|
+
|
|
23
|
+
return createBuildJobs(context, {
|
|
24
|
+
appBuild:
|
|
25
|
+
buildConfig.buildCommand !== null
|
|
26
|
+
? {
|
|
27
|
+
image: buildConfig.jobImage ?? defaultImage,
|
|
28
|
+
variables: {
|
|
29
|
+
...NODE_RUNNER_BUILD_VARIABLES,
|
|
30
|
+
},
|
|
31
|
+
cache: [
|
|
32
|
+
...(ensureArray(buildConfig.jobCache) ?? []),
|
|
33
|
+
...getNodeCache(context),
|
|
34
|
+
...getNextCache(context),
|
|
49
35
|
],
|
|
50
|
-
expire_in: "1 day",
|
|
51
|
-
},
|
|
52
|
-
jobTags: buildConfig.jobTags,
|
|
53
|
-
})
|
|
54
|
-
: null;
|
|
55
|
-
return [
|
|
56
|
-
...(appBuildJob ? [appBuildJob] : []),
|
|
57
|
-
...(requiresDockerBuild(context)
|
|
58
|
-
? [
|
|
59
|
-
createDockerBuildJobDefault(context, {
|
|
60
36
|
script: [
|
|
61
|
-
|
|
62
|
-
buildConfig.
|
|
63
|
-
? "ensureNginxDockerfile"
|
|
64
|
-
: "ensureNodeDockerfile",
|
|
37
|
+
...yarnInstall,
|
|
38
|
+
...(ensureArray(buildConfig.buildCommand) ?? []),
|
|
65
39
|
],
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
40
|
+
artifacts: {
|
|
41
|
+
paths: [
|
|
42
|
+
join(context.componentConfig.dir, "__build_info.json"),
|
|
43
|
+
join(context.componentConfig.dir, "dist"),
|
|
44
|
+
join(context.componentConfig.dir, ".next"),
|
|
45
|
+
...(buildConfig.artifactsPaths?.map((path) =>
|
|
46
|
+
join(context.componentConfig.dir, path)
|
|
47
|
+
) ?? []),
|
|
48
|
+
],
|
|
49
|
+
expire_in: "1 day",
|
|
75
50
|
},
|
|
51
|
+
jobTags: buildConfig.jobTags,
|
|
52
|
+
}
|
|
53
|
+
: undefined,
|
|
76
54
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
55
|
+
dockerBuild: {
|
|
56
|
+
script: getDockerBuildDefaultScript(
|
|
57
|
+
buildConfig.type === "node-static" || buildConfig.type === "storybook"
|
|
58
|
+
? "ensureNginxDockerfile"
|
|
59
|
+
: "ensureNodeDockerfile"
|
|
60
|
+
),
|
|
61
|
+
cache: [...getYarnCache(context, "pull")],
|
|
62
|
+
variables: {
|
|
63
|
+
// only required for non static
|
|
64
|
+
DOCKER_COPY_AND_INSTALL_APP: getDockerAppCopyAndBuildScript(context),
|
|
65
|
+
DOCKER_COPY_WORKSPACE_FILES:
|
|
66
|
+
context.packageManagerInfo?.pathsToCopyInDocker
|
|
67
|
+
.map((dir) => `COPY --chown=node:node ${dir} /app/${dir}`)
|
|
68
|
+
?.join("\n"),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
83
72
|
};
|
package/src/build/node/meteor.ts
CHANGED
|
@@ -5,14 +5,11 @@ import type { Context } from "../../types/context";
|
|
|
5
5
|
|
|
6
6
|
import type { CatladderJob } from "../../types/jobs";
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { createDockerBuildJobDefault } from "../docker";
|
|
8
|
+
import { createBuildJobs } from "../base";
|
|
9
|
+
import { getDockerBuildDefaultScript } from "../docker";
|
|
11
10
|
import { isOfBuildType } from "../types";
|
|
12
11
|
import { getNodeCache } from "./cache";
|
|
13
12
|
import { getYarnInstall } from "./yarn";
|
|
14
|
-
import { sbomDeactivated } from "../../deploy/sbom";
|
|
15
|
-
import { createSbomBuildJob } from "../sbom";
|
|
16
13
|
|
|
17
14
|
const getMeteorCache = (context: Context): GitlabJobCache[] => [
|
|
18
15
|
{
|
|
@@ -37,42 +34,40 @@ export const createMeteorBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
const yarnInstall = getYarnInstall(context);
|
|
40
|
-
const appBuildJob: CatladderJob | null =
|
|
41
|
-
buildConfig.buildCommand !== null
|
|
42
|
-
? createBuildJob(context, {
|
|
43
|
-
cache: [...getNodeCache(context), ...getMeteorCache(context)],
|
|
44
|
-
image: getRunnerImage("jobs-meteor"),
|
|
45
|
-
variables: {
|
|
46
|
-
METEOR_DISABLE_OPTIMISTIC_CACHING: "1", // see https://forums.meteor.com/t/veeery-long-building-time-inside-docker-container/58673/17?u=macrozone
|
|
47
|
-
},
|
|
48
|
-
script: [
|
|
49
|
-
...yarnInstall,
|
|
50
37
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
return createBuildJobs(context, {
|
|
39
|
+
appBuild:
|
|
40
|
+
buildConfig.buildCommand !== null
|
|
41
|
+
? {
|
|
42
|
+
cache: [...getNodeCache(context), ...getMeteorCache(context)],
|
|
43
|
+
image: getRunnerImage("jobs-meteor"),
|
|
44
|
+
variables: {
|
|
45
|
+
METEOR_DISABLE_OPTIMISTIC_CACHING: "1", // see https://forums.meteor.com/t/veeery-long-building-time-inside-docker-container/58673/17?u=macrozone
|
|
46
|
+
},
|
|
47
|
+
script: [
|
|
48
|
+
...yarnInstall,
|
|
54
49
|
|
|
55
|
-
|
|
50
|
+
'echo "add healthcheck package"',
|
|
51
|
+
"meteor add panter:healthroute --allow-superuser",
|
|
52
|
+
"meteor add qualia:prod-shell --allow-superuser",
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
paths: [
|
|
61
|
-
context.componentConfig.dir + "/__build_info.json",
|
|
62
|
-
context.componentConfig.dir + "/dist",
|
|
54
|
+
'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',
|
|
55
|
+
|
|
56
|
+
"cp ./__build_info.json ./dist/bundle/programs/server",
|
|
63
57
|
],
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
artifacts: {
|
|
59
|
+
paths: [
|
|
60
|
+
context.componentConfig.dir + "/__build_info.json",
|
|
61
|
+
context.componentConfig.dir + "/dist",
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
: undefined,
|
|
66
|
+
dockerBuild: {
|
|
67
|
+
script: getDockerBuildDefaultScript("ensureMeteorDockerfile"),
|
|
71
68
|
variables: {
|
|
72
69
|
METEOR_INSTALL_SCRIPTS: buildConfig.installScripts ? "true" : "",
|
|
73
70
|
},
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
...(sbomDeactivated(context) ? [] : [createSbomBuildJob(context)]),
|
|
77
|
-
];
|
|
71
|
+
},
|
|
72
|
+
});
|
|
78
73
|
};
|
package/src/build/rails/build.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Context } from "../..";
|
|
2
|
-
import { isOfBuildType } from "../types";
|
|
3
2
|
import type { CatladderJob } from "../../types/jobs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { createBuildJobs } from "../base";
|
|
4
|
+
import { gitlabDockerLogin } from "../docker";
|
|
5
|
+
import { isOfBuildType } from "../types";
|
|
7
6
|
|
|
8
7
|
export const createRailsBuildJobs = (context: Context): CatladderJob[] => {
|
|
9
8
|
const buildConfig = context.componentConfig.build;
|
|
@@ -17,9 +16,9 @@ export const createRailsBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
17
16
|
const packEnvArgs = Object.entries(cnbConf?.buildVars ?? {})
|
|
18
17
|
.map(([k, v]) => `--env '${k}${v ? `=${v}` : ""}'`)
|
|
19
18
|
.join(" ");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
return createBuildJobs(context, {
|
|
20
|
+
appBuild: undefined,
|
|
21
|
+
dockerBuild: {
|
|
23
22
|
variables: {
|
|
24
23
|
...context.environment.jobOnlyVars.build.envVars,
|
|
25
24
|
...context.componentConfig.build.extraVars,
|
|
@@ -38,7 +37,6 @@ export const createRailsBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
38
37
|
cnbConf?.packExtraArgs?.join(" ") ?? ""
|
|
39
38
|
}`,
|
|
40
39
|
],
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
];
|
|
40
|
+
},
|
|
41
|
+
});
|
|
44
42
|
};
|
package/src/build/types.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
EnvVars,
|
|
4
|
-
GitlabJobImage,
|
|
5
|
-
GitlabJobService,
|
|
6
|
-
} from "../types";
|
|
1
|
+
import type { Artifacts, EnvVars, GitlabJobImage } from "../types";
|
|
2
|
+
import type { Services } from "../types/gitlab-ci-yml";
|
|
7
3
|
|
|
8
4
|
import type { CatladderJob } from "../types/jobs";
|
|
9
5
|
|
|
@@ -168,9 +164,9 @@ export type BuildConfigCustom = Omit<
|
|
|
168
164
|
type: "custom";
|
|
169
165
|
jobImage: GitlabJobImage;
|
|
170
166
|
/**
|
|
171
|
-
* {@link
|
|
167
|
+
* {@link Services}s used in lint, test, audit, and build jobs.
|
|
172
168
|
*/
|
|
173
|
-
jobServices?:
|
|
169
|
+
jobServices?: Services;
|
|
174
170
|
|
|
175
171
|
docker: BuildConfigCustomDocker;
|
|
176
172
|
|
package/src/context/getLabels.ts
CHANGED
|
@@ -10,6 +10,7 @@ const sanitize = (value?: string) => {
|
|
|
10
10
|
export const getLabels = (context: Context) => {
|
|
11
11
|
const labels = {
|
|
12
12
|
"customer-name": sanitize(context.fullConfig.customerName),
|
|
13
|
+
"component-name": sanitize(context.componentName),
|
|
13
14
|
"app-name": sanitize(context.fullConfig.appName),
|
|
14
15
|
"env-type": sanitize(context.environment.envType),
|
|
15
16
|
"env-name": sanitize(context.environment.shortName),
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDockerImageVariables,
|
|
3
|
+
requiresDockerBuild,
|
|
4
|
+
} from "../../build/docker";
|
|
5
|
+
import { SBOM_BUILD_JOB_NAME } from "../../build/sbom";
|
|
6
|
+
import type { Context } from "../../types/context";
|
|
7
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
8
|
+
import { sbomDeactivated } from "../sbom";
|
|
9
|
+
import { contextIsStoppable } from "../utils";
|
|
10
|
+
import { STOP_JOB_NAME } from "./stop";
|
|
11
|
+
|
|
12
|
+
import { DEPLOY_RUNNER_VARIABLES } from "./variables";
|
|
13
|
+
|
|
14
|
+
export const DEPLOY_JOB_NAME = "🚀 Deploy";
|
|
15
|
+
|
|
16
|
+
export type DeployJobDefinition = Pick<
|
|
17
|
+
CatladderJob,
|
|
18
|
+
"script" | "variables" | "image" | "cache" | "artifacts" | "services"
|
|
19
|
+
>;
|
|
20
|
+
export const createDeployJob = (
|
|
21
|
+
context: Context,
|
|
22
|
+
jobDefinition: DeployJobDefinition
|
|
23
|
+
): CatladderJob => {
|
|
24
|
+
const hasDocker = requiresDockerBuild(context);
|
|
25
|
+
const isStoppable = contextIsStoppable(context);
|
|
26
|
+
|
|
27
|
+
const autoStop =
|
|
28
|
+
context.environment.envType === "review"
|
|
29
|
+
? "2 week"
|
|
30
|
+
: context.environment.envType === "dev"
|
|
31
|
+
? "4 weeks"
|
|
32
|
+
: undefined;
|
|
33
|
+
|
|
34
|
+
// if auto or manual is configured explicitly, use that
|
|
35
|
+
const whenDeployDefined =
|
|
36
|
+
context.componentConfig.deploy && context.componentConfig.deploy.when
|
|
37
|
+
? context.componentConfig.deploy.when
|
|
38
|
+
: undefined;
|
|
39
|
+
// otherwise auto deploy if env is not prod. If its prod, deploy automatically if stage is disabled
|
|
40
|
+
const whenDeployDefault =
|
|
41
|
+
context.environment.envType !== "prod"
|
|
42
|
+
? "auto" // is not stage, auto deploy
|
|
43
|
+
: context.componentConfig.env?.stage === false
|
|
44
|
+
? "auto" // is prod, but no staging, auto deploy
|
|
45
|
+
: "manual"; // manually deploy
|
|
46
|
+
const whenDeploy = whenDeployDefined ? whenDeployDefined : whenDeployDefault;
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
name: DEPLOY_JOB_NAME,
|
|
50
|
+
script: jobDefinition.script,
|
|
51
|
+
image: jobDefinition.image,
|
|
52
|
+
cache: jobDefinition.cache,
|
|
53
|
+
artifacts: jobDefinition.artifacts,
|
|
54
|
+
services: jobDefinition.services,
|
|
55
|
+
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
56
|
+
|
|
57
|
+
needs: [
|
|
58
|
+
...(sbomDeactivated(context)
|
|
59
|
+
? []
|
|
60
|
+
: [{ job: SBOM_BUILD_JOB_NAME, artifacts: true }]),
|
|
61
|
+
...(context.componentConfig.deploy
|
|
62
|
+
? context.componentConfig.deploy.waitFor?.map((c) => ({
|
|
63
|
+
componentName: c,
|
|
64
|
+
job: DEPLOY_JOB_NAME,
|
|
65
|
+
artifacts: false,
|
|
66
|
+
})) ?? []
|
|
67
|
+
: []),
|
|
68
|
+
],
|
|
69
|
+
// we don't want to deploy when there is a broken test
|
|
70
|
+
needsStages: [
|
|
71
|
+
{
|
|
72
|
+
stage: "build",
|
|
73
|
+
artifacts: hasDocker ? false : true, // we asume that no-docker deployments need build artifacts,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
stage: "test",
|
|
77
|
+
artifacts: false,
|
|
78
|
+
},
|
|
79
|
+
], // workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/220758
|
|
80
|
+
rules: [
|
|
81
|
+
whenDeploy === "auto"
|
|
82
|
+
? {
|
|
83
|
+
when: "on_success",
|
|
84
|
+
}
|
|
85
|
+
: {
|
|
86
|
+
when: "manual",
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
allow_failure: whenDeploy === "manual" ? true : false,
|
|
90
|
+
stage: "deploy",
|
|
91
|
+
variables: {
|
|
92
|
+
...DEPLOY_RUNNER_VARIABLES,
|
|
93
|
+
...context.environment.envVars,
|
|
94
|
+
...(hasDocker ? getDockerImageVariables(context) : {}),
|
|
95
|
+
...context.environment.jobOnlyVars.deploy.envVars,
|
|
96
|
+
...(context.componentConfig.deploy
|
|
97
|
+
? context.componentConfig.deploy.extraVars ?? {}
|
|
98
|
+
: {}),
|
|
99
|
+
...jobDefinition.variables,
|
|
100
|
+
},
|
|
101
|
+
environment: {
|
|
102
|
+
...context.environment.gitlabEnvironment,
|
|
103
|
+
...(isStoppable
|
|
104
|
+
? {
|
|
105
|
+
on_stop: STOP_JOB_NAME,
|
|
106
|
+
auto_stop_in: autoStop,
|
|
107
|
+
}
|
|
108
|
+
: {}),
|
|
109
|
+
},
|
|
110
|
+
jobTags: context.componentConfig.deploy
|
|
111
|
+
? context.componentConfig.deploy.jobTags
|
|
112
|
+
: undefined,
|
|
113
|
+
};
|
|
114
|
+
};
|
package/src/deploy/base/index.ts
CHANGED
|
@@ -1,134 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const autoStop =
|
|
23
|
-
context.environment.envType === "review"
|
|
24
|
-
? "2 week"
|
|
25
|
-
: context.environment.envType === "dev"
|
|
26
|
-
? "4 weeks"
|
|
27
|
-
: undefined;
|
|
28
|
-
|
|
29
|
-
// if auto or manual is configured explicitly, use that
|
|
30
|
-
const whenDeployDefined =
|
|
31
|
-
context.componentConfig.deploy && context.componentConfig.deploy.when
|
|
32
|
-
? context.componentConfig.deploy.when
|
|
33
|
-
: undefined;
|
|
34
|
-
// otherwise auto deploy if env is not prod. If its prod, deploy automatically if stage is disabled
|
|
35
|
-
const whenDeployDefault =
|
|
36
|
-
context.environment.envType !== "prod"
|
|
37
|
-
? "auto" // is not stage, auto deploy
|
|
38
|
-
: context.componentConfig.env?.stage === false
|
|
39
|
-
? "auto" // is prod, but no staging, auto deploy
|
|
40
|
-
: "manual"; // manually deploy
|
|
41
|
-
const whenDeploy = whenDeployDefined ? whenDeployDefined : whenDeployDefault;
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
name: DEPLOY_JOB_NAME,
|
|
45
|
-
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
46
|
-
|
|
47
|
-
needs: [
|
|
48
|
-
...(sbomDeactivated(context)
|
|
49
|
-
? []
|
|
50
|
-
: [{ job: SBOM_BUILD_JOB_NAME, artifacts: true }]),
|
|
51
|
-
...(context.componentConfig.deploy
|
|
52
|
-
? context.componentConfig.deploy.waitFor?.map((c) => ({
|
|
53
|
-
componentName: c,
|
|
54
|
-
job: DEPLOY_JOB_NAME,
|
|
55
|
-
artifacts: false,
|
|
56
|
-
})) ?? []
|
|
57
|
-
: []),
|
|
58
|
-
],
|
|
59
|
-
// we don't want to deploy when there is a broken test
|
|
60
|
-
needsStages: [
|
|
61
|
-
{
|
|
62
|
-
stage: "build",
|
|
63
|
-
artifacts: hasDocker ? false : true, // we asume that no-docker deployments need build artifacts,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
stage: "test",
|
|
67
|
-
artifacts: false,
|
|
68
|
-
},
|
|
69
|
-
], // workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/220758
|
|
70
|
-
rules: [
|
|
71
|
-
whenDeploy === "auto"
|
|
72
|
-
? {
|
|
73
|
-
when: "on_success",
|
|
74
|
-
}
|
|
75
|
-
: {
|
|
76
|
-
when: "manual",
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
allow_failure: whenDeploy === "manual" ? true : false,
|
|
80
|
-
stage: "deploy",
|
|
81
|
-
variables: {
|
|
82
|
-
...DEPLOY_RUNNER_VARIABLES,
|
|
83
|
-
...context.environment.envVars,
|
|
84
|
-
...(hasDocker ? getDockerImageVariables(context) : {}),
|
|
85
|
-
...context.environment.jobOnlyVars.deploy.envVars,
|
|
86
|
-
...(context.componentConfig.deploy
|
|
87
|
-
? context.componentConfig.deploy.extraVars ?? {}
|
|
88
|
-
: {}),
|
|
89
|
-
},
|
|
90
|
-
environment: {
|
|
91
|
-
...context.environment.gitlabEnvironment,
|
|
92
|
-
...(isStoppable
|
|
93
|
-
? {
|
|
94
|
-
on_stop: STOP_JOB_NAME,
|
|
95
|
-
auto_stop_in: autoStop,
|
|
96
|
-
}
|
|
97
|
-
: {}),
|
|
98
|
-
},
|
|
99
|
-
jobTags: context.componentConfig.deploy
|
|
100
|
-
? context.componentConfig.deploy.jobTags
|
|
101
|
-
: undefined,
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export const getBaseDeploymentStopJob = (
|
|
106
|
-
context: Context
|
|
107
|
-
): JobWithoutScript => {
|
|
108
|
-
return {
|
|
109
|
-
name: STOP_JOB_NAME,
|
|
110
|
-
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
111
|
-
needs: [], // can be executed even if the deploy job failed
|
|
112
|
-
rules: [
|
|
113
|
-
{
|
|
114
|
-
if: "$CI_COMMIT_BRANCH =~ /^[0-9]+\\.([0-9]+|x)\\.x$/", // automatic on hotfix branches
|
|
115
|
-
when: "on_success",
|
|
116
|
-
allow_failure: true,
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
when: "manual",
|
|
120
|
-
allow_failure: true,
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
variables: {
|
|
124
|
-
...DEPLOY_RUNNER_VARIABLES,
|
|
125
|
-
...context.environment.jobOnlyVars.deploy.envVars,
|
|
126
|
-
GIT_STRATEGY: "none",
|
|
127
|
-
},
|
|
128
|
-
stage: "stop",
|
|
129
|
-
environment: {
|
|
130
|
-
...context.environment.gitlabEnvironment,
|
|
131
|
-
action: "stop",
|
|
132
|
-
},
|
|
133
|
-
};
|
|
1
|
+
import type { Context } from "../../types/context";
|
|
2
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
3
|
+
import { createDeployJob, type DeployJobDefinition } from "./deploy";
|
|
4
|
+
import { createRollbackJob, type RollbackJobDefinition } from "./rollback";
|
|
5
|
+
import { createStopJob, type StopJobDefinition } from "./stop";
|
|
6
|
+
|
|
7
|
+
export const createDeployementJobs = (
|
|
8
|
+
context: Context,
|
|
9
|
+
definitions: {
|
|
10
|
+
deploy: DeployJobDefinition;
|
|
11
|
+
stop?: StopJobDefinition;
|
|
12
|
+
rollback?: RollbackJobDefinition;
|
|
13
|
+
}
|
|
14
|
+
): CatladderJob[] => {
|
|
15
|
+
return [
|
|
16
|
+
createDeployJob(context, definitions.deploy),
|
|
17
|
+
...(definitions.stop ? [createStopJob(context, definitions.stop)] : []),
|
|
18
|
+
...(definitions.rollback
|
|
19
|
+
? [createRollbackJob(context, definitions.rollback)]
|
|
20
|
+
: []),
|
|
21
|
+
];
|
|
134
22
|
};
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import { ROLLBACK_JOB_NAME } from ".";
|
|
2
1
|
import type { Context } from "../../types/context";
|
|
3
|
-
import type {
|
|
2
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
4
3
|
import { DEPLOY_RUNNER_VARIABLES } from "./variables";
|
|
5
4
|
|
|
6
|
-
export const
|
|
5
|
+
export const ROLLBACK_JOB_NAME = "↩️ Rollback ⚠️";
|
|
6
|
+
|
|
7
|
+
export type RollbackJobDefinition = Pick<
|
|
8
|
+
CatladderJob,
|
|
9
|
+
"script" | "variables" | "image"
|
|
10
|
+
>;
|
|
11
|
+
export const createRollbackJob = (
|
|
12
|
+
context: Context,
|
|
13
|
+
jobDefinition: RollbackJobDefinition
|
|
14
|
+
): CatladderJob => {
|
|
7
15
|
return {
|
|
8
16
|
name: ROLLBACK_JOB_NAME,
|
|
17
|
+
image: jobDefinition.image,
|
|
9
18
|
envMode: "stagePerEnv", // makes it easier to run manual tasks er env
|
|
10
19
|
needs: [], // can be executed even if the deploy job failed
|
|
11
20
|
rules: [
|
|
@@ -18,11 +27,14 @@ export const getBaseRollbackJob = (context: Context): JobWithoutScript => {
|
|
|
18
27
|
...DEPLOY_RUNNER_VARIABLES,
|
|
19
28
|
...context.environment.jobOnlyVars.deploy.envVars,
|
|
20
29
|
GIT_STRATEGY: "none",
|
|
30
|
+
...jobDefinition.variables,
|
|
21
31
|
},
|
|
22
32
|
stage: "rollback",
|
|
23
33
|
environment: {
|
|
24
34
|
...context.environment.gitlabEnvironment,
|
|
25
35
|
action: "access",
|
|
26
36
|
},
|
|
37
|
+
|
|
38
|
+
script: jobDefinition.script,
|
|
27
39
|
};
|
|
28
40
|
};
|