@catladder/pipeline 2.6.3 → 2.7.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/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 = "v2-6-3-db90530a" || "latest";
7
+ exports.PIPELINE_IMAGE_TAG = "v2-7-1-2e399c09" || "latest";
8
8
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "git.panter.ch:5001/catladder/catladder";
@@ -67,14 +67,14 @@ var getJobRunScriptForJob = function (context, jobName, wait) {
67
67
  };
68
68
  var getDeleteSchedulesScripts = function (context) {
69
69
  var deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
70
- var jobsWithSchedule = getCloudRunJobsWithSchedule(context);
70
+ var schedules = getSchedules(context);
71
71
  var argsString = (0, createArgsString_1.createArgsString)({
72
72
  project: deployConfig.projectId,
73
73
  location: deployConfig.region
74
74
  });
75
- return jobsWithSchedule.map(function (_a) {
76
- var schedulerName = _a.schedulerName;
77
- return ["".concat((0, common_1.gcloudSchedulerCmd)(), " jobs delete ").concat(schedulerName, " ").concat(argsString)];
75
+ return schedules.map(function (_a) {
76
+ var name = _a.name;
77
+ return ["".concat((0, common_1.gcloudSchedulerCmd)(), " jobs delete ").concat(name, " ").concat(argsString)];
78
78
  }).flat();
79
79
  };
80
80
  exports.getDeleteSchedulesScripts = getDeleteSchedulesScripts;
@@ -108,81 +108,85 @@ var getJobRunScripts = function (context, when) {
108
108
  exports.getJobRunScripts = getJobRunScripts;
109
109
  var getJobCreateScripts = function (context) {
110
110
  return getCloudRunJobsWithNames(context).map(function (_a, jobIndex) {
111
- var _b = _a.job,
112
- command = _b.command,
113
- image = _b.image,
114
- cpu = _b.cpu,
115
- _c = _b.memory,
116
- memory = _c === void 0 ? "512Mi" : _c,
117
- _d = _b.timeout,
118
- timeout = _d === void 0 ? "10m" : _d,
119
- _e = _b.parallelism,
120
- parallelism = _e === void 0 ? 1 : _e,
121
- volumes = _b.volumes,
111
+ var _b, _c, _d, _e;
112
+ var job = _a.job,
122
113
  jobName = _a.jobName;
123
- var commandArray = Array.isArray(command) ? command : command.split(" ");
114
+ var commandArray = Array.isArray(job.command) ? job.command : job.command.split(" ");
124
115
  var _f = (0, common_1.getCommonDeployArgs)(context),
125
116
  commonImage = _f.image,
126
117
  project = _f.project,
127
118
  region = _f.region,
128
119
  deployArgs = __rest(_f, ["image", "project", "region"]);
129
- var commonDeployArgsString = createArgsString_1.createArgsString.apply(void 0, __spreadArray([__assign({
120
+ var commonDeployArgsString = createArgsString_1.createArgsString.apply(void 0, __spreadArray([__assign(__assign({
130
121
  command: "\"".concat(commandArray.join(","), "\""),
131
122
  labels: "\"".concat((0, common_1.makeLabelString)((0, getLabels_1.getLabels)(context)), ",cloud-run-job-name=$current_job_name\""),
132
- image: "\"".concat(image !== null && image !== void 0 ? image : commonImage, "\""),
123
+ image: "\"".concat((_b = job.image) !== null && _b !== void 0 ? _b : commonImage, "\""),
133
124
  project: project,
134
125
  region: region,
135
- cpu: cpu,
136
- memory: memory,
137
- parallelism: parallelism,
138
- "task-timeout": timeout,
126
+ cpu: job.cpu,
127
+ memory: (_c = job.memory) !== null && _c !== void 0 ? _c : "512Mi",
128
+ parallelism: (_d = job.parallelism) !== null && _d !== void 0 ? _d : 1,
129
+ "task-timeout": (_e = job.timeout) !== null && _e !== void 0 ? _e : "10m",
139
130
  "env-vars-file": constants_1.ENV_VARS_FILENAME,
140
131
  "max-retries": 0
141
- }, deployArgs)], __read((0, volumes_1.createVolumeConfig)(volumes, "job")), false));
132
+ }, deployArgs), {
133
+ // network
134
+ "vpc-connector": job === null || job === void 0 ? void 0 : job.vpcConnector,
135
+ "vpc-egress": job === null || job === void 0 ? void 0 : job.vpcEgress,
136
+ network: job === null || job === void 0 ? void 0 : job.network,
137
+ subnet: job === null || job === void 0 ? void 0 : job.subnet
138
+ })], __read((0, volumes_1.createVolumeConfig)(job.volumes, "job")), false));
142
139
  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)(), " jobs update \"$current_job_name\" ").concat(commonDeployArgsString), "else", " ".concat((0, common_1.gcloudRunCmd)(), " jobs create \"$current_job_name\" ").concat(commonDeployArgsString), "fi"].filter(utils_1.notNil).join("\n");
143
140
  });
144
141
  };
145
142
  exports.getJobCreateScripts = getJobCreateScripts;
