@catladder/pipeline 1.133.11 → 1.134.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.
Files changed (30) hide show
  1. package/dist/bundles/catladder-gitlab/index.js +2 -2
  2. package/dist/constants.js +1 -1
  3. package/dist/deploy/cloudRun/createJobs/cloudRunJobs.d.ts +7 -0
  4. package/dist/deploy/cloudRun/createJobs/cloudRunJobs.js +178 -0
  5. package/dist/deploy/cloudRun/createJobs/cloudRunServices.d.ts +4 -0
  6. package/dist/deploy/cloudRun/createJobs/cloudRunServices.js +53 -0
  7. package/dist/deploy/cloudRun/createJobs/common.d.ts +15 -0
  8. package/dist/deploy/cloudRun/createJobs/common.js +78 -0
  9. package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.d.ts +2 -0
  10. package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +56 -0
  11. package/dist/deploy/cloudRun/createJobs/getCloudRunStopScripts.d.ts +2 -0
  12. package/dist/deploy/cloudRun/createJobs/getCloudRunStopScripts.js +52 -0
  13. package/dist/deploy/cloudRun/createJobs/index.d.ts +3 -0
  14. package/dist/deploy/cloudRun/createJobs/index.js +43 -0
  15. package/dist/deploy/cloudRun/createJobs/variables.d.ts +5 -0
  16. package/dist/deploy/cloudRun/createJobs/variables.js +19 -0
  17. package/dist/deploy/cloudRun/index.js +2 -2
  18. package/dist/tsconfig.tsbuildinfo +1 -1
  19. package/package.json +1 -1
  20. package/src/deploy/cloudRun/createJobs/cloudRunJobs.ts +178 -0
  21. package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +70 -0
  22. package/src/deploy/cloudRun/createJobs/common.ts +46 -0
  23. package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +58 -0
  24. package/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.ts +34 -0
  25. package/src/deploy/cloudRun/createJobs/index.ts +45 -0
  26. package/src/deploy/cloudRun/createJobs/variables.ts +21 -0
  27. package/src/deploy/cloudRun/index.ts +1 -1
  28. package/dist/deploy/cloudRun/deployJob.d.ts +0 -3
  29. package/dist/deploy/cloudRun/deployJob.js +0 -261
  30. package/src/deploy/cloudRun/deployJob.ts +0 -318
