@catladder/pipeline 1.145.0 → 1.146.1
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/bundles/catladder-gitlab/index.js +1 -1
- package/dist/constants.js +1 -1
- package/dist/context/getEnvironmentVariables.js +1 -2
- package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +1 -2
- package/dist/deploy/kubernetes/kubeValues.js +1 -3
- package/dist/pipeline/generatePipelineFiles.js +15 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/jobs.d.ts +1 -1
- package/examples/__utils__/helpers.ts +2 -2
- 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 +1 -1
- package/src/build/base/writeDotEnv.ts +1 -1
- package/src/build/custom/__tests__/testJob.test.ts +1 -1
- package/src/build/custom/buildJob.ts +2 -2
- package/src/build/custom/testJob.ts +3 -3
- package/src/build/docker.ts +7 -7
- package/src/build/index.ts +1 -1
- package/src/build/node/buildJob.ts +2 -2
- package/src/build/node/cache.ts +4 -4
- package/src/build/node/meteor.ts +1 -1
- package/src/build/node/testJob.ts +3 -3
- package/src/build/node/yarn.ts +7 -7
- 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 +1 -1
- package/src/context/getEnvironmentContext.ts +2 -2
- package/src/context/getEnvironmentVariables.ts +12 -12
- package/src/context/getReviewSlug.ts +2 -2
- package/src/context/index.ts +3 -3
- 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 +5 -5
- package/src/deploy/base/index.ts +1 -1
- package/src/deploy/base/rollback.ts +1 -1
- package/src/deploy/base/stop.ts +1 -1
- package/src/deploy/cloudRun/artifactsRegistry.ts +5 -5
- package/src/deploy/cloudRun/cleanup.ts +3 -3
- package/src/deploy/cloudRun/cloudRunRevisions.ts +3 -3
- 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 +7 -7
- package/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.ts +1 -1
- package/src/deploy/cloudRun/createJobs/index.ts +1 -1
- 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 +5 -5
- package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +1 -1
- 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/index.ts +3 -3
- package/src/deploy/kubernetes/cloudSql/index.ts +3 -3
- package/src/deploy/kubernetes/deployJob.ts +6 -6
- package/src/deploy/kubernetes/index.ts +1 -1
- package/src/deploy/kubernetes/kubeEnv.ts +1 -1
- package/src/deploy/kubernetes/kubeValues.ts +5 -5
- package/src/deploy/kubernetes/mongodb.ts +1 -1
- package/src/deploy/kubernetes/processSecretsAsFiles.ts +3 -3
- package/src/deploy/utils.ts +2 -2
- package/src/pipeline/createAllJobs.ts +4 -4
- package/src/pipeline/createChildPipeline.ts +2 -2
- package/src/pipeline/createJobsForComponent.ts +3 -3
- 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 +24 -24
- 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 +2 -2
- package/src/types/context.ts +1 -1
- 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
|
@@ -23,11 +23,11 @@ export type CreateContextContext = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
export const createContext = async (
|
|
26
|
-
ctx: CreateContextContext
|
|
26
|
+
ctx: CreateContextContext,
|
|
27
27
|
): Promise<Context> => {
|
|
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,7 +53,7 @@ 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 {
|
|
@@ -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
|
};
|
|
@@ -25,7 +25,7 @@ export type DeployJobDefinition = Pick<
|
|
|
25
25
|
>;
|
|
26
26
|
export const createDeployJob = (
|
|
27
27
|
context: Context,
|
|
28
|
-
jobDefinition: DeployJobDefinition
|
|
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
package/src/deploy/base/stop.ts
CHANGED
|
@@ -36,7 +36,7 @@ export const getArtifactsRegistryDockerUrl = (context: Context) => {
|
|
|
36
36
|
*/
|
|
37
37
|
export const getArtifactsRegistryImageName = (
|
|
38
38
|
context: Context,
|
|
39
|
-
lecacyReviewImageName = false
|
|
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");
|
|
@@ -67,7 +67,7 @@ export const getArtifactsRegistryImage = (context: Context) =>
|
|
|
67
67
|
|
|
68
68
|
const getDeleteImageCommands = (
|
|
69
69
|
fullImageName: StringOrBashExpression,
|
|
70
|
-
keepNewest = 0
|
|
70
|
+
keepNewest = 0,
|
|
71
71
|
) => {
|
|
72
72
|
if (keepNewest === 0) {
|
|
73
73
|
// no need to list tags, we delete the whole thing
|
|
@@ -80,7 +80,7 @@ const getDeleteImageCommands = (
|
|
|
80
80
|
|
|
81
81
|
const listImagesToDeletecommand = removeFirstLinesFromCommandOutput(
|
|
82
82
|
listAllImagesCommand,
|
|
83
|
-
keepNewest
|
|
83
|
+
keepNewest,
|
|
84
84
|
);
|
|
85
85
|
const deleteImageCommand = `gcloud artifacts docker images delete ${fullImageName}@$version --quiet --delete-tags`;
|
|
86
86
|
|
|
@@ -119,8 +119,8 @@ export const getDeleteUnusedImagesCommands = (context: Context, keep = 0) => {
|
|
|
119
119
|
? allowFailureInScripts(
|
|
120
120
|
getDeleteImageCommands(
|
|
121
121
|
getArtifactsRegistryImageName(context, true),
|
|
122
|
-
0
|
|
123
|
-
)
|
|
122
|
+
0,
|
|
123
|
+
),
|
|
124
124
|
)
|
|
125
125
|
: []),
|
|
126
126
|
];
|
|
@@ -4,7 +4,7 @@ import { getDeleteUnusedRevisionsCommands } from "./cloudRunRevisions";
|
|
|
4
4
|
|
|
5
5
|
export const getRemoveOldRevisionsAndImagesCommand = (
|
|
6
6
|
context: Context,
|
|
7
|
-
when: "postDeploy" | "onStop"
|
|
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];
|
|
@@ -9,7 +9,7 @@ const getListRevisionsCommand = (
|
|
|
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;
|
|
@@ -35,7 +35,7 @@ const getListRevisionsCommand = (
|
|
|
35
35
|
|
|
36
36
|
export const getDeleteUnusedRevisionsCommands = (
|
|
37
37
|
context: Context,
|
|
38
|
-
keep: number
|
|
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,
|
|
@@ -26,7 +26,7 @@ import { ENV_VARS_FILENAME } from "./constants";
|
|
|
26
26
|
const getJobRunScriptForJob = (
|
|
27
27
|
context: Context,
|
|
28
28
|
jobName: StringOrBashExpression,
|
|
29
|
-
wait: boolean
|
|
29
|
+
wait: boolean,
|
|
30
30
|
) => {
|
|
31
31
|
const commonArgs = getCommonCloudRunArgs(context);
|
|
32
32
|
|
|
@@ -66,7 +66,7 @@ export const getDeleteJobsScripts = (context: Context) => {
|
|
|
66
66
|
|
|
67
67
|
export const getJobRunScripts = (
|
|
68
68
|
context: Context,
|
|
69
|
-
when: DeployConfigCloudRunJob["when"]
|
|
69
|
+
when: DeployConfigCloudRunJob["when"],
|
|
70
70
|
) => {
|
|
71
71
|
const jobsWithNames = getCloudRunJobsWithNames(context);
|
|
72
72
|
return jobsWithNames
|
|
@@ -76,8 +76,8 @@ 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
|
|
|
@@ -92,7 +92,7 @@ export const getJobCreateScripts = (context: Context) => {
|
|
|
92
92
|
const getJobCreateScriptsForJob = (
|
|
93
93
|
context: Context,
|
|
94
94
|
jobName: StringOrBashExpression,
|
|
95
|
-
job: DeployConfigCloudRunJob
|
|
95
|
+
job: DeployConfigCloudRunJob,
|
|
96
96
|
) => {
|
|
97
97
|
const commonDeployArgs = getCommonDeployArgs(context);
|
|
98
98
|
|
|
@@ -125,9 +125,9 @@ 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
|
};
|
|
@@ -166,11 +166,11 @@ const getCloudRunJobsWithSchedule = (context: Context) => {
|
|
|
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,
|
|
@@ -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),
|
|
@@ -16,7 +16,7 @@ import { createVolumeConfig } from "./volumes";
|
|
|
16
16
|
export const getServiceDeployScript = (
|
|
17
17
|
context: Context,
|
|
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
69
|
context: Context,
|
|
70
|
-
serviceSuffix?: string
|
|
70
|
+
serviceSuffix?: string,
|
|
71
71
|
) => {
|
|
72
72
|
const commonArgs = getCommonCloudRunArgs(context);
|
|
73
73
|
|
|
@@ -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,25 +29,25 @@ export function getCloudRunDeployScripts(context: Context) {
|
|
|
29
29
|
const deployConfig = getCloudRunDeployConfig(context);
|
|
30
30
|
const allEnvVars = omit(
|
|
31
31
|
context.environment.envVars,
|
|
32
|
-
GCLOUD_DEPLOY_CREDENTIALS_KEY
|
|
32
|
+
GCLOUD_DEPLOY_CREDENTIALS_KEY,
|
|
33
33
|
);
|
|
34
34
|
|
|
35
35
|
return [
|
|
36
36
|
...collapseableSection(
|
|
37
37
|
"prepare",
|
|
38
|
-
"Prepare..."
|
|
38
|
+
"Prepare...",
|
|
39
39
|
)([
|
|
40
40
|
...gcloudServiceAccountLoginCommands(context),
|
|
41
41
|
...setGoogleProjectNumberScript(deployConfig),
|
|
42
42
|
]),
|
|
43
43
|
...collapseableSection(
|
|
44
44
|
"writeenvvars",
|
|
45
|
-
"Write env vars to file"
|
|
45
|
+
"Write env vars to file",
|
|
46
46
|
)(writeBashYamlToFileScript(allEnvVars, ENV_VARS_FILENAME)),
|
|
47
47
|
|
|
48
48
|
...collapseableSection(
|
|
49
49
|
"deploy",
|
|
50
|
-
"Deploy to cloud run"
|
|
50
|
+
"Deploy to cloud run",
|
|
51
51
|
)([
|
|
52
52
|
...(deployConfig.cloudSql
|
|
53
53
|
? getDatabaseCreateScript(context, deployConfig) // we create the db, so that we can also delete it afterwards
|
|
@@ -61,15 +61,15 @@ export function getCloudRunDeployScripts(context: Context) {
|
|
|
61
61
|
: []),
|
|
62
62
|
...Object.entries(deployConfig.additionalServices ?? {}).map(
|
|
63
63
|
([name, service]) =>
|
|
64
|
-
getServiceDeployScript(context, service, "-" + name)
|
|
64
|
+
getServiceDeployScript(context, service, "-" + name),
|
|
65
65
|
),
|
|
66
66
|
...getJobRunScripts(context, "postDeploy"),
|
|
67
67
|
]),
|
|
68
68
|
...collapseableSection(
|
|
69
69
|
"cleanup",
|
|
70
|
-
"Cleanup"
|
|
70
|
+
"Cleanup",
|
|
71
71
|
)(
|
|
72
|
-
getRemoveOldRevisionsAndImagesCommand(context, "postDeploy") // we cleanup inactive images both on deploy and stop
|
|
72
|
+
getRemoveOldRevisionsAndImagesCommand(context, "postDeploy"), // we cleanup inactive images both on deploy and stop
|
|
73
73
|
),
|
|
74
74
|
...getDependencyTrackUploadScript(context),
|
|
75
75
|
];
|
|
@@ -19,7 +19,7 @@ export function getCloudRunStopScripts(context: Context) {
|
|
|
19
19
|
...getJobRunScripts(context, "preStop"),
|
|
20
20
|
...(deployConfig.service !== false ? getServiceDeleteScript(context) : []),
|
|
21
21
|
...Object.entries(deployConfig.additionalServices ?? {}).flatMap(([name]) =>
|
|
22
|
-
getServiceDeleteScript(context, name)
|
|
22
|
+
getServiceDeleteScript(context, name),
|
|
23
23
|
),
|
|
24
24
|
...getJobRunScripts(context, "postStop"),
|
|
25
25
|
...getDeleteSchedulesScripts(context),
|
|
@@ -10,7 +10,7 @@ import { getCloudRunDeployScripts } from "./getCloudRunDeployScripts";
|
|
|
10
10
|
import { getCloudRunStopScripts } from "./getCloudRunStopScripts";
|
|
11
11
|
|
|
12
12
|
export const createGoogleCloudRunDeployJobs = (
|
|
13
|
-
context: Context
|
|
13
|
+
context: Context,
|
|
14
14
|
): CatladderJob[] => {
|
|
15
15
|
const deployConfig = context.componentConfig.deploy;
|
|
16
16
|
if (deployConfig === false) {
|
|
@@ -3,7 +3,7 @@ import type { keyValuesArg } from "../utils/createArgsString";
|
|
|
3
3
|
|
|
4
4
|
export const createVolumeConfig = (
|
|
5
5
|
volumes: DeployConfigCloudRunVolumes | undefined,
|
|
6
|
-
type: "service" | "job"
|
|
6
|
+
type: "service" | "job",
|
|
7
7
|
): keyValuesArg[] => {
|
|
8
8
|
if (!volumes) {
|
|
9
9
|
return [];
|
|
@@ -16,7 +16,7 @@ export const createVolumeConfig = (
|
|
|
16
16
|
readonly ? ",readonly=true" : ""
|
|
17
17
|
}`,
|
|
18
18
|
"add-volume-mount": `volume=${volumeName},mount-path=${mountPath}`,
|
|
19
|
-
})
|
|
19
|
+
}),
|
|
20
20
|
),
|
|
21
21
|
type === "service" ? { "execution-environment": "gen2" } : {},
|
|
22
22
|
];
|
|
@@ -33,11 +33,11 @@ const getCloudSqlVariables = ({
|
|
|
33
33
|
deployConfigRaw.cloudSql,
|
|
34
34
|
fullConfig,
|
|
35
35
|
environmentSlugPrefix,
|
|
36
|
-
componentName
|
|
36
|
+
componentName,
|
|
37
37
|
);
|
|
38
38
|
|
|
39
39
|
const additionalQueryParamsString = Object.entries(
|
|
40
|
-
deployConfigRaw.cloudSql.dbAdditionalQueryParams ?? {}
|
|
40
|
+
deployConfigRaw.cloudSql.dbAdditionalQueryParams ?? {},
|
|
41
41
|
)
|
|
42
42
|
.map(([key, value]) => `&${key}=${value}`)
|
|
43
43
|
.join("");
|
|
@@ -49,7 +49,7 @@ const getCloudSqlVariables = ({
|
|
|
49
49
|
DB_USER: deployConfigRaw.cloudSql.dbUser ?? "postgres",
|
|
50
50
|
DB_PASSWORD: "$" + getSecretVarName(env, componentName, "DB_PASSWORD"),
|
|
51
51
|
DATABASE_URL: `${getDatabaseConnectionString(
|
|
52
|
-
deployConfigRaw.cloudSql
|
|
52
|
+
deployConfigRaw.cloudSql,
|
|
53
53
|
)}${additionalQueryParamsString}`,
|
|
54
54
|
DATABASE_JDBC_URL: DATABASE_JDBC_URL,
|
|
55
55
|
};
|
|
@@ -88,10 +88,14 @@ export const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<"google-cloudrun"> = {
|
|
|
88
88
|
[
|
|
89
89
|
fullName,
|
|
90
90
|
getBashVariable(
|
|
91
|
-
getSecretVarName(
|
|
91
|
+
getSecretVarName(
|
|
92
|
+
env,
|
|
93
|
+
componentName,
|
|
94
|
+
GCLOUD_RUN_CANONICAL_HOST_SUFFIX,
|
|
95
|
+
),
|
|
92
96
|
),
|
|
93
97
|
],
|
|
94
|
-
"-"
|
|
98
|
+
"-",
|
|
95
99
|
).toLowerCase();
|
|
96
100
|
const jobTriggers =
|
|
97
101
|
deployConfigRaw && deployConfigRaw.jobs
|
|
@@ -103,7 +107,7 @@ export const GCLOUD_RUN_DEPLOY_TYPE: DeployTypeDefinition<"google-cloudrun"> = {
|
|
|
103
107
|
}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${
|
|
104
108
|
deployConfigRaw.projectId
|
|
105
109
|
}/jobs/${getCloudRunJobName(fullName, name)}:run`,
|
|
106
|
-
])
|
|
110
|
+
]),
|
|
107
111
|
)
|
|
108
112
|
: {};
|
|
109
113
|
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
|
|
8
8
|
export const getDatabaseDeleteScript = (
|
|
9
9
|
context: Context,
|
|
10
|
-
deployConfig: DeployConfigCloudRun
|
|
10
|
+
deployConfig: DeployConfigCloudRun,
|
|
11
11
|
): string[] => {
|
|
12
12
|
if (!deployConfig.cloudSql || !deployConfig.cloudSql.deleteDatabaseOnStop) {
|
|
13
13
|
throw new Error("not possible");
|
|
@@ -29,14 +29,14 @@ export const getDatabaseDeleteScript = (
|
|
|
29
29
|
`gcloud sql databases delete ${DB_NAME} --instance=${instanceId} --project ${projectId}`,
|
|
30
30
|
{
|
|
31
31
|
pauseInSeconds: 10,
|
|
32
|
-
}
|
|
32
|
+
},
|
|
33
33
|
),
|
|
34
34
|
];
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
export const getDatabaseCreateScript = (
|
|
38
38
|
context: Context,
|
|
39
|
-
deployConfig: DeployConfigCloudRun
|
|
39
|
+
deployConfig: DeployConfigCloudRun,
|
|
40
40
|
): string[] => {
|
|
41
41
|
if (!deployConfig.cloudSql) {
|
|
42
42
|
throw new Error("not possible");
|
|
@@ -61,14 +61,14 @@ export const DATABASE_JDBC_URL =
|
|
|
61
61
|
"jdbc:postgresql:///$DB_NAME?cloudSqlInstance=$CLOUD_SQL_INSTANCE_CONNECTION_NAME&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=$DB_USER&password=$DB_PASSWORD";
|
|
62
62
|
|
|
63
63
|
export const getDatabaseConnectionString = (
|
|
64
|
-
config: DeployConfigCloudRunCloudSql
|
|
64
|
+
config: DeployConfigCloudRunCloudSql,
|
|
65
65
|
): string => {
|
|
66
66
|
switch (config.dbConnectionStringFormat) {
|
|
67
67
|
case "jdbc":
|
|
68
68
|
return DATABASE_JDBC_URL;
|
|
69
69
|
case "rails":
|
|
70
70
|
return `postgresql://$DB_USER:$DB_PASSWORD@${encodeURIComponent(
|
|
71
|
-
`/cloudsql/${config.instanceConnectionName}
|
|
71
|
+
`/cloudsql/${config.instanceConnectionName}`,
|
|
72
72
|
)}/$DB_NAME?`;
|
|
73
73
|
default:
|
|
74
74
|
// prisma
|
|
@@ -5,6 +5,6 @@ import type { Context } from "../../../types";
|
|
|
5
5
|
export const gcloudServiceAccountLoginCommands = (context: Context) => [
|
|
6
6
|
`gcloud auth activate-service-account --key-file=<(echo "$${getSecretVarNameForContext(
|
|
7
7
|
context,
|
|
8
|
-
GCLOUD_DEPLOY_CREDENTIALS_KEY
|
|
8
|
+
GCLOUD_DEPLOY_CREDENTIALS_KEY,
|
|
9
9
|
)}")`,
|
|
10
10
|
];
|
|
@@ -2,6 +2,6 @@ import type { StringOrBashExpression } from "../../../bash/BashExpression";
|
|
|
2
2
|
|
|
3
3
|
export const getCloudRunJobName = (
|
|
4
4
|
fullAppName: StringOrBashExpression,
|
|
5
|
-
jobName: string
|
|
5
|
+
jobName: string,
|
|
6
6
|
): StringOrBashExpression =>
|
|
7
7
|
fullAppName.toLowerCase().concat("-" + jobName.toLowerCase());
|
|
@@ -12,7 +12,7 @@ export const getFullDbName = (
|
|
|
12
12
|
| DeployConfigKubernetesValuesCloudSQLUnmanaged,
|
|
13
13
|
fullConfig: Config<never>,
|
|
14
14
|
environmentSlugPrefix: StringOrBashExpression,
|
|
15
|
-
componentName: string
|
|
15
|
+
componentName: string,
|
|
16
16
|
) => {
|
|
17
17
|
return joinBashExpressions(
|
|
18
18
|
[
|
|
@@ -21,6 +21,6 @@ export const getFullDbName = (
|
|
|
21
21
|
environmentSlugPrefix,
|
|
22
22
|
cloudSqlConfig.dbBaseName ?? componentName,
|
|
23
23
|
].flatMap((part) => (part ? [part] : [])),
|
|
24
|
-
"-"
|
|
24
|
+
"-",
|
|
25
25
|
);
|
|
26
26
|
};
|
package/src/deploy/index.ts
CHANGED
|
@@ -17,13 +17,13 @@ export * from "./utils";
|
|
|
17
17
|
export type DeployTypeDefinition<T extends DeployConfigType> = {
|
|
18
18
|
jobs: (context: Context) => CatladderJob[];
|
|
19
19
|
defaults: (
|
|
20
|
-
envContext: EnvironmentContext<any, T
|
|
20
|
+
envContext: EnvironmentContext<any, T>,
|
|
21
21
|
) => PartialDeep<DeployConfigGeneric<T>>;
|
|
22
22
|
additionalSecretKeys: (
|
|
23
|
-
envContext: EnvironmentContext<any, T
|
|
23
|
+
envContext: EnvironmentContext<any, T>,
|
|
24
24
|
) => SecretEnvVar[];
|
|
25
25
|
getAdditionalEnvVars: (
|
|
26
|
-
envContext: EnvironmentContext<any, T
|
|
26
|
+
envContext: EnvironmentContext<any, T>,
|
|
27
27
|
) => Record<string, string | BashExpression | undefined | null>;
|
|
28
28
|
};
|
|
29
29
|
export type DeployTypes = {
|
|
@@ -20,7 +20,7 @@ type CloudSqlValues = {
|
|
|
20
20
|
dbUser: string;
|
|
21
21
|
};
|
|
22
22
|
export const createKubernetesCloudsqlBaseValues = (
|
|
23
|
-
context: Context
|
|
23
|
+
context: Context,
|
|
24
24
|
): {
|
|
25
25
|
cloudsql: CloudSqlValues;
|
|
26
26
|
} => {
|
|
@@ -36,7 +36,7 @@ export const createKubernetesCloudsqlBaseValues = (
|
|
|
36
36
|
|
|
37
37
|
const proxyCredentials = `$${getSecretVarNameForContext(
|
|
38
38
|
context,
|
|
39
|
-
"cloudsqlProxyCredentials"
|
|
39
|
+
"cloudsqlProxyCredentials",
|
|
40
40
|
)}`;
|
|
41
41
|
if (config?.type !== "unmanaged") {
|
|
42
42
|
const instanceConnectionName = `${config.projectId ?? "skynet-164509"}:${
|
|
@@ -63,7 +63,7 @@ export const createKubernetesCloudsqlBaseValues = (
|
|
|
63
63
|
config,
|
|
64
64
|
context.fullConfig,
|
|
65
65
|
context.environment.slugPrefix,
|
|
66
|
-
context.componentName
|
|
66
|
+
context.componentName,
|
|
67
67
|
),
|
|
68
68
|
},
|
|
69
69
|
};
|