146
143
  var getCreateScheduleScripts = function (context) {
147
- var jobsWithSchedule = getCloudRunJobsWithSchedule(context);
144
+ var schedules = getSchedules(context);
148
145
  var _a = (0, common_1.getCloudRunDeployConfig)(context),
149
146
  location = _a.region,
150
147
  project = _a.projectId;
151
- var uriBase = "https://".concat(location, "-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/").concat(project, "/jobs");
152
- var gcloudArgs = {
153
- project: project,
154
- location: location,
155
- uri: "\"$current_job_uri\"",
156
- "http-method": "POST",
157
- "oauth-service-account-email": "\"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com\""
158
- };
159
- return jobsWithSchedule.map(function (_a, jobIndex) {
160
- var _b = _a.job,
161
- maxRetryAttempts = _b.maxRetryAttempts,
162
- schedule = _b.schedule,
163
- jobName = _a.jobName,
164
- schedulerName = _a.schedulerName;
165
- var argsString = (0, createArgsString_1.createArgsString)(__assign(__assign({}, gcloudArgs), {
166
- schedule: "\"".concat(schedule, "\""),
167
- "max-retry-attempts": maxRetryAttempts !== null && maxRetryAttempts !== void 0 ? maxRetryAttempts : 0
168
- }));
169
- 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");
148
+ return schedules.map(function (scheduler, jobIndex) {
149
+ var _a;
150
+ var uri = getSchedulerUrl(scheduler, context);
151
+ var argsString = (0, createArgsString_1.createArgsString)({
152
+ project: project,
153
+ location: location,
154
+ uri: "\"$current_job_uri\"",
155
+ "http-method": "POST",
156
+ "oauth-service-account-email": "\"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com\"",
157
+ schedule: "\"".concat(scheduler.schedule, "\""),
158
+ "max-retry-attempts": (_a = scheduler.maxRetryAttempts) !== null && _a !== void 0 ? _a : 0
159
+ });
160
+ 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(uri, "\""), "current_scheduler_name=\"".concat(scheduler.name, "\""), "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");
170
161
  });
171
162
  };
172
163
  exports.getCreateScheduleScripts = getCreateScheduleScripts;
173
- var getCloudRunJobsWithSchedule = function (context) {
164
+ var getSchedulerUrl = function (scheduler, context) {
165
+ if (scheduler.type === "cloudRunJob") {
166
+ var _a = (0, common_1.getCloudRunDeployConfig)(context),
167
+ location_1 = _a.region,
168
+ project = _a.projectId;
169
+ var uriBase = "https://".concat(location_1, "-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/").concat(project, "/jobs");
170
+ return "".concat(uriBase, "/").concat(scheduler.jobName, ":run");
171
+ }
172
+ throw new Error("Unknown scheduler type: ".concat(scheduler.type));
173
+ };
174
+ var getSchedules = function (context) {
174
175
  var jobsWithNames = getCloudRunJobsWithNames(context);
175
176
  return jobsWithNames.filter(function (entry) {
176
177
  return entry.job.when === "schedule";
177
178
  }).map(function (_a) {
178
- var job = _a.job,
179
- jobName = _a.jobName,
180
- jobKey = _a.jobKey;
179
+ var _b = _a.job,
180
+ maxRetryAttempts = _b.maxRetryAttempts,
181
+ schedule = _b.schedule,
182
+ jobName = _a.jobName;
183
+ var schedulerName = jobName.concat("-scheduler");
181
184
  return {
182
- job: job,
183
- jobName: jobName,
184
- jobKey: jobKey,
185
- schedulerName: jobName.concat("-scheduler")
185
+ name: schedulerName,
186
+ maxRetryAttempts: maxRetryAttempts,
187
+ schedule: schedule,
188
+ type: "cloudRunJob",
189
+ jobName: jobName
186
190
  };
187
191
  });
188
192
  };
@@ -106,6 +106,18 @@ export type DeployConfigCloudRunService = {
106
106
  * defaults to gen1 according to gcloud
107
107
  */
108
108
  executionEnvironment?: "gen2" | "gen1";
109
+ /**
110
+ * Use http2 end-to-end. See https://cloud.google.com/run/docs/configuring/http2
111
+ *
112
+ * Defaults to false.
113
+ *
114
+ * Your service needs to be able to handle http2 requests.
115
+ * Its recommended to use http2 without tls, since cloud run handles the encryption for you. (so called "h2c" (http2 cleartext))
116
+ *
117
+ */
118
+ http2?: boolean;
119
+ } & DeployConfigCloudRunWithVolumes & DeployConfigCloudRunNetworkConfig;
120
+ export type DeployConfigCloudRunNetworkConfig = {
109
121
  network?: string;
110
122
  /**
111
123
  * vpc subnet to use, see https://cloud.google.com/sdk/gcloud/reference/run/deploy#--subnet
@@ -119,17 +131,7 @@ export type DeployConfigCloudRunService = {
119
131
  * vpc connector
120
132
  */
121
133
  vpcConnector?: string;
122
- /**
123
- * Use http2 end-to-end. See https://cloud.google.com/run/docs/configuring/http2
124
- *
125
- * Defaults to false.
126
- *
127
- * Your service needs to be able to handle http2 requests.
128
- * Its recommended to use http2 without tls, since cloud run handles the encryption for you. (so called "h2c" (http2 cleartext))
129
- *
130
- */
131
- http2?: boolean;
132
- } & DeployConfigCloudRunWithVolumes;
134
+ };
133
135
  export type DeployConfigCloudRunJobBase = {
134
136
  /**
135
137
  * command
@@ -157,7 +159,7 @@ export type DeployConfigCloudRunJobBase = {
157
159
  * number of tasks that may run concurrently, defaults to 1
158
160
  */
159
161
  parallelism?: number;
160
- } & DeployConfigCloudRunWithVolumes;
162
+ } & DeployConfigCloudRunWithVolumes & DeployConfigCloudRunNetworkConfig;
161
163
  type Minute = string;
162
164
  type Hour = string;
163
165
  type DayOfMonth = string;