package/dist/constants.js CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.DOCKER_REGISTRY = exports.PIPELINE_IMAGE_TAG = void 0;
5
- exports.PIPELINE_IMAGE_TAG = "v1-133-11-4be9038e" || "";
5
+ exports.PIPELINE_IMAGE_TAG = "v1-134-1-add2933c" || "";
6
6
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "";
@@ -0,0 +1,7 @@
1
+ import type { Context } from "../../../types/context";
2
+ import type { DeployConfigCloudRunJob } from "../../types/googleCloudRun";
3
+ export declare const getDeleteSchedulesScripts: (context: Context) => string[];
4
+ export declare const getDeleteJobsScripts: (context: Context) => string[];
5
+ export declare const getJobRunScripts: (context: Context, when: DeployConfigCloudRunJob["when"]) => string[];
6
+ export declare const getJobCreateScripts: (context: Context) => string[];
7
+ export declare const getCreateScheduleScripts: (context: Context) => string[];
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ var __assign = this && this.__assign || function () {
4
+ __assign = Object.assign || function (t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __read = this && this.__read || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o),
17
+ r,
18
+ ar = [],
19
+ e;
20
+ try {
21
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
+ } catch (error) {
23
+ e = {
24
+ error: error
25
+ };
26
+ } finally {
27
+ try {
28
+ if (r && !r.done && (m = i["return"])) m.call(i);
29
+ } finally {
30
+ if (e) throw e.error;
31
+ }
32
+ }
33
+ return ar;
34
+ };
35
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
36
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
37
+ if (ar || !(i in from)) {
38
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
39
+ ar[i] = from[i];
40
+ }
41
+ }
42
+ return to.concat(ar || Array.prototype.slice.call(from));
43
+ };
44
+ exports.__esModule = true;
45
+ exports.getCreateScheduleScripts = exports.getJobCreateScripts = exports.getJobRunScripts = exports.getDeleteJobsScripts = exports.getDeleteSchedulesScripts = void 0;
46
+ var gitlab_1 = require("../../../utils/gitlab");
47
+ var createArgsString_1 = require("../utils/createArgsString");
48
+ var jobName_1 = require("../utils/jobName");
49
+ var common_1 = require("./common");
50
+ var getLabels_1 = require("../../../context/getLabels");
51
+ var getJobRunScriptForJob = function (context, jobName, wait) {
52
+ var commonArgs = (0, common_1.getCommonCloudRunArgs)(context);
53
+ var commonArgsString = (0, createArgsString_1.createArgsString)(commonArgs);
54
+ return "gcloud beta run jobs execute ".concat(jobName, " ").concat(commonArgsString).concat(wait ? " --wait" : "");
55
+ };
56
+ var getDeleteSchedulesScripts = function (context) {
57
+ var deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
58
+ var jobsWithSchedule = getCloudRunJobsWithSchedule(context);
59
+ var argsString = (0, createArgsString_1.createArgsString)({
60
+ project: deployConfig.projectId,
61
+ location: deployConfig.region
62
+ });
63
+ return jobsWithSchedule.map(function (_a) {
64
+ var schedulerName = _a.schedulerName;
65
+ return ["gcloud scheduler jobs delete ".concat(schedulerName, " ").concat(argsString)];
66
+ }).flat();
67
+ };
68
+ exports.getDeleteSchedulesScripts = getDeleteSchedulesScripts;
69
+ var getDeleteJobsScripts = function (context) {
70
+ var commonArgs = (0, common_1.getCommonCloudRunArgs)(context);
71
+ var commonArgsString = (0, createArgsString_1.createArgsString)(commonArgs);
72
+ var jobsWithNames = getCloudRunJobsWithNames(context);
73
+ return jobsWithNames.flatMap(function (_a) {
74
+ var jobName = _a.jobName;
75
+ return [
76
+ // first delete all job executions. Otherwise delete might fail if one of those is still running
77
+ "gcloud beta run jobs executions list ".concat(commonArgsString, " --job ").concat(jobName, " --format=\"value(name)\" | xargs -I {} gcloud beta run jobs executions delete {} --quiet ").concat(commonArgsString), "gcloud beta run jobs delete ".concat(jobName, " ").concat(commonArgsString)];
78
+ });
79
+ };
80
+ exports.getDeleteJobsScripts = getDeleteJobsScripts;
81
+ var getJobRunScripts = function (context, when) {
82
+ var jobsWithNames = getCloudRunJobsWithNames(context);
83
+ return jobsWithNames.filter(function (_a) {
84
+ var job = _a.job;
85
+ return job.when === when;
86
+ }).map(function (_a) {
87
+ var jobName = _a.jobName;
88
+ return getJobRunScriptForJob(context, jobName,
89
+ // wait for completin on stop jobs, since stop will delete the jobs afterwards, so they will fail
90
+ ["preStop", "postStop"].includes(when));
91
+ });
92
+ };
93
+ exports.getJobRunScripts = getJobRunScripts;
94
+ var getJobCreateScripts = function (context) {
95
+ var jobsWithNames = getCloudRunJobsWithNames(context);
96
+ return jobsWithNames.map(function (_a) {
97
+ var job = _a.job,
98
+ jobName = _a.jobName;
99
+ return getJobCreateScriptsForJob(context, jobName, job);
100
+ }).flat();
101
+ };
102
+ exports.getJobCreateScripts = getJobCreateScripts;
103
+ var getJobCreateScriptsForJob = function (context, jobName, job) {
104
+ var commonDeployArgs = (0, common_1.getCommonDeployArgs)(context);
105
+ // due to some oversight from google, jobs create does not accept `--env-vars-file` 🤦
106
+ // lucky, update on the other hand accepts it... so let's just imediatly update it
107
+ // also we cannot upsert a job, so we have to create it and catch the error and then update
108
+ var commandArray = Array.isArray(job.command) ? job.command : job.command.split(" ");
109
+ var commonDeployArgsString = (0, createArgsString_1.createArgsString)(__assign(__assign({
110
+ command: '"' + commandArray.join(",") + '"'
111
+ }, commonDeployArgs), {
112
+ labels: (0, common_1.makeLabelString)(__assign(__assign({}, (0, getLabels_1.getLabels)(context)), {
113
+ "cloud-run-job-name": jobName
114
+ })),
115
+ image: job.image || commonDeployArgs.image,
116
+ memory: job.memory || "512Mi",
117
+ "task-timeout": job.timeout || "10m"
118
+ }));
119
+ var argsString = "".concat(jobName, " ").concat(commonDeployArgsString);
120
+ return __spreadArray(__spreadArray([], __read((0, gitlab_1.allowFailureInScripts)(["gcloud beta run jobs create ".concat(argsString)])), false), ["gcloud beta run jobs update ".concat(argsString, " --env-vars-file=____envvars.yaml")], false);
121
+ };
122
+ var getCreateScheduleScripts = function (context) {
123
+ var jobsWithSchedule = getCloudRunJobsWithSchedule(context);
124
+ var deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
125
+ return jobsWithSchedule.map(function (_a) {
126
+ var _b;
127
+ var job = _a.job,
128
+ jobName = _a.jobName,
129
+ schedulerName = _a.schedulerName;
130
+ var argsString = (0, createArgsString_1.createArgsString)({
131
+ project: deployConfig.projectId,
132
+ location: deployConfig.region,
133
+ schedule: "\"".concat(job.schedule, "\""),
134
+ "max-retry-attempts": (_b = job.maxRetryAttempts) !== null && _b !== void 0 ? _b : 0,
135
+ uri: "\"https://".concat(deployConfig.region, "-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/").concat(deployConfig.projectId, "/jobs/").concat(jobName, ":run\""),
136
+ "http-method": "POST",
137
+ "oauth-service-account-email": "$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com"
138
+ });
139
+ var commonArgs = "http ".concat(schedulerName, " ").concat(argsString);
140
+ return __spreadArray(__spreadArray([], __read((0, gitlab_1.allowFailureInScripts)(["gcloud scheduler jobs create ".concat(commonArgs)])), false), ["gcloud scheduler jobs update ".concat(commonArgs)], false);
141
+ }).flat();
142
+ };
143
+ exports.getCreateScheduleScripts = getCreateScheduleScripts;
144
+ var getCloudRunJobsWithSchedule = function (context) {
145
+ var jobsWithNames = getCloudRunJobsWithNames(context);
146
+ return jobsWithNames.filter(function (entry) {
147
+ return entry.job.when === "schedule";
148
+ }).map(function (_a) {
149
+ var job = _a.job,
150
+ jobName = _a.jobName;
151
+ return {
152
+ job: job,
153
+ jobName: jobName,
154
+ schedulerName: jobName + "-scheduler"
155
+ };
156
+ });
157
+ };
158
+ var getCloudRunJobsWithNames = function (context) {
159
+ var _a;
160
+ var deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
161
+ var getFullJobName = function (name) {
162
+ return (0, jobName_1.getCloudRunJobName)(context.environment.fullName, name);
163
+ };
164
+ var jobsWithNames = Object.entries((_a = deployConfig.jobs) !== null && _a !== void 0 ? _a : {})
165
+ // filter out disabled jobs
166
+ .filter(function (entry) {
167
+ return Boolean(entry[1]);
168
+ }).map(function (_a) {
169
+ var _b = __read(_a, 2),
170
+ name = _b[0],
171
+ job = _b[1];
172
+ return {
173
+ jobName: getFullJobName(name),
174
+ job: job
175
+ };
176
+ });
177
+ return jobsWithNames;
178
+ };
@@ -0,0 +1,4 @@
1
+ import type { Context } from "../../../types/context";
2
+ import type { DeployConfigCloudRunService } from "../../types/googleCloudRun";
3
+ export declare const getServiceDeployScript: (context: Context, service: DeployConfigCloudRunService | true | undefined, nameSuffix?: string | undefined) => string;
4
+ export declare const getServiceDeleteScript: (context: Context, serviceSuffix?: string | undefined) => string[];
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ var __assign = this && this.__assign || function () {
4
+ __assign = Object.assign || function (t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ exports.__esModule = true;
14
+ exports.getServiceDeleteScript = exports.getServiceDeployScript = void 0;
15
+ var getLabels_1 = require("../../../context/getLabels");
16
+ var createArgsString_1 = require("../utils/createArgsString");
17
+ var getServiceName_1 = require("../utils/getServiceName");
18
+ var common_1 = require("./common");
19
+ var getServiceDeployScript = function (context, service, nameSuffix) {
20
+ var _a, _b, _c, _d, _e;
21
+ var commonDeployArgs = (0, common_1.getCommonDeployArgs)(context);
22
+ var serviceName = (0, getServiceName_1.getServiceName)(context);
23
+ var customConfig = service !== true ? service : undefined;
24
+ var command = service !== true ? (_a = service === null || service === void 0 ? void 0 : service.command) !== null && _a !== void 0 ? _a : context.componentConfig.build.startCommand : undefined;
25
+ var commandArray = command ? Array.isArray(command) ? command : command.split(" ") : undefined;
26
+ var fullServiceName = "".concat(serviceName).concat(nameSuffix !== null && nameSuffix !== void 0 ? nameSuffix : "");
27
+ var argsString = (0, createArgsString_1.createArgsString)(__assign(__assign({
28
+ // command as empty string resets it to default (uses the image's entrypoint)
29
+ command: commandArray ? '"' + commandArray.join(",") + '"' : '""'
30
+ }, commonDeployArgs), {
31
+ labels: (0, common_1.makeLabelString)(__assign(__assign({}, (0, getLabels_1.getLabels)(context)), {
32
+ "cloud-run-service-name": fullServiceName
33
+ })),
34
+ "env-vars-file": "____envvars.yaml",
35
+ "min-instances": (_b = customConfig === null || customConfig === void 0 ? void 0 : customConfig.minInstances) !== null && _b !== void 0 ? _b : 0,
36
+ "max-instances": (_c = customConfig === null || customConfig === void 0 ? void 0 : customConfig.maxInstances) !== null && _c !== void 0 ? _c : 100,
37
+ "cpu-throttling": (customConfig === null || customConfig === void 0 ? void 0 : customConfig.noCpuThrottling) !== true,
38
+ memory: customConfig === null || customConfig === void 0 ? void 0 : customConfig.memory,
39
+ "allow-unauthenticated": (_d = customConfig === null || customConfig === void 0 ? void 0 : customConfig.allowUnauthenticated) !== null && _d !== void 0 ? _d : true,
40
+ ingress: (_e = customConfig === null || customConfig === void 0 ? void 0 : customConfig.ingress) !== null && _e !== void 0 ? _e : "all",
41
+ "cpu-boost": true
42
+ }));
43
+ return "gcloud run deploy ".concat(fullServiceName, " ").concat(argsString);
44
+ };
45
+ exports.getServiceDeployScript = getServiceDeployScript;
46
+ var getServiceDeleteScript = function (context, serviceSuffix) {
47
+ var commonArgs = (0, common_1.getCommonCloudRunArgs)(context);
48
+ var commonArgsString = (0, createArgsString_1.createArgsString)(commonArgs);
49
+ var serviceName = (0, getServiceName_1.getServiceName)(context);
50
+ var fullServiceName = serviceSuffix ? "".concat(serviceName, "-").concat(serviceSuffix) : serviceName;
51
+ return ["gcloud run services delete ".concat(fullServiceName, " ").concat(commonArgsString)];
52
+ };
53
+ exports.getServiceDeleteScript = getServiceDeleteScript;
@@ -0,0 +1,15 @@
1
+ import type { Context } from "../../../types/context";
2
+ import type { DeployConfigCloudRun } from "../../types/googleCloudRun";
3
+ export declare const setGoogleProjectNumberScript: (deployConfig: DeployConfigCloudRun) => string[];
4
+ export declare const makeLabelString: (obj: Record<string, unknown>) => string;
5
+ export declare const getCloudRunDeployConfig: (context: Context) => DeployConfigCloudRun;
6
+ export declare function getCommonCloudRunArgs(context: Context): {
7
+ project: string;
8
+ region: import("../../types").Gcloudregion;
9
+ };
10
+ export declare function getCommonDeployArgs(context: Context): {
11
+ "set-cloudsql-instances": string | undefined;
12
+ project: string;
13
+ region: import("../../types").Gcloudregion;
14
+ image: string;
15
+ };
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ var __assign = this && this.__assign || function () {
4
+ __assign = Object.assign || function (t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __read = this && this.__read || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o),
17
+ r,
18
+ ar = [],
19
+ e;
20
+ try {
21
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
+ } catch (error) {
23
+ e = {
24
+ error: error
25
+ };
26
+ } finally {
27
+ try {
28
+ if (r && !r.done && (m = i["return"])) m.call(i);
29
+ } finally {
30
+ if (e) throw e.error;
31
+ }
32
+ }
33
+ return ar;
34
+ };
35
+ exports.__esModule = true;
36
+ exports.getCommonDeployArgs = exports.getCommonCloudRunArgs = exports.getCloudRunDeployConfig = exports.makeLabelString = exports.setGoogleProjectNumberScript = void 0;
37
+ var types_1 = require("../../types");
38
+ var artifactsRegistry_1 = require("../artifactsRegistry");
39
+ var setGoogleProjectNumberScript = function (deployConfig) {
40
+ return ["export GCLOUD_PROJECT_NUMBER=$(gcloud projects describe ".concat(deployConfig.projectId, " --format=\"value(projectNumber)\")"), "echo \"GCLOUD_PROJECT_NUMBER: $GCLOUD_PROJECT_NUMBER\""];
41
+ };
42
+ exports.setGoogleProjectNumberScript = setGoogleProjectNumberScript;
43
+ var makeLabelString = function (obj) {
44
+ return Object.entries(obj).map(function (_a) {
45
+ var _b = __read(_a, 2),
46
+ key = _b[0],
47
+ value = _b[1];
48
+ return "".concat(key, "=").concat(value);
49
+ }).join(",");
50
+ };
51
+ exports.makeLabelString = makeLabelString;
52
+ var getCloudRunDeployConfig = function (context) {
53
+ var deployConfig = context.componentConfig.deploy;
54
+ if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
55
+ // should not happen
56
+ throw new Error("deploy config is wrong");
57
+ }
58
+ return deployConfig;
59
+ };
60
+ exports.getCloudRunDeployConfig = getCloudRunDeployConfig;
61
+ function getCommonCloudRunArgs(context) {
62
+ var deployConfig = (0, exports.getCloudRunDeployConfig)(context);
63
+ return {
64
+ project: deployConfig.projectId,
65
+ region: deployConfig.region
66
+ };
67
+ }
68
+ exports.getCommonCloudRunArgs = getCommonCloudRunArgs;
69
+ function getCommonDeployArgs(context) {
70
+ var commonArgs = getCommonCloudRunArgs(context);
71
+ var deployConfig = (0, exports.getCloudRunDeployConfig)(context);
72
+ return __assign(__assign({
73
+ image: (0, artifactsRegistry_1.getArtifactsRegistryImage)(context)
74
+ }, commonArgs), {
75
+ "set-cloudsql-instances": deployConfig.cloudSql ? deployConfig.cloudSql.instanceConnectionName : undefined
76
+ });
77
+ }
78
+ exports.getCommonDeployArgs = getCommonDeployArgs;
@@ -0,0 +1,2 @@
1
+ import type { Context } from "../../../types/context";
2
+ export declare function getCloudRunDeployScripts(context: Context): string[];
@@ -0,0 +1,56 @@
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
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
26
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
27
+ if (ar || !(i in from)) {
28
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
29
+ ar[i] = from[i];
30
+ }
31
+ }
32
+ return to.concat(ar || Array.prototype.slice.call(from));
33
+ };
34
+ exports.__esModule = true;
35
+ exports.getCloudRunDeployScripts = void 0;
36
+ var gitlab_1 = require("../../../utils/gitlab");
37
+ var sbom_1 = require("../../sbom");
38
+ var cleanup_1 = require("../cleanup");
39
+ var database_1 = require("../utils/database");
40
+ var gcloudServiceAccountLoginCommands_1 = require("../utils/gcloudServiceAccountLoginCommands");
41
+ var cloudRunJobs_1 = require("./cloudRunJobs");
42
+ var cloudRunServices_1 = require("./cloudRunServices");
43
+ var common_1 = require("./common");
44
+ function getCloudRunDeployScripts(context) {
45
+ var _a;
46
+ var deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
47
+ return __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((0, gitlab_1.collapseableSection)("prepare", "Prepare...")(__spreadArray(__spreadArray([], __read((0, gcloudServiceAccountLoginCommands_1.gcloudServiceAccountLoginCommands)(context)), false), __read((0, common_1.setGoogleProjectNumberScript)(deployConfig)), false))), false), __read((0, gitlab_1.collapseableSection)("deploy", "Deploy to cloud run")(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(["echo \"$ENV_VARS\" > ____envvars.yaml"], __read(deployConfig.cloudSql ? (0, database_1.getDatabaseCreateScript)(context, deployConfig) // we create the db, so that we can also delete it afterwards
48
+ : []), false), __read((0, cloudRunJobs_1.getCreateScheduleScripts)(context)), false), __read((0, cloudRunJobs_1.getJobCreateScripts)(context)), false), __read((0, cloudRunJobs_1.getJobRunScripts)(context, "preDeploy")), false), __read(deployConfig.service !== false ? [(0, cloudRunServices_1.getServiceDeployScript)(context, deployConfig.service)] : []), false), __read(Object.entries((_a = deployConfig.additionalServices) !== null && _a !== void 0 ? _a : {}).map(function (_a) {
49
+ var _b = __read(_a, 2),
50
+ name = _b[0],
51
+ service = _b[1];
52
+ return (0, cloudRunServices_1.getServiceDeployScript)(context, service, "-" + name);
53
+ })), false), __read((0, cloudRunJobs_1.getJobRunScripts)(context, "postDeploy")), false))), false), __read((0, gitlab_1.collapseableSection)("cleanup", "Cleanup")((0, cleanup_1.getRemoveOldRevisionsAndImagesCommand)(context, "postDeploy") // we cleanup inactive images both on deploy and stop
54
+ )), false), __read((0, sbom_1.getDependencyTrackUploadScript)(context)), false);
55
+ }
56
+ exports.getCloudRunDeployScripts = getCloudRunDeployScripts;
@@ -0,0 +1,2 @@
1
+ import type { Context } from "../../../types/context";
2
+ export declare function getCloudRunStopScripts(context: Context): string[];
@@ -0,0 +1,52 @@
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
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
26
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
27
+ if (ar || !(i in from)) {
28
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
29
+ ar[i] = from[i];
30
+ }
31
+ }
32
+ return to.concat(ar || Array.prototype.slice.call(from));
33
+ };
34
+ exports.__esModule = true;
35
+ exports.getCloudRunStopScripts = void 0;
36
+ var sbom_1 = require("../../sbom");
37
+ var cleanup_1 = require("../cleanup");
38
+ var database_1 = require("../utils/database");
39
+ var gcloudServiceAccountLoginCommands_1 = require("../utils/gcloudServiceAccountLoginCommands");
40
+ var cloudRunJobs_1 = require("./cloudRunJobs");
41
+ var cloudRunServices_1 = require("./cloudRunServices");
42
+ var common_1 = require("./common");
43
+ function getCloudRunStopScripts(context) {
44
+ var _a;
45
+ var deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
46
+ return __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((0, gcloudServiceAccountLoginCommands_1.gcloudServiceAccountLoginCommands)(context)), false), __read((0, cloudRunJobs_1.getJobRunScripts)(context, "preStop")), false), __read(deployConfig.service !== false ? (0, cloudRunServices_1.getServiceDeleteScript)(context) : []), false), __read(Object.entries((_a = deployConfig.additionalServices) !== null && _a !== void 0 ? _a : {}).flatMap(function (_a) {
47
+ var _b = __read(_a, 1),
48
+ name = _b[0];
49
+ return (0, cloudRunServices_1.getServiceDeleteScript)(context, name);
50
+ })), false), __read((0, cloudRunJobs_1.getJobRunScripts)(context, "postStop")), false), __read((0, cloudRunJobs_1.getDeleteSchedulesScripts)(context)), false), __read((0, cloudRunJobs_1.getDeleteJobsScripts)(context)), false), __read(deployConfig.cloudSql && deployConfig.cloudSql.deleteDatabaseOnStop ? (0, database_1.getDatabaseDeleteScript)(context, deployConfig) : []), false), __read((0, cleanup_1.getRemoveOldRevisionsAndImagesCommand)(context, "onStop")), false), __read((0, sbom_1.getDependencyTrackDeleteScript)(context)), false);
51
+ }
52
+ exports.getCloudRunStopScripts = getCloudRunStopScripts;
@@ -0,0 +1,3 @@
1
+ import type { Context } from "../../../types/context";
2
+ import type { CatladderJob } from "../../../types/jobs";
3
+ export declare const createGoogleCloudRunDeployJobs: (context: Context) => CatladderJob[];
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.createGoogleCloudRunDeployJobs = void 0;
5
+ var lodash_1 = require("lodash");
6
+ var docker_1 = require("../../../build/docker");
7
+ var runner_1 = require("../../../runner");
8
+ var gitlab_1 = require("../../../utils/gitlab");
9
+ var base_1 = require("../../base");
10
+ var types_1 = require("../../types");
11
+ var variables_1 = require("./variables");
12
+ var getCloudRunDeployScripts_1 = require("./getCloudRunDeployScripts");
13
+ var getCloudRunStopScripts_1 = require("./getCloudRunStopScripts");
14
+ var createGoogleCloudRunDeployJobs = function (context) {
15
+ var deployConfig = context.componentConfig.deploy;
16
+ if (deployConfig === false) {
17
+ return [];
18
+ }
19
+ if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) {
20
+ // should not happen
21
+ throw new Error("deploy config is wrong");
22
+ }
23
+ var deployScripts = (0, getCloudRunDeployScripts_1.getCloudRunDeployScripts)(context);
24
+ var stopScripts = (0, getCloudRunStopScripts_1.getCloudRunStopScripts)(context);
25
+ return (0, base_1.createDeployementJobs)(context, {
26
+ deploy: (0, lodash_1.merge)((0, docker_1.getDockerJobBaseProps)(context), {
27
+ artifacts: {
28
+ paths: ["____envvars.yaml"]
29
+ },
30
+ variables: (0, variables_1.getDeployJobVariables)(context),
31
+ image: (0, runner_1.getRunnerImage)("gcloud"),
32
+ script: deployScripts
33
+ }),
34
+ stop: {
35
+ image: (0, runner_1.getRunnerImage)("gcloud"),
36
+ variables: {
37
+ CLOUDSDK_CORE_DISABLE_PROMPTS: "1"
38
+ },
39
+ script: (0, gitlab_1.allowFailureInScripts)(stopScripts)
40
+ }
41
+ });
42
+ };
43
+ exports.createGoogleCloudRunDeployJobs = createGoogleCloudRunDeployJobs;
@@ -0,0 +1,5 @@
1
+ import type { Context } from "../../../types/context";
2
+ export declare function getDeployJobVariables(context: Context): {
3
+ CLOUDSDK_CORE_DISABLE_PROMPTS: string;
4
+ ENV_VARS: string;
5
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.getDeployJobVariables = void 0;
5
+ var js_yaml_1 = require("js-yaml");
6
+ var lodash_1 = require("lodash");
7
+ var __1 = require("../../..");
8
+ function getDeployJobVariables(context) {
9
+ var allEnvVars = (0, lodash_1.omit)(context.environment.envVars, __1.GCLOUD_DEPLOY_CREDENTIALS_KEY);
10
+ return {
11
+ CLOUDSDK_CORE_DISABLE_PROMPTS: "1",
12
+ ENV_VARS: (0, js_yaml_1.dump)(allEnvVars, {
13
+ lineWidth: -1,
14
+ quotingType: "'",
15
+ forceQuotes: true
16
+ })
17
+ };
18
+ }
19
+ exports.getDeployJobVariables = getDeployJobVariables;
@@ -46,7 +46,7 @@ exports.GCLOUD_RUN_DEPLOY_TYPE = exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = expo
46
46
  var context_1 = require("../../context");
47
47
  var gitlab_1 = require("../../utils/gitlab");
48
48
  var utils_1 = require("../cloudSql/utils");
49
- var deployJob_1 = require("./deployJob");
49
+ var createJobs_1 = require("./createJobs");
50
50
  var jobName_1 = require("./utils/jobName");
51
51
  exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
52
52
  // FIXME: rename to internalHostSuffix, but this means that project-setup needs to be rerun, so its kindof a breaking change
@@ -78,7 +78,7 @@ var getCloudSqlVariables = function (_a) {
78
78
  return {};
79
79
  };
80
80
  exports.GCLOUD_RUN_DEPLOY_TYPE = {
81
- jobs: deployJob_1.createGoogleCloudRunDeployJobs,
81
+ jobs: createJobs_1.createGoogleCloudRunDeployJobs,
82
82
  defaults: function (_a) {
83
83
  var deployConfigRaw = _a.deployConfigRaw,
84
84
  envType = _a.envType;