@catladder/pipeline 1.166.1 → 1.168.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/constants.js CHANGED
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DOCKER_REGISTRY = exports.PIPELINE_IMAGE_TAG = void 0;
7
- exports.PIPELINE_IMAGE_TAG = "v1-166-1-c0d1f049" || "latest";
7
+ exports.PIPELINE_IMAGE_TAG = "v1-168-0-99f1fffa" || "latest";
8
8
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "git.panter.ch:5001/catladder/catladder";
@@ -10,6 +10,14 @@ var __assign = this && this.__assign || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __rest = this && this.__rest || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
13
21
  var __read = this && this.__read || function (o, n) {
14
22
  var m = typeof Symbol === "function" && o[Symbol.iterator];
15
23
  if (!m) return o;
@@ -45,13 +53,13 @@ Object.defineProperty(exports, "__esModule", {
45
53
  value: true
46
54
  });
47
55
  exports.getCreateScheduleScripts = exports.getJobCreateScripts = exports.getJobRunScripts = exports.getDeleteJobsScripts = exports.getDeleteSchedulesScripts = void 0;
48
- var gitlab_1 = require("../../../utils/gitlab");
49
56
  var createArgsString_1 = require("../utils/createArgsString");
50
57
  var jobName_1 = require("../utils/jobName");
51
58
  var common_1 = require("./common");
52
59
  var getLabels_1 = require("../../../context/getLabels");
53
60
  var volumes_1 = require("./volumes");
54
61
  var constants_1 = require("./constants");
62
+ var utils_1 = require("../../../utils");
55
63
  var getJobRunScriptForJob = function (context, jobName, wait) {
56
64
  var commonArgs = (0, common_1.getCommonCloudRunArgs)(context);
57
65
  var commonArgsString = (0, createArgsString_1.createArgsString)(commonArgs);
@@ -96,58 +104,73 @@ var getJobRunScripts = function (context, when) {
96
104
  };
97
105
  exports.getJobRunScripts = getJobRunScripts;
98
106
  var getJobCreateScripts = function (context) {
99
- var jobsWithNames = getCloudRunJobsWithNames(context);
100
- return jobsWithNames.map(function (_a) {
101
- var job = _a.job,
107
+ return getCloudRunJobsWithNames(context).map(function (_a, jobIndex) {
108
+ var _b = _a.job,
109
+ command = _b.command,
110
+ image = _b.image,
111
+ cpu = _b.cpu,
112
+ _c = _b.memory,
113
+ memory = _c === void 0 ? "512Mi" : _c,
114
+ _d = _b.timeout,
115
+ timeout = _d === void 0 ? "10m" : _d,
116
+ _e = _b.parallelism,
117
+ parallelism = _e === void 0 ? 1 : _e,
118
+ volumes = _b.volumes,
102
119
  jobName = _a.jobName;
103
- return getJobCreateScriptsForJob(context, jobName, job);
104
- }).flat();
120
+ var commandArray = Array.isArray(command) ? command : command.split(" ");
121
+ var _f = (0, common_1.getCommonDeployArgs)(context),
122
+ commonImage = _f.image,
123
+ project = _f.project,
124
+ region = _f.region,
125
+ deployArgs = __rest(_f, ["image", "project", "region"]);
126
+ var commonDeployArgsString = (0, createArgsString_1.createArgsString)(__assign({
127
+ command: "\"".concat(commandArray.join(","), "\""),
128
+ labels: "\"".concat((0, common_1.makeLabelString)((0, getLabels_1.getLabels)(context)), ",cloud-run-job-name=$current_job_name\""),
129
+ image: "\"".concat(image !== null && image !== void 0 ? image : commonImage, "\""),
130
+ project: project,
131
+ region: region,
132
+ cpu: cpu,
133
+ memory: memory,
134
+ parallelism: parallelism,
135
+ "task-timeout": timeout,
136
+ "env-vars-file": constants_1.ENV_VARS_FILENAME,
137
+ "max-retries": 0
138
+ }, deployArgs));
139
+ // due to some oversight from google, jobs create does not yet accept `--add-volume` 🤦
140
+ // lucky, update on the other hand accepts it... so let's just imediatly update it
141
+ // we cannot upsert a job, so we have to create it and catch the error and then update
142
+ var hasVolumes = Object.keys(volumes || {}).length > 0;
143
+ var needsBeta = hasVolumes ? "beta" : undefined;
144
+ var volumeArgs = hasVolumes ? createArgsString_1.createArgsString.apply(void 0, __spreadArray([], __read((0, volumes_1.createVolumeConfig)(volumes, "job")), false)) : "";
145
+ return [jobIndex === 0 ? "exist_job_names=\"$(\n ".concat((0, common_1.gcloudRunCmd)(), " jobs list --filter='metadata.name ~ ").concat(context.env, ".*").concat(context.name, "' --format='value(name)' --limit=999 --project='").concat(project, "' --region='").concat(region, "'\n)\"") : null, "current_job_name=\"".concat(jobName, "\""), 'if grep "$current_job_name" <<<"$exist_job_names" >/dev/null; then', " ".concat((0, common_1.gcloudRunCmd)(needsBeta), " jobs update \"$current_job_name\" ").concat(commonDeployArgsString, " ").concat(volumeArgs), "else", " ".concat((0, common_1.gcloudRunCmd)(), " jobs create \"$current_job_name\" ").concat(commonDeployArgsString), "fi"].filter(utils_1.notNil).join("\n");
146
+ });
105
147
  };
106
148
  exports.getJobCreateScripts = getJobCreateScripts;
107
- var getJobCreateScriptsForJob = function (context, jobName, job) {
108
- var commonDeployArgs = (0, common_1.getCommonDeployArgs)(context);
109
- // due to some oversight from google, jobs create does not yet accept `--add-volume` 🤦
110
- // lucky, update on the other hand accepts it... so let's just imediatly update it
111
- // we cannot upsert a job, so we have to create it and catch the error and then update
112
- var commandArray = Array.isArray(job.command) ? job.command : job.command.split(" ");
113
- var commonDeployArgsString = (0, createArgsString_1.createArgsString)(__assign(__assign({
114
- command: '"' + commandArray.join(",") + '"'
115
- }, commonDeployArgs), {
116
- labels: (0, common_1.makeLabelString)(__assign(__assign({}, (0, getLabels_1.getLabels)(context)), {
117
- "cloud-run-job-name": jobName.toString()
118
- })),
119
- image: job.image || commonDeployArgs.image,
120
- cpu: job === null || job === void 0 ? void 0 : job.cpu,
121
- memory: job.memory || "512Mi",
122
- "task-timeout": job.timeout || "10m",
123
- parallelism: job.parallelism || 1,
124
- "env-vars-file": constants_1.ENV_VARS_FILENAME,
125
- "max-retries": 0
126
- }));
127
- var requiresBeta = (job === null || job === void 0 ? void 0 : job.volumes) && Object.keys(job === null || job === void 0 ? void 0 : job.volumes).length > 0;
128
- var argsString = "".concat(jobName, " ").concat(commonDeployArgsString);
129
- return __spreadArray(__spreadArray([], __read((0, gitlab_1.allowFailureInScripts)(["".concat((0, common_1.gcloudRunCmd)(), " jobs create ").concat(argsString)])), false), ["".concat((0, common_1.gcloudRunCmd)(requiresBeta ? "beta" : undefined), " jobs update ").concat(argsString, " ").concat(createArgsString_1.createArgsString.apply(void 0, __spreadArray([], __read((0, volumes_1.createVolumeConfig)(job === null || job === void 0 ? void 0 : job.volumes, "job")), false)))], false);
130
- };
131
149
  var getCreateScheduleScripts = function (context) {
132
150
  var jobsWithSchedule = getCloudRunJobsWithSchedule(context);
133
- var deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
134
- return jobsWithSchedule.map(function (_a) {
135
- var _b;
136
- var job = _a.job,
151
+ var _a = (0, common_1.getCloudRunDeployConfig)(context),
152
+ location = _a.region,
153
+ project = _a.projectId;
154
+ var uriBase = "https://".concat(location, "-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/").concat(project, "/jobs");
155
+ var gcloudArgs = {
156
+ project: project,
157
+ location: location,
158
+ uri: "\"$current_job_uri\"",
159
+ "http-method": "POST",
160
+ "oauth-service-account-email": "\"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com\""
161
+ };
162
+ return jobsWithSchedule.map(function (_a, jobIndex) {
163
+ var _b = _a.job,
164
+ maxRetryAttempts = _b.maxRetryAttempts,
165
+ schedule = _b.schedule,
137
166
  jobName = _a.jobName,
138
167
  schedulerName = _a.schedulerName;
139
- var argsString = (0, createArgsString_1.createArgsString)({
140
- project: deployConfig.projectId,
141
- location: deployConfig.region,
142
- schedule: "\"".concat(job.schedule, "\""),
143
- "max-retry-attempts": (_b = job.maxRetryAttempts) !== null && _b !== void 0 ? _b : 0,
144
- uri: "\"https://".concat(deployConfig.region, "-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/").concat(deployConfig.projectId, "/jobs/").concat(jobName, ":run\""),
145
- "http-method": "POST",
146
- "oauth-service-account-email": "$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com"
147
- });
148
- var commonArgs = "http ".concat(schedulerName, " ").concat(argsString);
149
- return __spreadArray(__spreadArray([], __read((0, gitlab_1.allowFailureInScripts)(["".concat((0, common_1.gcloudSchedulerCmd)(), " jobs create ").concat(commonArgs)])), false), ["".concat((0, common_1.gcloudSchedulerCmd)(), " jobs update ").concat(commonArgs)], false);
150
- }).flat();
168
+ var argsString = (0, createArgsString_1.createArgsString)(__assign(__assign({}, gcloudArgs), {
169
+ schedule: "\"".concat(schedule, "\""),
170
+ "max-retry-attempts": maxRetryAttempts !== null && maxRetryAttempts !== void 0 ? maxRetryAttempts : 0
171
+ }));
172
+ return [jobIndex === 0 ? "exist_scheduler_names=\"$(\n ".concat((0, common_1.gcloudSchedulerCmd)(), " jobs list --filter='httpTarget.uri ~ ").concat(context.env, ".*").concat(context.name, "' --format='value(name)' --limit=999 --location='").concat(location, "' --project='").concat(project, "'\n)\"") : null, "current_job_uri=\"".concat(uriBase, "/").concat(jobName, ":run\""), "current_scheduler_name=\"".concat(schedulerName, "\""), "if grep \"$current_scheduler_name\" <<<\"$exist_scheduler_names\" >/dev/null; then", " ".concat((0, common_1.gcloudSchedulerCmd)(), " jobs update http \"$current_scheduler_name\" ").concat(argsString), "else", " ".concat((0, common_1.gcloudSchedulerCmd)(), " jobs create http \"$current_scheduler_name\" ").concat(argsString), "fi"].filter(utils_1.notNil).join("\n");
173
+ });
151
174
  };
152
175
  exports.getCreateScheduleScripts = getCreateScheduleScripts;
153
176
  var getCloudRunJobsWithSchedule = function (context) {
@@ -156,10 +179,12 @@ var getCloudRunJobsWithSchedule = function (context) {
156
179
  return entry.job.when === "schedule";
157
180
  }).map(function (_a) {
158
181
  var job = _a.job,
159
- jobName = _a.jobName;
182
+ jobName = _a.jobName,
183
+ jobKey = _a.jobKey;
160
184
  return {
161
185
  job: job,
162
186
  jobName: jobName,
187
+ jobKey: jobKey,
163
188
  schedulerName: jobName.concat("-scheduler")
164
189
  };
165
190
  });
@@ -176,11 +201,12 @@ var getCloudRunJobsWithNames = function (context) {
176
201
  return Boolean(entry[1]);
177
202
  }).map(function (_a) {
178
203
  var _b = __read(_a, 2),
179
- name = _b[0],
204
+ jobKey = _b[0],
180
205
  job = _b[1];
181
206
  return {
182
- jobName: getFullJobName(name),
183
- job: job
207
+ jobName: getFullJobName(jobKey),
208
+ job: job,
209
+ jobKey: jobKey
184
210
  };
185
211
  });
186
212
  return jobsWithNames;
@@ -75,6 +75,7 @@ var getServiceDeployScript = function (context, service, nameSuffix) {
75
75
  timeout: customConfig === null || customConfig === void 0 ? void 0 : customConfig.timeout,
76
76
  "vpc-connector": customConfig === null || customConfig === void 0 ? void 0 : customConfig.vpcConnector,
77
77
  "vpc-egress": customConfig === null || customConfig === void 0 ? void 0 : customConfig.vpcEgress,
78
+ "use-http2": customConfig === null || customConfig === void 0 ? void 0 : customConfig.http2,
78
79
  "allow-unauthenticated": (_d = customConfig === null || customConfig === void 0 ? void 0 : customConfig.allowUnauthenticated) !== null && _d !== void 0 ? _d : true,
79
80
  ingress: (_e = customConfig === null || customConfig === void 0 ? void 0 : customConfig.ingress) !== null && _e !== void 0 ? _e : "all",
80
81
  "cpu-boost": true,
@@ -114,6 +114,16 @@ export type DeployConfigCloudRunService = {
114
114
  * vpc egress, see https://cloud.google.com/sdk/gcloud/reference/run/deploy#--vpc-egress
115
115
  */
116
116
  vpcEgress?: "all-traffic" | "private-ranges-only";
117
+ /**
118
+ * Use http2 end-to-end. See https://cloud.google.com/run/docs/configuring/http2
119
+ *
120
+ * Defaults to false.
121
+ *
122
+ * Your service needs to be able to handle http2 requests.
123
+ * Its recommended to use http2 without tls, since cloud run handles the encryption for you. (so called "h2c" (http2 cleartext))
124
+ *
125
+ */
126
+ http2?: boolean;
117
127
  } & DeployConfigCloudRunWithVolumes;
118
128
  export type DeployConfigCloudRunJobBase = {
119
129
  /**