@catladder/pipeline 0.0.0-refactor-args-c1264291 → 0.0.0-refactor-gcloud-api-60147713
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 +26 -111
- package/dist/constants.js +1 -1
- package/dist/deploy/cloudRun/deployJob.js +25 -53
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/examples/__snapshots__/cloud-run-with-sql.ts.snap +56 -56
- package/examples/__snapshots__/custom-build-job.ts.snap +8 -8
- package/package.json +1 -1
- package/src/deploy/cloudRun/deployJob.ts +35 -53
- package/dist/deploy/cloudRun/utils/createArgsString.d.ts +0 -11
- package/dist/deploy/cloudRun/utils/createArgsString.js +0 -50
- package/src/deploy/cloudRun/utils/createArgsString.ts +0 -19
|
@@ -151,7 +151,7 @@ exports[`matches snapshot 1`] = `
|
|
|
151
151
|
"docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
152
152
|
"docker push asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
153
153
|
"echo "$ENV_VARS" > ____envvars.yaml",
|
|
154
|
-
"gcloud run deploy pan-test-app-dev-www
|
|
154
|
+
"gcloud run deploy pan-test-app-dev-www --image asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project asdf --region=asia-east1 --labels customer-name=pan,app-name=test-app,env-type=dev,env-name=dev,build-type=custom --env-vars-file=____envvars.yaml --allow-unauthenticated",
|
|
155
155
|
"docker image rm asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
156
156
|
],
|
|
157
157
|
"services": [
|
|
@@ -231,7 +231,7 @@ _ALL_ENV_VAR_KEYS: '["ENV_SHORT","APP_DIR","ENV_TYPE","HOST","ROOT_URL","HOST_CA
|
|
|
231
231
|
"echo $CL_dev_www_GCLOUD_DEPLOY_credentialsKey > ./____keyfile.json
|
|
232
232
|
",
|
|
233
233
|
"gcloud auth activate-service-account --key-file="./____keyfile.json"",
|
|
234
|
-
"gcloud run services delete pan-test-app-dev-www --project
|
|
234
|
+
"gcloud run services delete pan-test-app-dev-www --project asdf --region=asia-east1",
|
|
235
235
|
],
|
|
236
236
|
"stage": "stop dev",
|
|
237
237
|
"variables": {
|
|
@@ -461,7 +461,7 @@ _ALL_ENV_VAR_KEYS: '["ENV_SHORT","APP_DIR","ENV_TYPE","HOST","ROOT_URL","HOST_CA
|
|
|
461
461
|
"docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
462
462
|
"docker push asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
463
463
|
"echo "$ENV_VARS" > ____envvars.yaml",
|
|
464
|
-
"gcloud run deploy pan-test-app-review-mr1234-www
|
|
464
|
+
"gcloud run deploy pan-test-app-review-mr1234-www --image asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project asdf --region=asia-east1 --labels customer-name=pan,app-name=test-app,env-type=review,env-name=review,build-type=custom --env-vars-file=____envvars.yaml --allow-unauthenticated",
|
|
465
465
|
"docker image rm asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
466
466
|
],
|
|
467
467
|
"services": [
|
|
@@ -541,7 +541,7 @@ _ALL_ENV_VAR_KEYS: '["ENV_SHORT","APP_DIR","ENV_TYPE","HOST","ROOT_URL","HOST_CA
|
|
|
541
541
|
"echo $CL_review_www_GCLOUD_DEPLOY_credentialsKey > ./____keyfile.json
|
|
542
542
|
",
|
|
543
543
|
"gcloud auth activate-service-account --key-file="./____keyfile.json"",
|
|
544
|
-
"gcloud run services delete pan-test-app-review-mr1234-www --project
|
|
544
|
+
"gcloud run services delete pan-test-app-review-mr1234-www --project asdf --region=asia-east1",
|
|
545
545
|
],
|
|
546
546
|
"stage": "stop review",
|
|
547
547
|
"variables": {
|
|
@@ -868,7 +868,7 @@ _ALL_ENV_VAR_KEYS: '["ENV_SHORT","APP_DIR","ENV_TYPE","HOST","ROOT_URL","HOST_CA
|
|
|
868
868
|
"docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
869
869
|
"docker push asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
870
870
|
"echo "$ENV_VARS" > ____envvars.yaml",
|
|
871
|
-
"gcloud run deploy pan-test-app-prod-www
|
|
871
|
+
"gcloud run deploy pan-test-app-prod-www --image asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project asdf --region=asia-east1 --labels customer-name=pan,app-name=test-app,env-type=prod,env-name=prod,build-type=custom --env-vars-file=____envvars.yaml --allow-unauthenticated",
|
|
872
872
|
"docker image rm asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
873
873
|
],
|
|
874
874
|
"services": [
|
|
@@ -966,7 +966,7 @@ _ALL_ENV_VAR_KEYS: '["ENV_SHORT","APP_DIR","ENV_TYPE","HOST","ROOT_URL","HOST_CA
|
|
|
966
966
|
"docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
967
967
|
"docker push asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
968
968
|
"echo "$ENV_VARS" > ____envvars.yaml",
|
|
969
|
-
"gcloud run deploy pan-test-app-stage-www
|
|
969
|
+
"gcloud run deploy pan-test-app-stage-www --image asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG --project asdf --region=asia-east1 --labels customer-name=pan,app-name=test-app,env-type=stage,env-name=stage,build-type=custom --env-vars-file=____envvars.yaml --allow-unauthenticated",
|
|
970
970
|
"docker image rm asia-east1-docker.pkg.dev/asdf/catladder-deploy/pan-test-app/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG",
|
|
971
971
|
],
|
|
972
972
|
"services": [
|
|
@@ -1046,7 +1046,7 @@ _ALL_ENV_VAR_KEYS: '["ENV_SHORT","APP_DIR","ENV_TYPE","HOST","ROOT_URL","HOST_CA
|
|
|
1046
1046
|
"echo $CL_prod_www_GCLOUD_DEPLOY_credentialsKey > ./____keyfile.json
|
|
1047
1047
|
",
|
|
1048
1048
|
"gcloud auth activate-service-account --key-file="./____keyfile.json"",
|
|
1049
|
-
"gcloud run services delete pan-test-app-prod-www --project
|
|
1049
|
+
"gcloud run services delete pan-test-app-prod-www --project asdf --region=asia-east1",
|
|
1050
1050
|
],
|
|
1051
1051
|
"stage": "stop prod",
|
|
1052
1052
|
"variables": {
|
|
@@ -1089,7 +1089,7 @@ _ALL_ENV_VAR_KEYS: '["ENV_SHORT","APP_DIR","ENV_TYPE","HOST","ROOT_URL","HOST_CA
|
|
|
1089
1089
|
"echo $CL_stage_www_GCLOUD_DEPLOY_credentialsKey > ./____keyfile.json
|
|
1090
1090
|
",
|
|
1091
1091
|
"gcloud auth activate-service-account --key-file="./____keyfile.json"",
|
|
1092
|
-
"gcloud run services delete pan-test-app-stage-www --project
|
|
1092
|
+
"gcloud run services delete pan-test-app-stage-www --project asdf --region=asia-east1",
|
|
1093
1093
|
],
|
|
1094
1094
|
"stage": "stop stage",
|
|
1095
1095
|
"variables": {
|
package/package.json
CHANGED
|
@@ -21,13 +21,11 @@ import {
|
|
|
21
21
|
} from "./utils/database";
|
|
22
22
|
import { allowFailureInScripts } from "../../utils/gitlab";
|
|
23
23
|
import { getCloudRunJobName } from "./utils/jobName";
|
|
24
|
-
import { createArgsString } from "./utils/createArgsString";
|
|
25
24
|
|
|
26
25
|
const setExtraVarsScripts = (deployConfig: DeployConfigCloudRun) => [
|
|
27
26
|
`export GCLOUD_PROJECT_NUMBER=$(gcloud projects describe ${deployConfig.projectId} --format="value(projectNumber)")`,
|
|
28
27
|
`echo "GCLOUD_PROJECT_NUMBER: $GCLOUD_PROJECT_NUMBER"`,
|
|
29
28
|
];
|
|
30
|
-
|
|
31
29
|
export const createGoogleCloudRunDeployJobs = (
|
|
32
30
|
context: Context
|
|
33
31
|
): CatladderJob[] => {
|
|
@@ -62,20 +60,11 @@ export const createGoogleCloudRunDeployJobs = (
|
|
|
62
60
|
.map(([key, value]) => `${key}=${value}`)
|
|
63
61
|
.join(",");
|
|
64
62
|
|
|
65
|
-
const commonArgs = {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const commonDeployArgs = {
|
|
71
|
-
image: gcloudImageName,
|
|
72
|
-
...commonArgs,
|
|
73
|
-
"set-cloudsql-instances": deployConfig.cloudSql
|
|
74
|
-
? deployConfig.cloudSql.instanceConnectionName
|
|
75
|
-
: undefined,
|
|
76
|
-
labels: labelsString,
|
|
77
|
-
};
|
|
78
|
-
|
|
63
|
+
const commonArgs = `--project ${deployConfig.projectId} --region=${deployConfig.region}`;
|
|
64
|
+
const cloudRunArgs = deployConfig.cloudSql
|
|
65
|
+
? `--set-cloudsql-instances=${deployConfig.cloudSql.instanceConnectionName}`
|
|
66
|
+
: "";
|
|
67
|
+
const commonDeployArgs = `--image ${gcloudImageName} ${commonArgs} ${cloudRunArgs} --labels ${labelsString}`;
|
|
79
68
|
const serviceName = context.environment.fullName.toLowerCase();
|
|
80
69
|
|
|
81
70
|
const getFullJobName = (name: string) =>
|
|
@@ -115,16 +104,25 @@ export const createGoogleCloudRunDeployJobs = (
|
|
|
115
104
|
? service?.command ?? context.componentConfig.build.startCommand
|
|
116
105
|
: undefined;
|
|
117
106
|
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
107
|
+
const commandArg = command
|
|
108
|
+
? `--command="${command.split(" ").join(",")}"`
|
|
109
|
+
: "";
|
|
110
|
+
|
|
111
|
+
const args = {
|
|
122
112
|
"allow-unauthenticated": true,
|
|
123
113
|
"min-instances": customConfig?.minInstances,
|
|
124
114
|
"max-instances": customConfig?.maxInstances,
|
|
125
115
|
"no-cpu-throttling": customConfig?.noCpuThrottling,
|
|
126
|
-
}
|
|
127
|
-
|
|
116
|
+
} as const;
|
|
117
|
+
|
|
118
|
+
const argsString = Object.entries(args)
|
|
119
|
+
.filter(([, value]) => !isNil(value))
|
|
120
|
+
.map(([key, value]) => `--${key}${value !== true ? `=${value}` : ""}`)
|
|
121
|
+
.join(" ");
|
|
122
|
+
|
|
123
|
+
return `gcloud run deploy ${serviceName}${
|
|
124
|
+
nameSuffix ?? ""
|
|
125
|
+
} ${commandArg} ${commonDeployArgs} --env-vars-file=____envvars.yaml ${argsString}`;
|
|
128
126
|
};
|
|
129
127
|
|
|
130
128
|
const getJobCreateScriptsForJob = (
|
|
@@ -135,28 +133,22 @@ export const createGoogleCloudRunDeployJobs = (
|
|
|
135
133
|
// lucky, update on the other hand accepts it... so let's just imediatly update it
|
|
136
134
|
|
|
137
135
|
// also we cannot upsert a job, so we have to create it and catch the error and then update
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
memory: job.memory || "512Mi",
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const argsString = `${jobName} ${commonDeployArgsString}`;
|
|
136
|
+
const args = `${jobName} --command="${job.command
|
|
137
|
+
.split(" ")
|
|
138
|
+
.join(",")}" ${commonDeployArgs} --memory=${job.memory || "512Mi"}`;
|
|
145
139
|
return [
|
|
146
|
-
...allowFailureInScripts([`gcloud beta run jobs create ${
|
|
147
|
-
`gcloud beta run jobs update ${
|
|
140
|
+
...allowFailureInScripts([`gcloud beta run jobs create ${args}`]),
|
|
141
|
+
`gcloud beta run jobs update ${args} --env-vars-file=____envvars.yaml`,
|
|
148
142
|
];
|
|
149
143
|
};
|
|
150
144
|
|
|
151
|
-
const commonArgsString = createArgsString(commonArgs);
|
|
152
|
-
|
|
153
145
|
const getJobCreateScripts = () =>
|
|
154
146
|
jobsWithNames
|
|
155
147
|
.map(({ job, jobName }) => getJobCreateScriptsForJob(jobName, job))
|
|
156
148
|
.flat();
|
|
157
149
|
|
|
158
150
|
const getJobRunScriptForJob = (jobName: string) => {
|
|
159
|
-
return `gcloud beta run jobs execute ${jobName} ${
|
|
151
|
+
return `gcloud beta run jobs execute ${jobName} ${commonArgs}`;
|
|
160
152
|
};
|
|
161
153
|
|
|
162
154
|
const getJobRunScripts = (when: DeployConfigCloudRunJob["when"]) =>
|
|
@@ -167,16 +159,11 @@ export const createGoogleCloudRunDeployJobs = (
|
|
|
167
159
|
const getCreateScheduleScripts = () => {
|
|
168
160
|
return jobsWithSchedule
|
|
169
161
|
.map(({ job, jobName, schedulerName }) => {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
"http-method": "POST",
|
|
176
|
-
"oauth-service-account-email":
|
|
177
|
-
"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com",
|
|
178
|
-
});
|
|
179
|
-
const commonArgs = `http ${schedulerName} ${argsString}`;
|
|
162
|
+
const commonArgs = `http ${schedulerName} --project=${deployConfig.projectId} --location ${deployConfig.region} \
|
|
163
|
+
--schedule="${job.schedule}" \
|
|
164
|
+
--uri="https://${deployConfig.region}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${deployConfig.projectId}/jobs/${jobName}:run" \
|
|
165
|
+
--http-method POST \
|
|
166
|
+
--oauth-service-account-email $GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com`;
|
|
180
167
|
return [
|
|
181
168
|
...allowFailureInScripts([
|
|
182
169
|
`gcloud scheduler jobs create ${commonArgs}`,
|
|
@@ -188,15 +175,11 @@ export const createGoogleCloudRunDeployJobs = (
|
|
|
188
175
|
};
|
|
189
176
|
|
|
190
177
|
const getDeleteSchedulesScripts = () => {
|
|
191
|
-
const argsString = createArgsString({
|
|
192
|
-
project: deployConfig.projectId,
|
|
193
|
-
location: deployConfig.region,
|
|
194
|
-
});
|
|
195
178
|
return jobsWithSchedule
|
|
196
179
|
.map(({ schedulerName }) => {
|
|
197
180
|
return [
|
|
198
181
|
...allowFailureInScripts([
|
|
199
|
-
`gcloud scheduler jobs delete ${schedulerName} ${
|
|
182
|
+
`gcloud scheduler jobs delete ${schedulerName} --project=${deployConfig.projectId} --location ${deployConfig.region}`,
|
|
200
183
|
]),
|
|
201
184
|
];
|
|
202
185
|
})
|
|
@@ -205,8 +188,7 @@ export const createGoogleCloudRunDeployJobs = (
|
|
|
205
188
|
|
|
206
189
|
const getDeleteJobsScripts = () =>
|
|
207
190
|
jobsWithNames.map(
|
|
208
|
-
({ jobName }) =>
|
|
209
|
-
`gcloud beta run jobs delete ${jobName} ${commonArgsString}`
|
|
191
|
+
({ jobName }) => `gcloud beta run jobs delete ${jobName} ${commonArgs}`
|
|
210
192
|
);
|
|
211
193
|
|
|
212
194
|
const deployScripts = [
|
|
@@ -235,11 +217,11 @@ export const createGoogleCloudRunDeployJobs = (
|
|
|
235
217
|
const stopScripts = [
|
|
236
218
|
...gcloudServiceAccountLoginCommands(context),
|
|
237
219
|
...(deployConfig.service !== false
|
|
238
|
-
? [`gcloud run services delete ${serviceName} ${
|
|
220
|
+
? [`gcloud run services delete ${serviceName} ${commonArgs}`]
|
|
239
221
|
: []),
|
|
240
222
|
...Object.entries(deployConfig.additionalServices ?? {}).map(
|
|
241
223
|
([name]) =>
|
|
242
|
-
`gcloud run services delete ${serviceName}-${name} ${
|
|
224
|
+
`gcloud run services delete ${serviceName}-${name} ${commonArgs}`
|
|
243
225
|
),
|
|
244
226
|
...getDeleteSchedulesScripts(),
|
|
245
227
|
...getDeleteJobsScripts(),
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* creates arguments string:
|
|
3
|
-
*
|
|
4
|
-
* --key=value
|
|
5
|
-
*
|
|
6
|
-
* - undefined or null values will get removed completly
|
|
7
|
-
* - true will just be "--key"
|
|
8
|
-
* @param args args record
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
export declare const createArgsString: (args: Record<string, string | number | true | undefined>) => string;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __read = this && this.__read || function (o, n) {
|
|
4
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
5
|
-
if (!m) return o;
|
|
6
|
-
var i = m.call(o),
|
|
7
|
-
r,
|
|
8
|
-
ar = [],
|
|
9
|
-
e;
|
|
10
|
-
try {
|
|
11
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
12
|
-
} catch (error) {
|
|
13
|
-
e = {
|
|
14
|
-
error: error
|
|
15
|
-
};
|
|
16
|
-
} finally {
|
|
17
|
-
try {
|
|
18
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
19
|
-
} finally {
|
|
20
|
-
if (e) throw e.error;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
exports.__esModule = true;
|
|
26
|
-
exports.createArgsString = void 0;
|
|
27
|
-
var lodash_1 = require("lodash");
|
|
28
|
-
/**
|
|
29
|
-
* creates arguments string:
|
|
30
|
-
*
|
|
31
|
-
* --key=value
|
|
32
|
-
*
|
|
33
|
-
* - undefined or null values will get removed completly
|
|
34
|
-
* - true will just be "--key"
|
|
35
|
-
* @param args args record
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
|
-
var createArgsString = function (args) {
|
|
39
|
-
return Object.entries(args).filter(function (_a) {
|
|
40
|
-
var _b = __read(_a, 2),
|
|
41
|
-
value = _b[1];
|
|
42
|
-
return !(0, lodash_1.isNil)(value);
|
|
43
|
-
}).map(function (_a) {
|
|
44
|
-
var _b = __read(_a, 2),
|
|
45
|
-
key = _b[0],
|
|
46
|
-
value = _b[1];
|
|
47
|
-
return "--".concat(key).concat(value !== true ? "=".concat(value) : "");
|
|
48
|
-
}).join(" ");
|
|
49
|
-
};
|
|
50
|
-
exports.createArgsString = createArgsString;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { isNil } from "lodash";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* creates arguments string:
|
|
5
|
-
*
|
|
6
|
-
* --key=value
|
|
7
|
-
*
|
|
8
|
-
* - undefined or null values will get removed completly
|
|
9
|
-
* - true will just be "--key"
|
|
10
|
-
* @param args args record
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
export const createArgsString = (
|
|
14
|
-
args: Record<string, string | number | true | undefined>
|
|
15
|
-
) =>
|
|
16
|
-
Object.entries(args)
|
|
17
|
-
.filter(([, value]) => !isNil(value))
|
|
18
|
-
.map(([key, value]) => `--${key}${value !== true ? `=${value}` : ""}`)
|
|
19
|
-
.join(" ");
|