@catladder/pipeline 0.0.0-refactor-docker-9fda97e9 → 0.0.0-refactor-docker-c24f8608
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 +1 -1
- package/dist/build/base/index.d.ts +2 -2
- package/dist/build/base/writeBuildInfo.d.ts +2 -2
- package/dist/build/base/writeDotEnv.d.ts +2 -2
- package/dist/build/custom/buildJob.d.ts +2 -2
- package/dist/build/custom/index.d.ts +2 -2
- package/dist/build/custom/testJob.d.ts +2 -2
- package/dist/build/docker.d.ts +11 -11
- package/dist/build/docker.js +6 -6
- package/dist/build/index.d.ts +2 -2
- package/dist/build/node/buildJob.d.ts +2 -2
- package/dist/build/node/buildJob.js +7 -7
- package/dist/build/node/cache.d.ts +5 -5
- package/dist/build/node/cache.js +4 -4
- package/dist/build/node/index.d.ts +4 -4
- package/dist/build/node/meteor.d.ts +2 -2
- package/dist/build/node/meteor.js +2 -2
- package/dist/build/node/testJob.d.ts +2 -2
- package/dist/build/node/testJob.js +6 -6
- 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/index.d.ts +2 -2
- package/dist/build/rails/test.d.ts +2 -2
- package/dist/build/sbom.d.ts +2 -2
- package/dist/build/sbom.js +1 -1
- package/dist/bundles/catladder-gitlab/index.js +61 -46
- 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/getEnvironmentVariables.js +1 -2
- package/dist/context/getLabels.d.ts +2 -2
- package/dist/context/index.d.ts +7 -3
- package/dist/context/index.js +12 -3
- package/dist/deploy/base/deploy.d.ts +2 -2
- 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 -7
- package/dist/deploy/cloudRun/cleanup.d.ts +2 -2
- package/dist/deploy/cloudRun/cloudRunRevisions.d.ts +2 -2
- 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/common.d.ts +4 -4
- package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.d.ts +2 -2
- package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +1 -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/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 +1 -1
- package/dist/deploy/dockerTag/deployJob.d.ts +2 -2
- package/dist/deploy/index.d.ts +2 -2
- package/dist/deploy/kubernetes/cloudSql/index.d.ts +3 -3
- package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
- package/dist/deploy/kubernetes/kubeEnv.d.ts +2 -2
- package/dist/deploy/kubernetes/kubeValues.d.ts +2 -2
- package/dist/deploy/kubernetes/kubeValues.js +1 -3
- package/dist/deploy/kubernetes/mongodb.d.ts +2 -2
- package/dist/deploy/sbom.d.ts +4 -4
- package/dist/deploy/utils.d.ts +2 -2
- package/dist/pipeline/createJobsForComponent.d.ts +2 -2
- package/dist/pipeline/createJobsForComponent.js +1 -1
- package/dist/pipeline/generatePipelineFiles.js +15 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +3 -3
- package/dist/types/context.d.ts +16 -2
- package/dist/types/jobs.d.ts +1 -1
- package/examples/__snapshots__/cloud-run-storybook.ts.snap +1687 -0
- package/examples/__utils__/helpers.ts +2 -2
- package/examples/cloud-run-storybook.ts +24 -0
- package/package.json +1 -1
- package/scripts/generate-gitlab-ci-types.ts +2 -2
- package/src/bash/BashExpression.ts +4 -4
- package/src/bash/bashExpressionPerPipelineType.ts +1 -1
- package/src/bash/replaceAsync.ts +4 -4
- package/src/build/base/__tests__/createArtifactsConfig.test.ts +3 -3
- package/src/build/base/createAppBuildJob.ts +3 -3
- package/src/build/base/createArtifactsConfig.ts +2 -2
- package/src/build/base/index.ts +2 -2
- package/src/build/base/writeBuildInfo.ts +2 -2
- package/src/build/base/writeDotEnv.ts +3 -3
- package/src/build/custom/__tests__/testJob.test.ts +6 -6
- package/src/build/custom/buildJob.ts +4 -2
- package/src/build/custom/index.ts +2 -2
- package/src/build/custom/testJob.ts +7 -5
- package/src/build/docker.ts +18 -18
- package/src/build/index.ts +3 -3
- package/src/build/node/buildJob.ts +16 -10
- package/src/build/node/cache.ts +13 -13
- package/src/build/node/index.ts +6 -4
- package/src/build/node/meteor.ts +10 -5
- package/src/build/node/testJob.ts +14 -11
- package/src/build/node/yarn.ts +13 -15
- package/src/build/rails/build.ts +4 -2
- package/src/build/rails/index.ts +2 -2
- package/src/build/rails/test.ts +4 -2
- package/src/build/sbom.ts +4 -4
- package/src/config/configruedEnvs.ts +6 -6
- package/src/config/readConfig.ts +2 -2
- package/src/context/__tests__/resolveReferences.test.ts +1 -1
- package/src/context/getBuildInfoVariables.ts +5 -5
- package/src/context/getEnvConfig.ts +1 -1
- package/src/context/getEnvType.ts +1 -1
- package/src/context/getEnvironment.ts +2 -2
- package/src/context/getEnvironmentContext.ts +4 -4
- package/src/context/getEnvironmentVariables.ts +19 -16
- package/src/context/getLabels.ts +2 -2
- package/src/context/getReviewSlug.ts +2 -2
- package/src/context/index.ts +17 -7
- package/src/context/resolveReferences.ts +12 -9
- package/src/context/transformJobOnlyVars.ts +1 -1
- package/src/context/utils/envVars.ts +3 -3
- package/src/deploy/base/deploy.ts +7 -7
- package/src/deploy/base/index.ts +3 -3
- package/src/deploy/base/rollback.ts +3 -3
- package/src/deploy/base/stop.ts +3 -3
- package/src/deploy/cloudRun/artifactsRegistry.ts +17 -12
- package/src/deploy/cloudRun/cleanup.ts +5 -5
- package/src/deploy/cloudRun/cloudRunRevisions.ts +6 -6
- package/src/deploy/cloudRun/createJobs/cloudRunJobs.ts +20 -20
- package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +7 -7
- package/src/deploy/cloudRun/createJobs/common.ts +5 -5
- package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +12 -9
- package/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.ts +3 -3
- package/src/deploy/cloudRun/createJobs/index.ts +2 -2
- package/src/deploy/cloudRun/createJobs/volumes.ts +2 -2
- package/src/deploy/cloudRun/index.ts +10 -6
- package/src/deploy/cloudRun/utils/createArgsString.ts +1 -1
- package/src/deploy/cloudRun/utils/database.ts +8 -8
- package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +5 -3
- package/src/deploy/cloudRun/utils/getServiceName.ts +2 -2
- package/src/deploy/cloudRun/utils/jobName.ts +1 -1
- package/src/deploy/cloudRun/utils/removeFirstLinesFromCommandOutput.ts +1 -1
- package/src/deploy/cloudSql/utils.ts +2 -2
- package/src/deploy/custom/deployJob.ts +7 -3
- package/src/deploy/dockerTag/deployJob.ts +4 -2
- package/src/deploy/index.ts +5 -5
- package/src/deploy/kubernetes/cloudSql/index.ts +5 -5
- package/src/deploy/kubernetes/deployJob.ts +7 -7
- package/src/deploy/kubernetes/index.ts +1 -1
- package/src/deploy/kubernetes/kubeEnv.ts +3 -3
- package/src/deploy/kubernetes/kubeValues.ts +8 -8
- package/src/deploy/kubernetes/mongodb.ts +9 -9
- package/src/deploy/kubernetes/processSecretsAsFiles.ts +3 -3
- package/src/deploy/sbom.ts +8 -4
- package/src/deploy/utils.ts +4 -4
- package/src/pipeline/createAllJobs.ts +4 -4
- package/src/pipeline/createChildPipeline.ts +2 -2
- package/src/pipeline/createJobsForComponent.ts +13 -9
- package/src/pipeline/createMainPipeline.ts +20 -17
- package/src/pipeline/generatePipelineFiles.ts +21 -12
- package/src/pipeline/getPipelineStages.ts +1 -1
- package/src/pipeline/gitlab/createGitlabJobs.ts +26 -26
- package/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.ts +6 -6
- package/src/pipeline/packageManager.ts +2 -2
- package/src/pipeline/yarn/yarnUtils.ts +7 -7
- package/src/types/config.ts +4 -4
- package/src/types/context.ts +19 -3
- package/src/types/environmentContext.ts +1 -1
- package/src/types/jobs.ts +1 -1
- package/src/types/utils.ts +4 -4
- package/src/utils/gitlab.ts +1 -1
- package/src/utils/index.ts +2 -2
- package/src/utils/writeFiles.ts +2 -2
package/src/context/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { DEPLOY_TYPES } from "../deploy";
|
|
|
4
4
|
import type { DeployConfig, DeployConfigType } from "../deploy/types";
|
|
5
5
|
import type { PipelineType } from "../types";
|
|
6
6
|
import type { Config, PipelineTrigger } from "../types/config";
|
|
7
|
-
import type {
|
|
7
|
+
import type { ComponentContext, PackageManagerInfo } from "../types/context";
|
|
8
8
|
import type { PartialDeep } from "../types/utils";
|
|
9
9
|
import { mergeWithMergingArrays } from "../utils";
|
|
10
10
|
import { getEnvironment } from "./getEnvironment";
|
|
@@ -13,7 +13,7 @@ import { getEnvironmentContext } from "./getEnvironmentContext";
|
|
|
13
13
|
export * from "./getEnvironment";
|
|
14
14
|
export * from "./getEnvironmentVariables";
|
|
15
15
|
|
|
16
|
-
export type
|
|
16
|
+
export type CreateComponentContextContext = {
|
|
17
17
|
config: Config;
|
|
18
18
|
componentName: string;
|
|
19
19
|
env: string;
|
|
@@ -22,12 +22,12 @@ export type CreateContextContext = {
|
|
|
22
22
|
packageManagerInfo?: PackageManagerInfo;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export const
|
|
26
|
-
ctx:
|
|
27
|
-
): Promise<
|
|
25
|
+
export const createComponentContext = async (
|
|
26
|
+
ctx: CreateComponentContextContext,
|
|
27
|
+
): Promise<ComponentContext> => {
|
|
28
28
|
if (!/^[a-z0-9-]+$/.test(ctx.componentName)) {
|
|
29
29
|
throw new Error(
|
|
30
|
-
"componentName may only contain lower case letters, numbers and -"
|
|
30
|
+
"componentName may only contain lower case letters, numbers and -",
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -53,12 +53,17 @@ export const createContext = async (
|
|
|
53
53
|
};
|
|
54
54
|
const componentConfig = mergeWithMergingArrays(
|
|
55
55
|
defaults,
|
|
56
|
-
componentConfigWithoutDefaults
|
|
56
|
+
componentConfigWithoutDefaults,
|
|
57
57
|
);
|
|
58
58
|
|
|
59
59
|
return {
|
|
60
60
|
fullConfig: ctx.config,
|
|
61
61
|
componentConfig,
|
|
62
|
+
buildContext: {
|
|
63
|
+
dir: componentConfig.dir,
|
|
64
|
+
packageManagerInfo: ctx.packageManagerInfo,
|
|
65
|
+
config: componentConfig.build,
|
|
66
|
+
},
|
|
62
67
|
componentName: ctx.componentName,
|
|
63
68
|
environment: await getEnvironment(ctx),
|
|
64
69
|
packageManagerInfo: ctx.packageManagerInfo,
|
|
@@ -66,3 +71,8 @@ export const createContext = async (
|
|
|
66
71
|
trigger: ctx.trigger,
|
|
67
72
|
};
|
|
68
73
|
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated use createComponentContext instead
|
|
77
|
+
*/
|
|
78
|
+
export const createContext = createComponentContext;
|
|
@@ -12,9 +12,9 @@ export const resolveReferences = async (
|
|
|
12
12
|
vars: Record<string, string | BashExpression | undefined | null>,
|
|
13
13
|
getOtherVariables?: (
|
|
14
14
|
componentName: string,
|
|
15
|
-
alreadyVisited: Record<string, Record<string, boolean
|
|
15
|
+
alreadyVisited: Record<string, Record<string, boolean>>,
|
|
16
16
|
) => Promise<UnspecifiedEnvVars>,
|
|
17
|
-
alreadyVisitedBase: Record<string, Record<string, boolean>> = {}
|
|
17
|
+
alreadyVisitedBase: Record<string, Record<string, boolean>> = {},
|
|
18
18
|
) => {
|
|
19
19
|
/**
|
|
20
20
|
*
|
|
@@ -22,7 +22,10 @@ export const resolveReferences = async (
|
|
|
22
22
|
*/
|
|
23
23
|
const replaceSingleValue = async (
|
|
24
24
|
value: string | BashExpression,
|
|
25
|
-
alreadyVisited: Record<
|
|
25
|
+
alreadyVisited: Record<
|
|
26
|
+
string,
|
|
27
|
+
Record<string, boolean>
|
|
28
|
+
> = alreadyVisitedBase,
|
|
26
29
|
): Promise<string | BashExpression> => {
|
|
27
30
|
if (REGEX.test(value.toString())) {
|
|
28
31
|
// we consider variables that got references in it BashExpressions, because the replacement may be one
|
|
@@ -41,7 +44,7 @@ export const resolveReferences = async (
|
|
|
41
44
|
});
|
|
42
45
|
const result = componentName
|
|
43
46
|
? (await getOtherVariables?.(componentName, newAlreadyVisited).then(
|
|
44
|
-
(r) => r?.[variableName]
|
|
47
|
+
(r) => r?.[variableName],
|
|
45
48
|
)) ?? null
|
|
46
49
|
: vars[variableName]; // is self reference
|
|
47
50
|
|
|
@@ -51,7 +54,7 @@ export const resolveReferences = async (
|
|
|
51
54
|
: match;
|
|
52
55
|
|
|
53
56
|
return replaced;
|
|
54
|
-
}
|
|
57
|
+
},
|
|
55
58
|
);
|
|
56
59
|
} else {
|
|
57
60
|
return value;
|
|
@@ -71,13 +74,13 @@ export const resolveReferences = async (
|
|
|
71
74
|
? await replaceSingleValue(value)
|
|
72
75
|
: null,
|
|
73
76
|
];
|
|
74
|
-
})
|
|
75
|
-
)
|
|
77
|
+
}),
|
|
78
|
+
),
|
|
76
79
|
) as Record<string, BashExpression>;
|
|
77
80
|
};
|
|
78
81
|
|
|
79
82
|
export const translateLegacyFromComponents = (
|
|
80
|
-
fromComponents: Record<string, Record<string, string
|
|
83
|
+
fromComponents: Record<string, Record<string, string>>,
|
|
81
84
|
) => {
|
|
82
85
|
return Object.fromEntries(
|
|
83
86
|
Object.entries(fromComponents).flatMap(([componentName, variables]) => {
|
|
@@ -85,6 +88,6 @@ export const translateLegacyFromComponents = (
|
|
|
85
88
|
ourName,
|
|
86
89
|
"${" + componentName + ":" + otherName + "}",
|
|
87
90
|
]);
|
|
88
|
-
})
|
|
91
|
+
}),
|
|
89
92
|
);
|
|
90
93
|
};
|
|
@@ -8,7 +8,7 @@ export const stringifyValues = (obj: Record<string, unknown>) =>
|
|
|
8
8
|
Object.entries(obj).map(([key, value]) => [
|
|
9
9
|
key,
|
|
10
10
|
isObject(value) ? JSON.stringify(value) : `${value}`,
|
|
11
|
-
])
|
|
11
|
+
]),
|
|
12
12
|
);
|
|
13
13
|
|
|
14
14
|
export const stringListToSecreteEnvVarList = (keys: string[]): SecretEnvVar[] =>
|
|
@@ -16,12 +16,12 @@ export const stringListToSecreteEnvVarList = (keys: string[]): SecretEnvVar[] =>
|
|
|
16
16
|
export const makeSecretEnvVarMapping = (
|
|
17
17
|
env: string,
|
|
18
18
|
componentName: string,
|
|
19
|
-
secretEnvVars: SecretEnvVar[]
|
|
19
|
+
secretEnvVars: SecretEnvVar[],
|
|
20
20
|
) => {
|
|
21
21
|
return Object.fromEntries(
|
|
22
22
|
secretEnvVars.map(({ key }) => [
|
|
23
23
|
key,
|
|
24
24
|
getBashVariable(getSecretVarName(env, componentName, key)),
|
|
25
|
-
])
|
|
25
|
+
]),
|
|
26
26
|
);
|
|
27
27
|
};
|
|
@@ -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,8 +24,8 @@ export type DeployJobDefinition = Pick<
|
|
|
24
24
|
| "runnerVariables"
|
|
25
25
|
>;
|
|
26
26
|
export const createDeployJob = (
|
|
27
|
-
context:
|
|
28
|
-
jobDefinition: DeployJobDefinition
|
|
27
|
+
context: ComponentContext,
|
|
28
|
+
jobDefinition: DeployJobDefinition,
|
|
29
29
|
): CatladderJob => {
|
|
30
30
|
const hasDocker = requiresDockerBuild(context);
|
|
31
31
|
const isStoppable = contextIsStoppable(context);
|
|
@@ -34,8 +34,8 @@ export const createDeployJob = (
|
|
|
34
34
|
context.environment.envType === "review"
|
|
35
35
|
? "1 week"
|
|
36
36
|
: context.environment.envType === "dev"
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
? "4 weeks"
|
|
38
|
+
: undefined;
|
|
39
39
|
|
|
40
40
|
// if auto or manual is configured explicitly, use that
|
|
41
41
|
const whenDeployDefined =
|
|
@@ -47,8 +47,8 @@ export const createDeployJob = (
|
|
|
47
47
|
context.environment.envType !== "prod"
|
|
48
48
|
? "auto" // is not stage, auto deploy
|
|
49
49
|
: context.componentConfig.env?.stage === false
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
? "auto" // is prod, but no staging, auto deploy
|
|
51
|
+
: "manual"; // manually deploy
|
|
52
52
|
const whenDeploy = whenDeployDefined ? whenDeployDefined : whenDeployDefault;
|
|
53
53
|
|
|
54
54
|
return {
|
package/src/deploy/base/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
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;
|
|
12
12
|
rollback?: RollbackJobDefinition;
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
14
|
): CatladderJob[] => {
|
|
15
15
|
return [
|
|
16
16
|
createDeployJob(context, definitions.deploy),
|
|
@@ -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,8 +9,8 @@ export type RollbackJobDefinition = Pick<
|
|
|
9
9
|
"script" | "variables" | "runnerVariables" | "image"
|
|
10
10
|
>;
|
|
11
11
|
export const createRollbackJob = (
|
|
12
|
-
context:
|
|
13
|
-
jobDefinition: RollbackJobDefinition
|
|
12
|
+
context: ComponentContext,
|
|
13
|
+
jobDefinition: RollbackJobDefinition,
|
|
14
14
|
): CatladderJob => {
|
|
15
15
|
return {
|
|
16
16
|
name: ROLLBACK_JOB_NAME,
|
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,8 +9,8 @@ export type StopJobDefinition = Pick<
|
|
|
9
9
|
"script" | "variables" | "image" | "runnerVariables"
|
|
10
10
|
>;
|
|
11
11
|
export const createStopJob = (
|
|
12
|
-
context:
|
|
13
|
-
jobDefinition: StopJobDefinition
|
|
12
|
+
context: ComponentContext,
|
|
13
|
+
jobDefinition: StopJobDefinition,
|
|
14
14
|
): CatladderJob => {
|
|
15
15
|
return {
|
|
16
16
|
name: STOP_JOB_NAME,
|
|
@@ -1,13 +1,13 @@
|
|
|
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
8
|
export const getArtifactsRegistryHost = ({
|
|
9
9
|
componentConfig: { deploy },
|
|
10
|
-
}:
|
|
10
|
+
}: ComponentContext) => {
|
|
11
11
|
if (!isOfDeployType(deploy, "google-cloudrun")) {
|
|
12
12
|
// should not happen
|
|
13
13
|
throw new Error("deploy config is wrong");
|
|
@@ -15,7 +15,7 @@ export const getArtifactsRegistryHost = ({
|
|
|
15
15
|
return `${deploy.region}-docker.pkg.dev`;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export const getArtifactsRegistryDockerUrl = (context:
|
|
18
|
+
export const getArtifactsRegistryDockerUrl = (context: ComponentContext) => {
|
|
19
19
|
const deployConfig = context.componentConfig.deploy;
|
|
20
20
|
|
|
21
21
|
if (!isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
@@ -35,8 +35,8 @@ export const getArtifactsRegistryDockerUrl = (context: Context) => {
|
|
|
35
35
|
* 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
36
|
*/
|
|
37
37
|
export const getArtifactsRegistryImageName = (
|
|
38
|
-
context:
|
|
39
|
-
lecacyReviewImageName = false
|
|
38
|
+
context: ComponentContext,
|
|
39
|
+
lecacyReviewImageName = false,
|
|
40
40
|
) => {
|
|
41
41
|
if (lecacyReviewImageName && context.environment.envType !== "review") {
|
|
42
42
|
throw new Error("lecacyReviewImageName is only allowed for review app");
|
|
@@ -55,19 +55,21 @@ export const getArtifactsRegistryImageName = (
|
|
|
55
55
|
return joinBashExpressions(gcloudImagePath, "/");
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
export const getArtifactsRegistryBuildCacheImage = (
|
|
58
|
+
export const getArtifactsRegistryBuildCacheImage = (
|
|
59
|
+
context: ComponentContext,
|
|
60
|
+
) => {
|
|
59
61
|
const dockerUrl = getArtifactsRegistryDockerUrl(context);
|
|
60
62
|
// does not include env, so that after merge, you might get more cache hits (review-->dev)
|
|
61
63
|
const gcloudImagePath = [dockerUrl, "caches", context.componentName];
|
|
62
64
|
return gcloudImagePath.join("/");
|
|
63
65
|
};
|
|
64
66
|
|
|
65
|
-
export const getArtifactsRegistryImage = (context:
|
|
67
|
+
export const getArtifactsRegistryImage = (context: ComponentContext) =>
|
|
66
68
|
`${getArtifactsRegistryImageName(context)}:$DOCKER_IMAGE_TAG`;
|
|
67
69
|
|
|
68
70
|
const getDeleteImageCommands = (
|
|
69
71
|
fullImageName: StringOrBashExpression,
|
|
70
|
-
keepNewest = 0
|
|
72
|
+
keepNewest = 0,
|
|
71
73
|
) => {
|
|
72
74
|
if (keepNewest === 0) {
|
|
73
75
|
// no need to list tags, we delete the whole thing
|
|
@@ -80,7 +82,7 @@ const getDeleteImageCommands = (
|
|
|
80
82
|
|
|
81
83
|
const listImagesToDeletecommand = removeFirstLinesFromCommandOutput(
|
|
82
84
|
listAllImagesCommand,
|
|
83
|
-
keepNewest
|
|
85
|
+
keepNewest,
|
|
84
86
|
);
|
|
85
87
|
const deleteImageCommand = `gcloud artifacts docker images delete ${fullImageName}@$version --quiet --delete-tags`;
|
|
86
88
|
|
|
@@ -96,7 +98,10 @@ const getDeleteImageCommands = (
|
|
|
96
98
|
* @param keep how many of the newest images to keep
|
|
97
99
|
* @returns
|
|
98
100
|
*/
|
|
99
|
-
export const getDeleteUnusedImagesCommands = (
|
|
101
|
+
export const getDeleteUnusedImagesCommands = (
|
|
102
|
+
context: ComponentContext,
|
|
103
|
+
keep = 0,
|
|
104
|
+
) => {
|
|
100
105
|
const deployConfig = context.componentConfig.deploy;
|
|
101
106
|
if (deployConfig === false) {
|
|
102
107
|
return [];
|
|
@@ -119,8 +124,8 @@ export const getDeleteUnusedImagesCommands = (context: Context, keep = 0) => {
|
|
|
119
124
|
? allowFailureInScripts(
|
|
120
125
|
getDeleteImageCommands(
|
|
121
126
|
getArtifactsRegistryImageName(context, true),
|
|
122
|
-
0
|
|
123
|
-
)
|
|
127
|
+
0,
|
|
128
|
+
),
|
|
124
129
|
)
|
|
125
130
|
: []),
|
|
126
131
|
];
|
|
@@ -1,10 +1,10 @@
|
|
|
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:
|
|
7
|
-
when: "postDeploy" | "onStop"
|
|
6
|
+
context: ComponentContext,
|
|
7
|
+
when: "postDeploy" | "onStop",
|
|
8
8
|
) => {
|
|
9
9
|
if (when === "onStop") {
|
|
10
10
|
// service is already deleted, so we don't need to delete old revisions, just delete all images
|
|
@@ -19,11 +19,11 @@ export const getRemoveOldRevisionsAndImagesCommand = (
|
|
|
19
19
|
|
|
20
20
|
const deleteOldRevisionsCommands = getDeleteUnusedRevisionsCommands(
|
|
21
21
|
context,
|
|
22
|
-
revisionsToKeep
|
|
22
|
+
revisionsToKeep,
|
|
23
23
|
);
|
|
24
24
|
const deleteOldImagesCommands = getDeleteUnusedImagesCommands(
|
|
25
25
|
context,
|
|
26
|
-
imagesToKeep
|
|
26
|
+
imagesToKeep,
|
|
27
27
|
);
|
|
28
28
|
|
|
29
29
|
return [...deleteOldRevisionsCommands, ...deleteOldImagesCommands];
|
|
@@ -1,15 +1,15 @@
|
|
|
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
|
const deployConfig = context.componentConfig.deploy;
|
|
@@ -34,8 +34,8 @@ const getListRevisionsCommand = (
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export const getDeleteUnusedRevisionsCommands = (
|
|
37
|
-
context:
|
|
38
|
-
keep: number
|
|
37
|
+
context: ComponentContext,
|
|
38
|
+
keep: number,
|
|
39
39
|
) => {
|
|
40
40
|
const deployConfig = context.componentConfig.deploy;
|
|
41
41
|
if (deployConfig === false) {
|
|
@@ -54,7 +54,7 @@ export const getDeleteUnusedRevisionsCommands = (
|
|
|
54
54
|
// this removes the newest `revisionsToKeep` images
|
|
55
55
|
const listRevisionsToDeleteCmd = removeFirstLinesFromCommandOutput(
|
|
56
56
|
listAllInactiveRevisionsCmd,
|
|
57
|
-
keep
|
|
57
|
+
keep,
|
|
58
58
|
);
|
|
59
59
|
const deleteRevisionCmd = `gcloud run revisions delete ${createArgsString({
|
|
60
60
|
project: deployConfig.projectId,
|
|
@@ -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,9 +24,9 @@ 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
|
-
wait: boolean
|
|
29
|
+
wait: boolean,
|
|
30
30
|
) => {
|
|
31
31
|
const commonArgs = getCommonCloudRunArgs(context);
|
|
32
32
|
|
|
@@ -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,8 +65,8 @@ export const getDeleteJobsScripts = (context: Context) => {
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
export const getJobRunScripts = (
|
|
68
|
-
context:
|
|
69
|
-
when: DeployConfigCloudRunJob["when"]
|
|
68
|
+
context: ComponentContext,
|
|
69
|
+
when: DeployConfigCloudRunJob["when"],
|
|
70
70
|
) => {
|
|
71
71
|
const jobsWithNames = getCloudRunJobsWithNames(context);
|
|
72
72
|
return jobsWithNames
|
|
@@ -76,12 +76,12 @@ export const getJobRunScripts = (
|
|
|
76
76
|
context,
|
|
77
77
|
jobName,
|
|
78
78
|
// wait for completin on stop jobs, since stop will delete the jobs afterwards, so they will fail
|
|
79
|
-
["preStop", "postStop"].includes(when)
|
|
80
|
-
)
|
|
79
|
+
["preStop", "postStop"].includes(when),
|
|
80
|
+
),
|
|
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,9 +90,9 @@ export const getJobCreateScripts = (context: Context) => {
|
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
const getJobCreateScriptsForJob = (
|
|
93
|
-
context:
|
|
93
|
+
context: ComponentContext,
|
|
94
94
|
jobName: StringOrBashExpression,
|
|
95
|
-
job: DeployConfigCloudRunJob
|
|
95
|
+
job: DeployConfigCloudRunJob,
|
|
96
96
|
) => {
|
|
97
97
|
const commonDeployArgs = getCommonDeployArgs(context);
|
|
98
98
|
|
|
@@ -125,14 +125,14 @@ const getJobCreateScriptsForJob = (
|
|
|
125
125
|
return [
|
|
126
126
|
...allowFailureInScripts([`${gcloudRunCmd()} jobs create ${argsString}`]),
|
|
127
127
|
`${gcloudRunCmd(
|
|
128
|
-
requiresBeta ? "beta" : undefined
|
|
128
|
+
requiresBeta ? "beta" : undefined,
|
|
129
129
|
)} jobs update ${argsString} ${createArgsString(
|
|
130
|
-
...createVolumeConfig(job?.volumes, "job")
|
|
130
|
+
...createVolumeConfig(job?.volumes, "job"),
|
|
131
131
|
)}`,
|
|
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,17 +160,17 @@ 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
|
|
167
167
|
.filter(
|
|
168
168
|
(
|
|
169
|
-
entry
|
|
169
|
+
entry,
|
|
170
170
|
): entry is {
|
|
171
171
|
jobName: BashExpression;
|
|
172
172
|
job: DeployConfigCloudRunJobWithSchedule;
|
|
173
|
-
} => entry.job.when === "schedule"
|
|
173
|
+
} => entry.job.when === "schedule",
|
|
174
174
|
)
|
|
175
175
|
.map(({ job, jobName }) => ({
|
|
176
176
|
job,
|
|
@@ -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) =>
|
|
@@ -188,7 +188,7 @@ const getCloudRunJobsWithNames = (context: Context) => {
|
|
|
188
188
|
const jobsWithNames = Object.entries(deployConfig.jobs ?? {})
|
|
189
189
|
// filter out disabled jobs
|
|
190
190
|
.filter((entry): entry is [string, DeployConfigCloudRunJob] =>
|
|
191
|
-
Boolean(entry[1])
|
|
191
|
+
Boolean(entry[1]),
|
|
192
192
|
)
|
|
193
193
|
.map(([name, job]) => ({
|
|
194
194
|
jobName: getFullJobName(name),
|
|
@@ -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,9 +14,9 @@ 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
|
-
nameSuffix?: string
|
|
19
|
+
nameSuffix?: string,
|
|
20
20
|
) => {
|
|
21
21
|
const commonDeployArgs = getCommonDeployArgs(context);
|
|
22
22
|
|
|
@@ -54,20 +54,20 @@ export const getServiceDeployScript = (
|
|
|
54
54
|
"cpu-boost": true,
|
|
55
55
|
"execution-environment": customConfig?.executionEnvironment,
|
|
56
56
|
},
|
|
57
|
-
...createVolumeConfig(customConfig?.volumes, "service")
|
|
57
|
+
...createVolumeConfig(customConfig?.volumes, "service"),
|
|
58
58
|
);
|
|
59
59
|
// volumes require beta
|
|
60
60
|
const requiresBeta =
|
|
61
61
|
customConfig?.volumes && Object.keys(customConfig?.volumes).length > 0;
|
|
62
62
|
|
|
63
63
|
return `${gcloudRunCmd(
|
|
64
|
-
requiresBeta ? "beta" : undefined
|
|
64
|
+
requiresBeta ? "beta" : undefined,
|
|
65
65
|
)} deploy ${fullServiceName} ${argsString}`;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
export const getServiceDeleteScript = (
|
|
69
|
-
context:
|
|
70
|
-
serviceSuffix?: string
|
|
69
|
+
context: ComponentContext,
|
|
70
|
+
serviceSuffix?: string,
|
|
71
71
|
) => {
|
|
72
72
|
const commonArgs = getCommonCloudRunArgs(context);
|
|
73
73
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentContext } from "../../../types/context";
|
|
2
2
|
|
|
3
3
|
import { isOfDeployType } from "../../types";
|
|
4
4
|
import type { DeployConfigCloudRun } from "../../types/googleCloudRun";
|
|
@@ -16,7 +16,7 @@ export const gcloudSchedulerCmd = (version?: "beta") => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export const setGoogleProjectNumberScript = (
|
|
19
|
-
deployConfig: DeployConfigCloudRun
|
|
19
|
+
deployConfig: DeployConfigCloudRun,
|
|
20
20
|
) => [
|
|
21
21
|
`export GCLOUD_PROJECT_NUMBER=$(${gcloudCmd()} projects describe ${
|
|
22
22
|
deployConfig.projectId
|
|
@@ -29,7 +29,7 @@ export const makeLabelString = (obj: Record<string, unknown>) =>
|
|
|
29
29
|
.map(([key, value]) => `${key}=${value}`)
|
|
30
30
|
.join(",");
|
|
31
31
|
|
|
32
|
-
export const getCloudRunDeployConfig = (context:
|
|
32
|
+
export const getCloudRunDeployConfig = (context: ComponentContext) => {
|
|
33
33
|
const deployConfig = context.componentConfig.deploy;
|
|
34
34
|
if (!isOfDeployType(deployConfig, "google-cloudrun")) {
|
|
35
35
|
// should not happen
|
|
@@ -38,7 +38,7 @@ export const getCloudRunDeployConfig = (context: Context) => {
|
|
|
38
38
|
return deployConfig;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
export function getCommonCloudRunArgs(context:
|
|
41
|
+
export function getCommonCloudRunArgs(context: ComponentContext) {
|
|
42
42
|
const deployConfig = getCloudRunDeployConfig(context);
|
|
43
43
|
return {
|
|
44
44
|
project: deployConfig.projectId,
|
|
@@ -46,7 +46,7 @@ export function getCommonCloudRunArgs(context: Context) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export function getCommonDeployArgs(context:
|
|
49
|
+
export function getCommonDeployArgs(context: ComponentContext) {
|
|
50
50
|
const commonArgs = getCommonCloudRunArgs(context);
|
|
51
51
|
const deployConfig = getCloudRunDeployConfig(context);
|
|
52
52
|
return {
|