@catladder/pipeline 1.146.1 → 1.147.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/createAppBuildJob.d.ts +2 -2
- package/dist/build/base/createAppBuildJob.js +6 -6
- package/dist/build/base/index.d.ts +2 -2
- package/dist/build/base/writeBuildInfo.d.ts +2 -2
- package/dist/build/base/writeBuildInfo.js +1 -1
- package/dist/build/base/writeDotEnv.d.ts +2 -2
- package/dist/build/base/writeDotEnv.js +1 -1
- package/dist/build/custom/__tests__/testJob.test.js +11 -14
- package/dist/build/custom/buildJob.d.ts +2 -2
- package/dist/build/custom/buildJob.js +5 -5
- package/dist/build/custom/index.d.ts +2 -2
- package/dist/build/custom/testJob.d.ts +2 -2
- package/dist/build/custom/testJob.js +5 -5
- package/dist/build/docker.d.ts +32 -15
- package/dist/build/docker.js +41 -20
- package/dist/build/index.d.ts +2 -2
- package/dist/build/node/buildJob.d.ts +2 -2
- package/dist/build/node/buildJob.js +8 -8
- package/dist/build/node/cache.d.ts +5 -5
- package/dist/build/node/cache.js +5 -5
- package/dist/build/node/index.d.ts +4 -4
- package/dist/build/node/meteor.d.ts +2 -2
- package/dist/build/node/meteor.js +6 -6
- package/dist/build/node/testJob.d.ts +2 -2
- package/dist/build/node/testJob.js +11 -11
- package/dist/build/node/yarn.d.ts +4 -4
- package/dist/build/node/yarn.js +1 -1
- package/dist/build/rails/build.d.ts +2 -2
- package/dist/build/rails/build.js +3 -3
- package/dist/build/rails/index.d.ts +2 -2
- package/dist/build/rails/test.d.ts +2 -2
- package/dist/build/rails/test.js +4 -4
- package/dist/build/sbom.d.ts +2 -2
- package/dist/build/sbom.js +2 -2
- package/dist/build/types.d.ts +34 -26
- package/dist/bundles/catladder-gitlab/index.js +2 -2
- package/dist/constants.js +1 -1
- package/dist/context/getEnvironment.d.ts +2 -2
- package/dist/context/getEnvironmentContext.d.ts +2 -2
- package/dist/context/getEnvironmentVariables.d.ts +4 -4
- package/dist/context/getLabels.d.ts +2 -2
- package/dist/context/getLabels.js +1 -1
- package/dist/context/index.d.ts +7 -3
- package/dist/context/index.js +43 -12
- package/dist/deploy/base/deploy.d.ts +2 -2
- package/dist/deploy/base/deploy.js +9 -8
- package/dist/deploy/base/index.d.ts +2 -2
- package/dist/deploy/base/rollback.d.ts +2 -2
- package/dist/deploy/base/stop.d.ts +2 -2
- package/dist/deploy/cloudRun/artifactsRegistry.d.ts +7 -11
- package/dist/deploy/cloudRun/artifactsRegistry.js +8 -9
- package/dist/deploy/cloudRun/cleanup.d.ts +2 -2
- package/dist/deploy/cloudRun/cloudRunRevisions.d.ts +2 -2
- package/dist/deploy/cloudRun/cloudRunRevisions.js +4 -5
- package/dist/deploy/cloudRun/createJobs/cloudRunJobs.d.ts +6 -6
- package/dist/deploy/cloudRun/createJobs/cloudRunServices.d.ts +3 -3
- package/dist/deploy/cloudRun/createJobs/cloudRunServices.js +1 -1
- package/dist/deploy/cloudRun/createJobs/common.js +2 -1
- package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.d.ts +2 -2
- package/dist/deploy/cloudRun/createJobs/getCloudRunStopScripts.d.ts +2 -2
- package/dist/deploy/cloudRun/createJobs/index.d.ts +2 -2
- package/dist/deploy/cloudRun/createJobs/index.js +2 -4
- package/dist/deploy/cloudRun/utils/database.d.ts +3 -3
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.d.ts +2 -2
- package/dist/deploy/cloudRun/utils/getServiceName.d.ts +2 -2
- package/dist/deploy/custom/deployJob.d.ts +2 -2
- package/dist/deploy/custom/deployJob.js +7 -10
- package/dist/deploy/dockerTag/deployJob.d.ts +2 -2
- package/dist/deploy/dockerTag/deployJob.js +3 -5
- package/dist/deploy/index.d.ts +2 -2
- package/dist/deploy/kubernetes/cloudSql/index.d.ts +3 -3
- package/dist/deploy/kubernetes/cloudSql/index.js +11 -9
- package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
- package/dist/deploy/kubernetes/deployJob.js +4 -7
- package/dist/deploy/kubernetes/kubeEnv.d.ts +2 -2
- package/dist/deploy/kubernetes/kubeEnv.js +2 -1
- package/dist/deploy/kubernetes/kubeValues.d.ts +2 -2
- package/dist/deploy/kubernetes/kubeValues.js +10 -10
- package/dist/deploy/kubernetes/mongodb.d.ts +2 -2
- package/dist/deploy/kubernetes/mongodb.js +11 -11
- package/dist/deploy/sbom.d.ts +4 -4
- package/dist/deploy/sbom.js +1 -1
- package/dist/deploy/types/index.d.ts +1 -1
- package/dist/deploy/types/index.js +1 -1
- package/dist/deploy/utils.d.ts +2 -2
- package/dist/deploy/utils.js +2 -1
- package/dist/pipeline/createJobsForComponent.d.ts +2 -2
- package/dist/pipeline/createJobsForComponent.js +6 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +2 -2
- package/dist/types/context.d.ts +28 -2
- package/examples/__snapshots__/cloud-run-storybook.ts.snap +1687 -0
- package/examples/__snapshots__/cloud-run-with-ngnix.ts.snap +1971 -0
- package/examples/cloud-run-storybook.ts +24 -0
- package/examples/cloud-run-with-ngnix.ts +24 -0
- package/package.json +1 -1
- package/src/build/base/createAppBuildJob.ts +9 -9
- package/src/build/base/index.ts +2 -2
- package/src/build/base/writeBuildInfo.ts +3 -3
- package/src/build/base/writeDotEnv.ts +3 -3
- package/src/build/custom/__tests__/testJob.test.ts +8 -11
- package/src/build/custom/buildJob.ts +10 -11
- package/src/build/custom/index.ts +2 -2
- package/src/build/custom/testJob.ts +9 -7
- package/src/build/docker.ts +73 -29
- package/src/build/index.ts +2 -2
- package/src/build/node/buildJob.ts +19 -15
- package/src/build/node/cache.ts +10 -10
- package/src/build/node/index.ts +6 -4
- package/src/build/node/meteor.ts +16 -17
- package/src/build/node/testJob.ts +19 -16
- package/src/build/node/yarn.ts +6 -8
- package/src/build/rails/build.ts +7 -5
- package/src/build/rails/index.ts +2 -2
- package/src/build/rails/test.ts +8 -6
- package/src/build/sbom.ts +5 -5
- package/src/build/types.ts +53 -38
- package/src/context/getEnvironment.ts +2 -2
- package/src/context/getEnvironmentContext.ts +2 -2
- package/src/context/getEnvironmentVariables.ts +7 -4
- package/src/context/getLabels.ts +3 -3
- package/src/context/index.ts +33 -7
- package/src/deploy/base/deploy.ts +10 -16
- package/src/deploy/base/index.ts +2 -2
- package/src/deploy/base/rollback.ts +2 -2
- package/src/deploy/base/stop.ts +2 -2
- package/src/deploy/cloudRun/artifactsRegistry.ts +16 -16
- package/src/deploy/cloudRun/cleanup.ts +2 -2
- package/src/deploy/cloudRun/cloudRunRevisions.ts +6 -8
- package/src/deploy/cloudRun/createJobs/cloudRunJobs.ts +10 -10
- package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +4 -4
- package/src/deploy/cloudRun/createJobs/common.ts +1 -1
- package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +5 -2
- package/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.ts +2 -2
- package/src/deploy/cloudRun/createJobs/index.ts +3 -6
- package/src/deploy/cloudRun/utils/database.ts +3 -3
- package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +4 -2
- package/src/deploy/cloudRun/utils/getServiceName.ts +2 -2
- package/src/deploy/custom/deployJob.ts +10 -8
- package/src/deploy/dockerTag/deployJob.ts +6 -7
- package/src/deploy/index.ts +2 -2
- package/src/deploy/kubernetes/cloudSql/index.ts +10 -7
- package/src/deploy/kubernetes/deployJob.ts +3 -6
- package/src/deploy/kubernetes/kubeEnv.ts +3 -3
- package/src/deploy/kubernetes/kubeValues.ts +6 -6
- package/src/deploy/kubernetes/mongodb.ts +14 -14
- package/src/deploy/sbom.ts +9 -6
- package/src/deploy/types/index.ts +2 -2
- package/src/deploy/utils.ts +3 -3
- package/src/pipeline/createJobsForComponent.ts +17 -17
- package/src/pipeline/gitlab/createGitlabJobs.ts +2 -2
- package/src/types/config.ts +4 -2
- package/src/types/context.ts +33 -2
package/src/context/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { isFunction } from "lodash";
|
|
1
2
|
import { BUILD_TYPES } from "../build";
|
|
2
3
|
import type { BuildConfig, BuildConfigType } from "../build/types";
|
|
3
4
|
import { DEPLOY_TYPES } from "../deploy";
|
|
4
5
|
import type { DeployConfig, DeployConfigType } from "../deploy/types";
|
|
5
6
|
import type { PipelineType } from "../types";
|
|
6
7
|
import type { Config, PipelineTrigger } from "../types/config";
|
|
7
|
-
import type {
|
|
8
|
+
import type { ComponentContext, PackageManagerInfo } from "../types/context";
|
|
8
9
|
import type { PartialDeep } from "../types/utils";
|
|
9
10
|
import { mergeWithMergingArrays } from "../utils";
|
|
10
11
|
import { getEnvironment } from "./getEnvironment";
|
|
@@ -13,7 +14,7 @@ import { getEnvironmentContext } from "./getEnvironmentContext";
|
|
|
13
14
|
export * from "./getEnvironment";
|
|
14
15
|
export * from "./getEnvironmentVariables";
|
|
15
16
|
|
|
16
|
-
export type
|
|
17
|
+
export type CreateComponentContextContext = {
|
|
17
18
|
config: Config;
|
|
18
19
|
componentName: string;
|
|
19
20
|
env: string;
|
|
@@ -22,9 +23,9 @@ export type CreateContextContext = {
|
|
|
22
23
|
packageManagerInfo?: PackageManagerInfo;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
export const
|
|
26
|
-
ctx:
|
|
27
|
-
): Promise<
|
|
26
|
+
export const createComponentContext = async (
|
|
27
|
+
ctx: CreateComponentContextContext,
|
|
28
|
+
): Promise<ComponentContext> => {
|
|
28
29
|
if (!/^[a-z0-9-]+$/.test(ctx.componentName)) {
|
|
29
30
|
throw new Error(
|
|
30
31
|
"componentName may only contain lower case letters, numbers and -",
|
|
@@ -56,13 +57,38 @@ export const createContext = async (
|
|
|
56
57
|
componentConfigWithoutDefaults,
|
|
57
58
|
);
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
const environment = await getEnvironment(ctx);
|
|
61
|
+
const { deploy, build, customJobs, dir } = componentConfig;
|
|
62
|
+
const context: Omit<ComponentContext, "customJobs"> = {
|
|
60
63
|
fullConfig: ctx.config,
|
|
61
64
|
componentConfig,
|
|
65
|
+
|
|
66
|
+
build: {
|
|
67
|
+
dir: dir,
|
|
68
|
+
packageManagerInfo: ctx.packageManagerInfo,
|
|
69
|
+
config: build,
|
|
70
|
+
},
|
|
71
|
+
deploy: deploy
|
|
72
|
+
? {
|
|
73
|
+
config: deploy,
|
|
74
|
+
}
|
|
75
|
+
: null,
|
|
62
76
|
componentName: ctx.componentName,
|
|
63
|
-
environment
|
|
77
|
+
environment,
|
|
64
78
|
packageManagerInfo: ctx.packageManagerInfo,
|
|
65
79
|
pipelineType: ctx.pipelineType,
|
|
66
80
|
trigger: ctx.trigger,
|
|
67
81
|
};
|
|
82
|
+
const resolvedCustomJobs = isFunction(customJobs)
|
|
83
|
+
? customJobs(context)
|
|
84
|
+
: customJobs;
|
|
85
|
+
return {
|
|
86
|
+
...context,
|
|
87
|
+
customJobs: resolvedCustomJobs,
|
|
88
|
+
};
|
|
68
89
|
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @deprecated use createComponentContext instead
|
|
93
|
+
*/
|
|
94
|
+
export const createContext = createComponentContext;
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
requiresDockerBuild,
|
|
4
4
|
} from "../../build/docker";
|
|
5
5
|
import { SBOM_BUILD_JOB_NAME } from "../../build/sbom";
|
|
6
|
-
import type {
|
|
6
|
+
import type { ComponentContext } from "../../types/context";
|
|
7
7
|
import type { CatladderJob } from "../../types/jobs";
|
|
8
8
|
import { sbomDeactivated } from "../sbom";
|
|
9
9
|
import { contextIsStoppable } from "../utils";
|
|
@@ -24,7 +24,7 @@ export type DeployJobDefinition = Pick<
|
|
|
24
24
|
| "runnerVariables"
|
|
25
25
|
>;
|
|
26
26
|
export const createDeployJob = (
|
|
27
|
-
context:
|
|
27
|
+
context: ComponentContext,
|
|
28
28
|
jobDefinition: DeployJobDefinition,
|
|
29
29
|
): CatladderJob => {
|
|
30
30
|
const hasDocker = requiresDockerBuild(context);
|
|
@@ -37,11 +37,11 @@ export const createDeployJob = (
|
|
|
37
37
|
? "4 weeks"
|
|
38
38
|
: undefined;
|
|
39
39
|
|
|
40
|
+
const deployConfig = context.deploy?.config;
|
|
41
|
+
|
|
40
42
|
// if auto or manual is configured explicitly, use that
|
|
41
43
|
const whenDeployDefined =
|
|
42
|
-
|
|
43
|
-
? context.componentConfig.deploy.when
|
|
44
|
-
: undefined;
|
|
44
|
+
deployConfig && deployConfig.when ? deployConfig.when : undefined;
|
|
45
45
|
// otherwise auto deploy if env is not prod. If its prod, deploy automatically if stage is disabled
|
|
46
46
|
const whenDeployDefault =
|
|
47
47
|
context.environment.envType !== "prod"
|
|
@@ -64,8 +64,8 @@ export const createDeployJob = (
|
|
|
64
64
|
...(sbomDeactivated(context)
|
|
65
65
|
? []
|
|
66
66
|
: [{ job: SBOM_BUILD_JOB_NAME, artifacts: true }]),
|
|
67
|
-
...(
|
|
68
|
-
?
|
|
67
|
+
...(deployConfig
|
|
68
|
+
? deployConfig.waitFor?.map((c) => ({
|
|
69
69
|
componentName: c,
|
|
70
70
|
job: DEPLOY_JOB_NAME,
|
|
71
71
|
artifacts: false,
|
|
@@ -91,17 +91,13 @@ export const createDeployJob = (
|
|
|
91
91
|
...context.environment.envVars,
|
|
92
92
|
...(hasDocker ? getDockerImageVariables(context) : {}),
|
|
93
93
|
...context.environment.jobOnlyVars.deploy.envVars,
|
|
94
|
-
...(
|
|
95
|
-
? context.componentConfig.deploy.extraVars ?? {}
|
|
96
|
-
: {}),
|
|
94
|
+
...(deployConfig ? deployConfig.extraVars ?? {} : {}),
|
|
97
95
|
...jobDefinition.variables,
|
|
98
96
|
},
|
|
99
97
|
runnerVariables: {
|
|
100
98
|
...DEPLOY_RUNNER_VARIABLES,
|
|
101
99
|
...(jobDefinition.runnerVariables ?? {}),
|
|
102
|
-
...(
|
|
103
|
-
? context.componentConfig.deploy.runnerVariables ?? {}
|
|
104
|
-
: {}),
|
|
100
|
+
...(deployConfig ? deployConfig.runnerVariables ?? {} : {}),
|
|
105
101
|
},
|
|
106
102
|
environment: isStoppable
|
|
107
103
|
? {
|
|
@@ -109,8 +105,6 @@ export const createDeployJob = (
|
|
|
109
105
|
auto_stop_in: autoStop,
|
|
110
106
|
}
|
|
111
107
|
: undefined,
|
|
112
|
-
jobTags:
|
|
113
|
-
? context.componentConfig.deploy.jobTags
|
|
114
|
-
: undefined,
|
|
108
|
+
jobTags: deployConfig ? deployConfig.jobTags : undefined,
|
|
115
109
|
};
|
|
116
110
|
};
|
package/src/deploy/base/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentContext } from "../../types/context";
|
|
2
2
|
import type { CatladderJob } from "../../types/jobs";
|
|
3
3
|
import { createDeployJob, type DeployJobDefinition } from "./deploy";
|
|
4
4
|
import { createRollbackJob, type RollbackJobDefinition } from "./rollback";
|
|
5
5
|
import { createStopJob, type StopJobDefinition } from "./stop";
|
|
6
6
|
|
|
7
7
|
export const createDeployementJobs = (
|
|
8
|
-
context:
|
|
8
|
+
context: ComponentContext,
|
|
9
9
|
definitions: {
|
|
10
10
|
deploy: DeployJobDefinition;
|
|
11
11
|
stop?: StopJobDefinition;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentContext } from "../../types/context";
|
|
2
2
|
import type { CatladderJob } from "../../types/jobs";
|
|
3
3
|
import { DEPLOY_RUNNER_VARIABLES } from "./variables";
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ export type RollbackJobDefinition = Pick<
|
|
|
9
9
|
"script" | "variables" | "runnerVariables" | "image"
|
|
10
10
|
>;
|
|
11
11
|
export const createRollbackJob = (
|
|
12
|
-
context:
|
|
12
|
+
context: ComponentContext,
|
|
13
13
|
jobDefinition: RollbackJobDefinition,
|
|
14
14
|
): CatladderJob => {
|
|
15
15
|
return {
|
package/src/deploy/base/stop.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentContext } from "../../types/context";
|
|
2
2
|
import type { CatladderJob } from "../../types/jobs";
|
|
3
3
|
|
|
4
4
|
import { DEPLOY_RUNNER_VARIABLES } from "./variables";
|
|
@@ -9,7 +9,7 @@ export type StopJobDefinition = Pick<
|
|
|
9
9
|
"script" | "variables" | "image" | "runnerVariables"
|
|
10
10
|
>;
|
|
11
11
|
export const createStopJob = (
|
|
12
|
-
context:
|
|
12
|
+
context: ComponentContext,
|
|
13
13
|
jobDefinition: StopJobDefinition,
|
|
14
14
|
): CatladderJob => {
|
|
15
15
|
return {
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import type { StringOrBashExpression } from "../../bash/BashExpression";
|
|
2
2
|
import { joinBashExpressions } from "../../bash/BashExpression";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ComponentContext } from "../../types/context";
|
|
4
4
|
import { allowFailureInScripts } from "../../utils/gitlab";
|
|
5
5
|
import { isOfDeployType } from "../types";
|
|
6
6
|
import { removeFirstLinesFromCommandOutput } from "./utils/removeFirstLinesFromCommandOutput";
|
|
7
7
|
|
|
8
|
-
export const getArtifactsRegistryHost = ({
|
|
9
|
-
|
|
10
|
-
}: Context) => {
|
|
11
|
-
if (!isOfDeployType(deploy, "google-cloudrun")) {
|
|
8
|
+
export const getArtifactsRegistryHost = (context: ComponentContext) => {
|
|
9
|
+
if (!isOfDeployType(context.deploy?.config, "google-cloudrun")) {
|
|
12
10
|
// should not happen
|
|
13
11
|
throw new Error("deploy config is wrong");
|
|
14
12
|
}
|
|
15
|
-
return `${deploy.region}-docker.pkg.dev`;
|
|
13
|
+
return `${context.deploy.config.region}-docker.pkg.dev`;
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
export const getArtifactsRegistryDockerUrl = (context:
|
|
19
|
-
const deployConfig = context.
|
|
16
|
+
export const getArtifactsRegistryDockerUrl = (context: ComponentContext) => {
|
|
17
|
+
const deployConfig = context.deploy?.config;
|
|
20
18
|
|
|
21
19
|
if (!isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
22
20
|
// should not happen
|
|
@@ -35,7 +33,7 @@ export const getArtifactsRegistryDockerUrl = (context: Context) => {
|
|
|
35
33
|
* lecacyReviewImageName is only temporary. In old versions the images had no reviewslug in review apps, which makes cleanup harder. We delete all those images now, but need the path
|
|
36
34
|
*/
|
|
37
35
|
export const getArtifactsRegistryImageName = (
|
|
38
|
-
context:
|
|
36
|
+
context: ComponentContext,
|
|
39
37
|
lecacyReviewImageName = false,
|
|
40
38
|
) => {
|
|
41
39
|
if (lecacyReviewImageName && context.environment.envType !== "review") {
|
|
@@ -55,14 +53,16 @@ export const getArtifactsRegistryImageName = (
|
|
|
55
53
|
return joinBashExpressions(gcloudImagePath, "/");
|
|
56
54
|
};
|
|
57
55
|
|
|
58
|
-
export const getArtifactsRegistryBuildCacheImage = (
|
|
56
|
+
export const getArtifactsRegistryBuildCacheImage = (
|
|
57
|
+
context: ComponentContext,
|
|
58
|
+
) => {
|
|
59
59
|
const dockerUrl = getArtifactsRegistryDockerUrl(context);
|
|
60
60
|
// does not include env, so that after merge, you might get more cache hits (review-->dev)
|
|
61
61
|
const gcloudImagePath = [dockerUrl, "caches", context.componentName];
|
|
62
62
|
return gcloudImagePath.join("/");
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
export const getArtifactsRegistryImage = (context:
|
|
65
|
+
export const getArtifactsRegistryImage = (context: ComponentContext) =>
|
|
66
66
|
`${getArtifactsRegistryImageName(context)}:$DOCKER_IMAGE_TAG`;
|
|
67
67
|
|
|
68
68
|
const getDeleteImageCommands = (
|
|
@@ -96,11 +96,11 @@ const getDeleteImageCommands = (
|
|
|
96
96
|
* @param keep how many of the newest images to keep
|
|
97
97
|
* @returns
|
|
98
98
|
*/
|
|
99
|
-
export const getDeleteUnusedImagesCommands = (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
export const getDeleteUnusedImagesCommands = (
|
|
100
|
+
context: ComponentContext,
|
|
101
|
+
keep = 0,
|
|
102
|
+
) => {
|
|
103
|
+
const deployConfig = context.deploy?.config;
|
|
104
104
|
if (!isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
105
105
|
// should not happen
|
|
106
106
|
throw new Error("deploy config is wrong");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentContext } from "../../types/context";
|
|
2
2
|
import { getDeleteUnusedImagesCommands } from "./artifactsRegistry";
|
|
3
3
|
import { getDeleteUnusedRevisionsCommands } from "./cloudRunRevisions";
|
|
4
4
|
|
|
5
5
|
export const getRemoveOldRevisionsAndImagesCommand = (
|
|
6
|
-
context:
|
|
6
|
+
context: ComponentContext,
|
|
7
7
|
when: "postDeploy" | "onStop",
|
|
8
8
|
) => {
|
|
9
9
|
if (when === "onStop") {
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentContext } from "../../types/context";
|
|
2
2
|
import { isOfDeployType } from "../types";
|
|
3
3
|
import { createArgsString } from "./utils/createArgsString";
|
|
4
4
|
import { getServiceName } from "./utils/getServiceName";
|
|
5
5
|
import { removeFirstLinesFromCommandOutput } from "./utils/removeFirstLinesFromCommandOutput";
|
|
6
6
|
|
|
7
7
|
const getListRevisionsCommand = (
|
|
8
|
-
context:
|
|
8
|
+
context: ComponentContext,
|
|
9
9
|
args: {
|
|
10
10
|
filter?: string;
|
|
11
11
|
format: string;
|
|
12
12
|
},
|
|
13
13
|
) => {
|
|
14
14
|
const serviceName = getServiceName(context);
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
const deployConfig = context.deploy?.config;
|
|
16
17
|
|
|
17
18
|
if (!deployConfig || !isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
18
19
|
// should not happen
|
|
@@ -34,13 +35,10 @@ const getListRevisionsCommand = (
|
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
export const getDeleteUnusedRevisionsCommands = (
|
|
37
|
-
context:
|
|
38
|
+
context: ComponentContext,
|
|
38
39
|
keep: number,
|
|
39
40
|
) => {
|
|
40
|
-
const deployConfig = context.
|
|
41
|
-
if (deployConfig === false) {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
41
|
+
const deployConfig = context.deploy?.config;
|
|
44
42
|
if (!isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
45
43
|
// should not happen
|
|
46
44
|
throw new Error("deploy config is wrong");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentContext } from "../../../types/context";
|
|
2
2
|
import { allowFailureInScripts } from "../../../utils/gitlab";
|
|
3
3
|
|
|
4
4
|
import type {
|
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
import { ENV_VARS_FILENAME } from "./constants";
|
|
25
25
|
|
|
26
26
|
const getJobRunScriptForJob = (
|
|
27
|
-
context:
|
|
27
|
+
context: ComponentContext,
|
|
28
28
|
jobName: StringOrBashExpression,
|
|
29
29
|
wait: boolean,
|
|
30
30
|
) => {
|
|
@@ -36,7 +36,7 @@ const getJobRunScriptForJob = (
|
|
|
36
36
|
}`;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
export const getDeleteSchedulesScripts = (context:
|
|
39
|
+
export const getDeleteSchedulesScripts = (context: ComponentContext) => {
|
|
40
40
|
const deployConfig = getCloudRunDeployConfig(context);
|
|
41
41
|
const jobsWithSchedule = getCloudRunJobsWithSchedule(context);
|
|
42
42
|
const argsString = createArgsString({
|
|
@@ -52,7 +52,7 @@ export const getDeleteSchedulesScripts = (context: Context) => {
|
|
|
52
52
|
.flat();
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
export const getDeleteJobsScripts = (context:
|
|
55
|
+
export const getDeleteJobsScripts = (context: ComponentContext) => {
|
|
56
56
|
const commonArgs = getCommonCloudRunArgs(context);
|
|
57
57
|
const commonArgsString = createArgsString(commonArgs);
|
|
58
58
|
const jobsWithNames = getCloudRunJobsWithNames(context);
|
|
@@ -65,7 +65,7 @@ export const getDeleteJobsScripts = (context: Context) => {
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
export const getJobRunScripts = (
|
|
68
|
-
context:
|
|
68
|
+
context: ComponentContext,
|
|
69
69
|
when: DeployConfigCloudRunJob["when"],
|
|
70
70
|
) => {
|
|
71
71
|
const jobsWithNames = getCloudRunJobsWithNames(context);
|
|
@@ -81,7 +81,7 @@ export const getJobRunScripts = (
|
|
|
81
81
|
);
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
export const getJobCreateScripts = (context:
|
|
84
|
+
export const getJobCreateScripts = (context: ComponentContext) => {
|
|
85
85
|
const jobsWithNames = getCloudRunJobsWithNames(context);
|
|
86
86
|
|
|
87
87
|
return jobsWithNames
|
|
@@ -90,7 +90,7 @@ export const getJobCreateScripts = (context: Context) => {
|
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
const getJobCreateScriptsForJob = (
|
|
93
|
-
context:
|
|
93
|
+
context: ComponentContext,
|
|
94
94
|
jobName: StringOrBashExpression,
|
|
95
95
|
job: DeployConfigCloudRunJob,
|
|
96
96
|
) => {
|
|
@@ -132,7 +132,7 @@ const getJobCreateScriptsForJob = (
|
|
|
132
132
|
];
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
export const getCreateScheduleScripts = (context:
|
|
135
|
+
export const getCreateScheduleScripts = (context: ComponentContext) => {
|
|
136
136
|
const jobsWithSchedule = getCloudRunJobsWithSchedule(context);
|
|
137
137
|
const deployConfig = getCloudRunDeployConfig(context);
|
|
138
138
|
|
|
@@ -160,7 +160,7 @@ export const getCreateScheduleScripts = (context: Context) => {
|
|
|
160
160
|
.flat();
|
|
161
161
|
};
|
|
162
162
|
|
|
163
|
-
const getCloudRunJobsWithSchedule = (context:
|
|
163
|
+
const getCloudRunJobsWithSchedule = (context: ComponentContext) => {
|
|
164
164
|
const jobsWithNames = getCloudRunJobsWithNames(context);
|
|
165
165
|
|
|
166
166
|
return jobsWithNames
|
|
@@ -179,7 +179,7 @@ const getCloudRunJobsWithSchedule = (context: Context) => {
|
|
|
179
179
|
}));
|
|
180
180
|
};
|
|
181
181
|
|
|
182
|
-
const getCloudRunJobsWithNames = (context:
|
|
182
|
+
const getCloudRunJobsWithNames = (context: ComponentContext) => {
|
|
183
183
|
const deployConfig = getCloudRunDeployConfig(context);
|
|
184
184
|
|
|
185
185
|
const getFullJobName = (name: string) =>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getLabels } from "../../../context/getLabels";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ComponentContext } from "../../../types/context";
|
|
3
3
|
|
|
4
4
|
import type { DeployConfigCloudRunService } from "../../types/googleCloudRun";
|
|
5
5
|
import { createArgsString } from "../utils/createArgsString";
|
|
@@ -14,7 +14,7 @@ import { ENV_VARS_FILENAME } from "./constants";
|
|
|
14
14
|
import { createVolumeConfig } from "./volumes";
|
|
15
15
|
|
|
16
16
|
export const getServiceDeployScript = (
|
|
17
|
-
context:
|
|
17
|
+
context: ComponentContext,
|
|
18
18
|
service: DeployConfigCloudRunService | true | undefined,
|
|
19
19
|
nameSuffix?: string,
|
|
20
20
|
) => {
|
|
@@ -25,7 +25,7 @@ export const getServiceDeployScript = (
|
|
|
25
25
|
const customConfig = service !== true ? service : undefined;
|
|
26
26
|
const command =
|
|
27
27
|
service !== true
|
|
28
|
-
? service?.command ?? context.
|
|
28
|
+
? service?.command ?? context.build.config.startCommand
|
|
29
29
|
: undefined;
|
|
30
30
|
|
|
31
31
|
const commandArray = command
|
|
@@ -66,7 +66,7 @@ export const getServiceDeployScript = (
|
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
export const getServiceDeleteScript = (
|
|
69
|
-
context:
|
|
69
|
+
context: ComponentContext,
|
|
70
70
|
serviceSuffix?: string,
|
|
71
71
|
) => {
|
|
72
72
|
const commonArgs = getCommonCloudRunArgs(context);
|
|
@@ -30,7 +30,7 @@ export const makeLabelString = (obj: Record<string, unknown>) =>
|
|
|
30
30
|
.join(",");
|
|
31
31
|
|
|
32
32
|
export const getCloudRunDeployConfig = (context: Context) => {
|
|
33
|
-
const deployConfig = context.
|
|
33
|
+
const deployConfig = context.deploy?.config;
|
|
34
34
|
if (!isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
35
35
|
// should not happen
|
|
36
36
|
throw new Error("deploy config is wrong");
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { isNil, omit } from "lodash";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
ComponentContext,
|
|
4
|
+
UnspecifiedEnvVars,
|
|
5
|
+
} from "../../../types/context";
|
|
3
6
|
import { collapseableSection } from "../../../utils/gitlab";
|
|
4
7
|
import { getDependencyTrackUploadScript } from "../../sbom";
|
|
5
8
|
|
|
@@ -25,7 +28,7 @@ import {
|
|
|
25
28
|
yamlBashString,
|
|
26
29
|
} from "../../../bash/bashYaml";
|
|
27
30
|
|
|
28
|
-
export function getCloudRunDeployScripts(context:
|
|
31
|
+
export function getCloudRunDeployScripts(context: ComponentContext) {
|
|
29
32
|
const deployConfig = getCloudRunDeployConfig(context);
|
|
30
33
|
const allEnvVars = omit(
|
|
31
34
|
context.environment.envVars,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentContext } from "../../../types/context";
|
|
2
2
|
import { getDependencyTrackDeleteScript } from "../../sbom";
|
|
3
3
|
|
|
4
4
|
import { getRemoveOldRevisionsAndImagesCommand } from "../cleanup";
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import { getServiceDeleteScript } from "./cloudRunServices";
|
|
13
13
|
import { getCloudRunDeployConfig } from "./common";
|
|
14
14
|
|
|
15
|
-
export function getCloudRunStopScripts(context:
|
|
15
|
+
export function getCloudRunStopScripts(context: ComponentContext) {
|
|
16
16
|
const deployConfig = getCloudRunDeployConfig(context);
|
|
17
17
|
return [
|
|
18
18
|
...gcloudServiceAccountLoginCommands(context),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getRunnerImage } from "../../../runner";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ComponentContext } from "../../../types/context";
|
|
3
3
|
import type { CatladderJob } from "../../../types/jobs";
|
|
4
4
|
import { allowFailureInScripts } from "../../../utils/gitlab";
|
|
5
5
|
import { createDeployementJobs } from "../../base";
|
|
@@ -10,12 +10,9 @@ import { getCloudRunDeployScripts } from "./getCloudRunDeployScripts";
|
|
|
10
10
|
import { getCloudRunStopScripts } from "./getCloudRunStopScripts";
|
|
11
11
|
|
|
12
12
|
export const createGoogleCloudRunDeployJobs = (
|
|
13
|
-
context:
|
|
13
|
+
context: ComponentContext,
|
|
14
14
|
): CatladderJob[] => {
|
|
15
|
-
const deployConfig = context.
|
|
16
|
-
if (deployConfig === false) {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
15
|
+
const deployConfig = context.deploy?.config;
|
|
19
16
|
if (!isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
20
17
|
// should not happen
|
|
21
18
|
throw new Error("deploy config is wrong");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentContext } from "../../../types";
|
|
2
2
|
import { allowFailureInScripts, repeatOnFailure } from "../../../utils/gitlab";
|
|
3
3
|
import type {
|
|
4
4
|
DeployConfigCloudRun,
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
} from "../../types";
|
|
7
7
|
|
|
8
8
|
export const getDatabaseDeleteScript = (
|
|
9
|
-
context:
|
|
9
|
+
context: ComponentContext,
|
|
10
10
|
deployConfig: DeployConfigCloudRun,
|
|
11
11
|
): string[] => {
|
|
12
12
|
if (!deployConfig.cloudSql || !deployConfig.cloudSql.deleteDatabaseOnStop) {
|
|
@@ -35,7 +35,7 @@ export const getDatabaseDeleteScript = (
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
export const getDatabaseCreateScript = (
|
|
38
|
-
context:
|
|
38
|
+
context: ComponentContext,
|
|
39
39
|
deployConfig: DeployConfigCloudRun,
|
|
40
40
|
): string[] => {
|
|
41
41
|
if (!deployConfig.cloudSql) {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { GCLOUD_DEPLOY_CREDENTIALS_KEY } from "..";
|
|
2
2
|
import { getSecretVarNameForContext } from "../../../context";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ComponentContext } from "../../../types";
|
|
4
4
|
|
|
5
|
-
export const gcloudServiceAccountLoginCommands = (
|
|
5
|
+
export const gcloudServiceAccountLoginCommands = (
|
|
6
|
+
context: ComponentContext,
|
|
7
|
+
) => [
|
|
6
8
|
`gcloud auth activate-service-account --key-file=<(echo "$${getSecretVarNameForContext(
|
|
7
9
|
context,
|
|
8
10
|
GCLOUD_DEPLOY_CREDENTIALS_KEY,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export const getServiceName = (context:
|
|
1
|
+
import type { ComponentContext } from "../../../types/context";
|
|
2
|
+
export const getServiceName = (context: ComponentContext) =>
|
|
3
3
|
context.environment.fullName.toLowerCase();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getYarnInstall } from "../../build/node/yarn";
|
|
2
2
|
import { getRunnerImage } from "../../runner";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ComponentContext } from "../../types/context";
|
|
4
4
|
import type { CatladderJob } from "../../types/jobs";
|
|
5
5
|
import { createDeployementJobs } from "../base";
|
|
6
6
|
import {
|
|
@@ -9,23 +9,25 @@ import {
|
|
|
9
9
|
} from "../sbom";
|
|
10
10
|
import { isOfDeployType } from "../types";
|
|
11
11
|
|
|
12
|
-
export const createCustomDeployJobs = (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
export const createCustomDeployJobs = (
|
|
13
|
+
context: ComponentContext,
|
|
14
|
+
): CatladderJob[] => {
|
|
15
|
+
const deployConfig = context.deploy?.config;
|
|
16
|
+
|
|
17
17
|
if (!isOfDeployType(deployConfig, "custom")) {
|
|
18
18
|
// should not happen
|
|
19
19
|
throw new Error("deploy config is not custom");
|
|
20
20
|
}
|
|
21
21
|
// FIXME: custom deploy currently assumes yarn-based project
|
|
22
|
-
const yarnInstall = getYarnInstall(context, {
|
|
22
|
+
const yarnInstall = getYarnInstall(context.build, {
|
|
23
|
+
noCustomPostInstall: true,
|
|
24
|
+
});
|
|
23
25
|
return createDeployementJobs(context, {
|
|
24
26
|
deploy: {
|
|
25
27
|
image: deployConfig.jobImage ?? getRunnerImage("jobs-default"),
|
|
26
28
|
cache: deployConfig.jobCache ?? [],
|
|
27
29
|
script: [
|
|
28
|
-
`cd ${context.
|
|
30
|
+
`cd ${context.build.dir}`,
|
|
29
31
|
...(deployConfig.requiresYarnInstall ? yarnInstall : []),
|
|
30
32
|
...deployConfig.script,
|
|
31
33
|
...getDependencyTrackUploadScript(context),
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { getDockerJobBaseProps, gitlabDockerLogin } from "../../build/docker";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { ComponentContext } from "../../types/context";
|
|
4
4
|
import type { CatladderJob } from "../../types/jobs";
|
|
5
5
|
import { createDeployementJobs } from "../base";
|
|
6
6
|
import { isOfDeployType } from "../types";
|
|
7
7
|
|
|
8
|
-
export const createDockerTagDeployJobs = (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
8
|
+
export const createDockerTagDeployJobs = (
|
|
9
|
+
context: ComponentContext,
|
|
10
|
+
): CatladderJob[] => {
|
|
11
|
+
const deployConfig = context.deploy?.config;
|
|
13
12
|
if (!isOfDeployType(deployConfig, "dockerTag")) {
|
|
14
13
|
// should not happen
|
|
15
14
|
throw new Error("deploy config is not dockerTag");
|
|
@@ -17,7 +16,7 @@ export const createDockerTagDeployJobs = (context: Context): CatladderJob[] => {
|
|
|
17
16
|
const tag = deployConfig.tag;
|
|
18
17
|
return createDeployementJobs(context, {
|
|
19
18
|
deploy: {
|
|
20
|
-
...getDockerJobBaseProps(
|
|
19
|
+
...getDockerJobBaseProps(),
|
|
21
20
|
script: [
|
|
22
21
|
...gitlabDockerLogin(context),
|
|
23
22
|
`docker pull $DOCKER_IMAGE:$DOCKER_IMAGE_TAG`,
|
package/src/deploy/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SecretEnvVar } from "..";
|
|
2
2
|
import type { BashExpression } from "../bash/BashExpression";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ComponentContext } from "../types/context";
|
|
4
4
|
import type { EnvironmentContext } from "../types/environmentContext";
|
|
5
5
|
import type { CatladderJob } from "../types/jobs";
|
|
6
6
|
import type { PartialDeep } from "../types/utils";
|
|
@@ -15,7 +15,7 @@ export * from "./types";
|
|
|
15
15
|
export * from "./utils";
|
|
16
16
|
|
|
17
17
|
export type DeployTypeDefinition<T extends DeployConfigType> = {
|
|
18
|
-
jobs: (context:
|
|
18
|
+
jobs: (context: ComponentContext) => CatladderJob[];
|
|
19
19
|
defaults: (
|
|
20
20
|
envContext: EnvironmentContext<any, T>,
|
|
21
21
|
) => PartialDeep<DeployConfigGeneric<T>>;
|