@catladder/cli 0.0.0-main-99d0da33 → 0.0.0-main-ca4b8550

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 (36) hide show
  1. package/dist/bundles/catenv/index.js +304 -119
  2. package/dist/bundles/cli/index.js +296 -116
  3. package/dist/cli/src/apps/catenv/printVariables.js +4 -1
  4. package/dist/cli/src/apps/catenv/printVariables.js.map +1 -1
  5. package/dist/cli/src/apps/catenv/utils.d.ts +6 -2
  6. package/dist/cli/src/apps/catenv/utils.js +4 -2
  7. package/dist/cli/src/apps/catenv/utils.js.map +1 -1
  8. package/dist/pipeline/src/bash/bashEscape.d.ts +4 -1
  9. package/dist/pipeline/src/bash/bashEscape.js +4 -2
  10. package/dist/pipeline/src/bash/bashEscape.js.map +1 -1
  11. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.d.ts +5 -3
  12. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js +16 -105
  13. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js.map +1 -1
  14. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.d.ts +4 -0
  15. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.js +85 -0
  16. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.js.map +1 -0
  17. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/schedules.d.ts +3 -0
  18. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/schedules.js +136 -0
  19. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/schedules.js.map +1 -0
  20. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +5 -3
  21. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js.map +1 -1
  22. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.js +5 -3
  23. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.js.map +1 -1
  24. package/dist/pipeline/src/deploy/cloudRun/index.js +6 -2
  25. package/dist/pipeline/src/deploy/cloudRun/index.js.map +1 -1
  26. package/dist/pipeline/src/deploy/cloudRun/utils/cloudRunExecutionUrl.d.ts +6 -0
  27. package/dist/pipeline/src/deploy/cloudRun/utils/cloudRunExecutionUrl.js +11 -0
  28. package/dist/pipeline/src/deploy/cloudRun/utils/cloudRunExecutionUrl.js.map +1 -0
  29. package/dist/pipeline/src/deploy/cloudRun/utils/jobName.d.ts +5 -1
  30. package/dist/pipeline/src/deploy/cloudRun/utils/jobName.js +7 -1
  31. package/dist/pipeline/src/deploy/cloudRun/utils/jobName.js.map +1 -1
  32. package/dist/pipeline/src/deploy/types/googleCloudRun.d.ts +95 -1
  33. package/dist/tsconfig.tsbuildinfo +1 -1
  34. package/package.json +1 -1
  35. package/src/apps/catenv/printVariables.ts +4 -1
  36. package/src/apps/catenv/utils.ts +12 -3
@@ -77,7 +77,10 @@ const printVariables = async (config, choice) => {
77
77
  console.log(makeExportKeyValuestring(variables));
78
78
  };
79
79
  exports.printVariables = printVariables;
80
- const makeExportKeyValuestring = (variables) => (0, utils_1.makeKeyValueString)(variables, "export ");
80
+ const makeExportKeyValuestring = (variables) => (0, utils_1.makeKeyValueString)(variables, {
81
+ keyPrefix: "export ",
82
+ escapeOptions: { quoteMode: "always" },
83
+ });
81
84
  //# sourceMappingURL=printVariables.js.map
82
85
 
83
86
  /***/ }),
@@ -111,9 +114,11 @@ const getCurrentComponentAndEnvFromChoice = async (config, choice) => {
111
114
  };
112
115
  };
113
116
  exports.getCurrentComponentAndEnvFromChoice = getCurrentComponentAndEnvFromChoice;
114
- const makeKeyValueString = (variables, keyPrefix = "") => Object.entries(variables)
117
+ const makeKeyValueString = (variables, { keyPrefix, escapeOptions } = {
118
+ keyPrefix: "",
119
+ }) => Object.entries(variables)
115
120
  // quotes are important, otherwise line breaks don't work properly
116
- .map(([key, value]) => `${keyPrefix}${key}=${(0, pipeline_1.escapeForDotEnv)(value)}`)
121
+ .map(([key, value]) => `${keyPrefix}${key}=${(0, pipeline_1.escapeForDotEnv)(value, escapeOptions)}`)
117
122
  .join("\n");
118
123
  exports.makeKeyValueString = makeKeyValueString;
119
124
  const sanitizeEnvVarName = (name) => name.replace(/[\s\-.]+/g, "_");
@@ -959,14 +964,16 @@ exports.escapeSingleQuotes = escapeSingleQuotes;
959
964
  *
960
965
  * - other languages are currently only partially supported, since most .env implementations are slightly different
961
966
  */
962
- const escapeForDotEnv = (value) => {
967
+ const escapeForDotEnv = (value, options = {
968
+ quoteMode: "auto",
969
+ }) => {
963
970
  if (value === undefined || value === null) {
964
971
  return "";
965
972
  }
966
973
  if (typeof value === "string") {
967
974
  // if string contains newlines, we need to wrap it in quotes
968
975
  // we additionaly escape newlines, that give best compatibility
969
- if (value.includes("\n")) {
976
+ if (options.quoteMode === "always" || value.includes("\n")) {
970
977
  const newlinesReplaces = value.replace(/\n/g, "\\n");
971
978
  // default to ", but if this is not possible, we try to use ' or `
972
979
  const quote = value.includes(`"`)
@@ -3841,62 +3848,27 @@ exports.getDeleteUnusedRevisionsCommands = getDeleteUnusedRevisionsCommands;
3841
3848
  "use strict";
3842
3849
 
3843
3850
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3844
- exports.getCreateScheduleScripts = exports.getJobCreateScripts = exports.getJobRunScripts = exports.getDeleteJobsScripts = exports.getDeleteSchedulesScripts = void 0;
3851
+ exports.getCloudRunJobsWithNames = exports.getJobCreateScripts = exports.getDeleteJobsScripts = void 0;
3852
+ const getLabels_1 = __nccwpck_require__(920);
3853
+ const utils_1 = __nccwpck_require__(2497);
3845
3854
  const createArgsString_1 = __nccwpck_require__(9598);
3846
3855
  const jobName_1 = __nccwpck_require__(9626);
3847
3856
  const common_1 = __nccwpck_require__(3325);
3848
- const getLabels_1 = __nccwpck_require__(920);
3849
- const volumes_1 = __nccwpck_require__(847);
3850
3857
  const constants_1 = __nccwpck_require__(8865);
3851
- const utils_1 = __nccwpck_require__(2497);
3852
- const getJobRunScriptForJob = (context, jobName, wait) => {
3853
- const commonArgs = (0, common_1.getCommonCloudRunArgs)(context);
3854
- const commonArgsString = (0, createArgsString_1.createArgsString)(commonArgs);
3855
- return `${(0, common_1.gcloudRunCmd)()} jobs execute ${jobName.toString()} ${commonArgsString}${wait ? " --wait" : ""}`;
3856
- };
3857
- const getDeleteSchedulesScripts = (context) => {
3858
- const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
3859
- const schedules = getSchedules(context);
3860
- const argsString = (0, createArgsString_1.createArgsString)({
3861
- project: deployConfig.projectId,
3862
- location: deployConfig.region,
3863
- });
3864
- return schedules
3865
- .map(({ name }) => {
3866
- return [`${(0, common_1.gcloudSchedulerCmd)()} jobs delete ${name} ${argsString}`];
3867
- })
3868
- .flat();
3869
- };
3870
- exports.getDeleteSchedulesScripts = getDeleteSchedulesScripts;
3858
+ const volumes_1 = __nccwpck_require__(847);
3859
+ const onDeploy_1 = __nccwpck_require__(2358);
3871
3860
  const getDeleteJobsScripts = (context) => {
3872
3861
  const commonArgs = (0, common_1.getCommonCloudRunArgs)(context);
3873
3862
  const commonArgsString = (0, createArgsString_1.createArgsString)(commonArgs);
3874
- const jobsWithNames = getCloudRunJobsWithNames(context);
3875
- return jobsWithNames.flatMap(({ jobName }) => [
3863
+ const jobsWithNames = (0, exports.getCloudRunJobsWithNames)(context);
3864
+ return jobsWithNames.flatMap(({ fullJobName }) => [
3876
3865
  // first delete all job executions. Otherwise delete might fail if one of those is still running
3877
- `${(0, common_1.gcloudRunCmd)()} jobs executions list ${commonArgsString} --job ${jobName} --format="value(name)" | xargs -I {} ${(0, common_1.gcloudRunCmd)()} jobs executions delete {} --quiet ${commonArgsString}`,
3878
- `${(0, common_1.gcloudRunCmd)()} jobs delete ${jobName} ${commonArgsString}`,
3866
+ `${(0, common_1.gcloudRunCmd)()} jobs executions list ${commonArgsString} --job ${fullJobName} --format="value(name)" | xargs -I {} ${(0, common_1.gcloudRunCmd)()} jobs executions delete {} --quiet ${commonArgsString}`,
3867
+ `${(0, common_1.gcloudRunCmd)()} jobs delete ${fullJobName} ${commonArgsString}`,
3879
3868
  ]);
3880
3869
  };
3881
3870
  exports.getDeleteJobsScripts = getDeleteJobsScripts;
3882
- const getJobRunScripts = (context, when) => {
3883
- const jobsWithNames = getCloudRunJobsWithNames(context);
3884
- return jobsWithNames
3885
- .filter(({ job }) => job.when === when)
3886
- .map(({ jobName, job }) => {
3887
- var _a;
3888
- // always wait for completion for preStop and postStop jobs
3889
- // since stop will delete the jobs afterwards, so they will fail
3890
- const waitForCompletion = ["preStop", "postStop"].includes(when)
3891
- ? true
3892
- : "waitForCompletion" in job
3893
- ? ((_a = job.waitForCompletion) !== null && _a !== void 0 ? _a : false)
3894
- : false;
3895
- return getJobRunScriptForJob(context, jobName, waitForCompletion);
3896
- });
3897
- };
3898
- exports.getJobRunScripts = getJobRunScripts;
3899
- const getJobCreateScripts = (context) => getCloudRunJobsWithNames(context).map(({ job, jobName }, jobIndex) => {
3871
+ const getJobCreateScripts = (context) => (0, exports.getCloudRunJobsWithNames)(context).map(({ job, fullJobName }, jobIndex) => {
3900
3872
  var _a, _b, _c, _d;
3901
3873
  const commandArray = Array.isArray(job.command)
3902
3874
  ? job.command
@@ -3904,6 +3876,7 @@ const getJobCreateScripts = (context) => getCloudRunJobsWithNames(context).map((
3904
3876
  const { image: commonImage, project, region, ...deployArgs } = (0, common_1.getCommonDeployArgs)(context);
3905
3877
  const commonDeployArgsString = (0, createArgsString_1.createArgsString)({
3906
3878
  command: `"${commandArray.join(",")}"`,
3879
+ args: (0, onDeploy_1.getCloudRunJobArgsArg)(job.args),
3907
3880
  labels: `"${(0, common_1.makeLabelString)((0, getLabels_1.getLabels)(context))},cloud-run-job-name=$current_job_name"`,
3908
3881
  image: `"${(_a = job.image) !== null && _a !== void 0 ? _a : commonImage}"`,
3909
3882
  project,
@@ -3925,7 +3898,7 @@ const getJobCreateScripts = (context) => getCloudRunJobsWithNames(context).map((
3925
3898
  jobIndex === 0
3926
3899
  ? `exist_job_names="$(\n ${(0, common_1.gcloudRunCmd)()} jobs list --filter='metadata.name ~ ${context.env}.*${context.name}' --format='value(name)' --limit=999 --project='${project}' --region='${region}'\n)"`
3927
3900
  : null,
3928
- `current_job_name="${jobName}"`,
3901
+ `current_job_name="${fullJobName}"`,
3929
3902
  'if grep "$current_job_name" <<<"$exist_job_names" >/dev/null; then',
3930
3903
  ` ${(0, common_1.gcloudRunCmd)()} jobs update "$current_job_name" ${commonDeployArgsString}`,
3931
3904
  "else",
@@ -3936,75 +3909,20 @@ const getJobCreateScripts = (context) => getCloudRunJobsWithNames(context).map((
3936
3909
  .join("\n");
3937
3910
  });
3938
3911
  exports.getJobCreateScripts = getJobCreateScripts;
3939
- const getCreateScheduleScripts = (context) => {
3940
- const schedules = getSchedules(context);
3941
- const { region: location, projectId: project } = (0, common_1.getCloudRunDeployConfig)(context);
3942
- return schedules.map((scheduler, jobIndex) => {
3943
- var _a;
3944
- const uri = getSchedulerUrl(scheduler, context);
3945
- const argsString = (0, createArgsString_1.createArgsString)({
3946
- project,
3947
- location,
3948
- uri: `"$current_job_uri"`,
3949
- "http-method": "POST",
3950
- "oauth-service-account-email": `"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com"`,
3951
- schedule: `"${scheduler.schedule}"`,
3952
- "max-retry-attempts": (_a = scheduler.maxRetryAttempts) !== null && _a !== void 0 ? _a : 0,
3953
- });
3954
- return [
3955
- jobIndex === 0
3956
- ? `exist_scheduler_names="$(\n ${(0, common_1.gcloudSchedulerCmd)()} jobs list --filter='httpTarget.uri ~ ${context.env}.*${context.name}' --format='value(name)' --limit=999 --location='${location}' --project='${project}'\n)"`
3957
- : null,
3958
- `current_job_uri="${uri}"`,
3959
- `current_scheduler_name="${scheduler.name}"`,
3960
- `if grep "$current_scheduler_name" <<<"$exist_scheduler_names" >/dev/null; then`,
3961
- ` ${(0, common_1.gcloudSchedulerCmd)()} jobs update http "$current_scheduler_name" ${argsString}`,
3962
- `else`,
3963
- ` ${(0, common_1.gcloudSchedulerCmd)()} jobs create http "$current_scheduler_name" ${argsString}`,
3964
- `fi`,
3965
- ]
3966
- .filter(utils_1.notNil)
3967
- .join("\n");
3968
- });
3969
- };
3970
- exports.getCreateScheduleScripts = getCreateScheduleScripts;
3971
- const getSchedulerUrl = (scheduler, context) => {
3972
- if (scheduler.type === "cloudRunJob") {
3973
- const { region: location, projectId: project } = (0, common_1.getCloudRunDeployConfig)(context);
3974
- const uriBase = `https://${location}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${project}/jobs`;
3975
- return `${uriBase}/${scheduler.jobName}:run`;
3976
- }
3977
- throw new Error(`Unknown scheduler type: ${scheduler.type}`);
3978
- };
3979
- const getSchedules = (context) => {
3980
- const jobsWithNames = getCloudRunJobsWithNames(context);
3981
- return jobsWithNames
3982
- .filter((entry) => entry.job.when === "schedule")
3983
- .map(({ job: { maxRetryAttempts, schedule }, jobName }) => {
3984
- const schedulerName = jobName.concat("-scheduler");
3985
- return {
3986
- name: schedulerName,
3987
- maxRetryAttempts,
3988
- schedule,
3989
- type: "cloudRunJob",
3990
- jobName,
3991
- };
3992
- });
3993
- };
3994
3912
  const getCloudRunJobsWithNames = (context) => {
3995
3913
  var _a;
3996
3914
  const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
3997
- const getFullJobName = (name) => (0, jobName_1.getCloudRunJobName)(context.environment.fullName, name);
3998
3915
  const jobsWithNames = Object.entries((_a = deployConfig.jobs) !== null && _a !== void 0 ? _a : {})
3999
3916
  // filter out disabled jobs
4000
3917
  .filter((entry) => Boolean(entry[1]))
4001
- .map(([jobKey, job]) => ({
4002
- jobName: getFullJobName(jobKey),
3918
+ .map(([jobName, job]) => ({
3919
+ fullJobName: (0, jobName_1.getFullJobName)(context, jobName),
4003
3920
  job,
4004
- jobKey,
3921
+ jobName,
4005
3922
  }));
4006
3923
  return jobsWithNames;
4007
3924
  };
3925
+ exports.getCloudRunJobsWithNames = getCloudRunJobsWithNames;
4008
3926
  //# sourceMappingURL=cloudRunJobs.js.map
4009
3927
 
4010
3928
  /***/ }),
@@ -4156,6 +4074,241 @@ exports.ENV_VARS_FILENAME = "____envvars.yaml";
4156
4074
 
4157
4075
  /***/ }),
4158
4076
 
4077
+ /***/ 2358:
4078
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4079
+
4080
+ "use strict";
4081
+
4082
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
4083
+ exports.getCloudRunJobArgsArg = exports.getOnDeployExecuteScript = void 0;
4084
+ const createArgsString_1 = __nccwpck_require__(9598);
4085
+ const jobName_1 = __nccwpck_require__(9626);
4086
+ const cloudRunJobs_1 = __nccwpck_require__(1224);
4087
+ const common_1 = __nccwpck_require__(3325);
4088
+ const getOnDeployExecuteScript = (context, when) => {
4089
+ const executes = getExecutes(context);
4090
+ return executes
4091
+ .filter(({ config }) => config.when === when)
4092
+ .map((execute) => {
4093
+ return getJobRunScriptForExecute(context, execute);
4094
+ });
4095
+ };
4096
+ exports.getOnDeployExecuteScript = getOnDeployExecuteScript;
4097
+ const getExecutes = (context) => {
4098
+ var _a;
4099
+ const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
4100
+ return [
4101
+ ...getLegacyExecutes(context),
4102
+ ...Object.entries((_a = deployConfig.execute) !== null && _a !== void 0 ? _a : {}).flatMap(([key, value]) => {
4103
+ if (!value || (value.when !== "schedule" && value.type !== "job")) {
4104
+ return [];
4105
+ }
4106
+ return [
4107
+ {
4108
+ jobName: key,
4109
+ config: value,
4110
+ },
4111
+ ];
4112
+ }),
4113
+ ];
4114
+ };
4115
+ const getLegacyExecutes = (context) => {
4116
+ const jobsWithNames = (0, cloudRunJobs_1.getCloudRunJobsWithNames)(context);
4117
+ return jobsWithNames.flatMap(({ jobName, job }) => {
4118
+ if (!job.when ||
4119
+ !["preDeploy", "postDeploy", "preStop", "postStop"].includes(job.when)) {
4120
+ return [];
4121
+ }
4122
+ return [
4123
+ {
4124
+ jobName,
4125
+ config: {
4126
+ job: jobName,
4127
+ type: "job",
4128
+ when: job.when,
4129
+ ...(job.when === "preDeploy" || job.when === "postDeploy"
4130
+ ? {
4131
+ waitForCompletion: job.waitForCompletion,
4132
+ }
4133
+ : {}),
4134
+ },
4135
+ },
4136
+ ];
4137
+ });
4138
+ };
4139
+ const getJobRunScriptForExecute = (context, { jobName, config }) => {
4140
+ var _a;
4141
+ const commonArgs = (0, common_1.getCommonCloudRunArgs)(context);
4142
+ // always wait for completion for preStop and postStop jobs
4143
+ // since stop will delete the jobs afterwards, so they will fail
4144
+ const waitForCompletion = ["preStop", "postStop"].includes(config.when)
4145
+ ? true // always
4146
+ : "waitForCompletion" in config
4147
+ ? ((_a = config.waitForCompletion) !== null && _a !== void 0 ? _a : false) // depends on config
4148
+ : false;
4149
+ const argString = (0, createArgsString_1.createArgsString)({
4150
+ ...commonArgs,
4151
+ wait: waitForCompletion === true ? true : undefined,
4152
+ args: (0, exports.getCloudRunJobArgsArg)(config.args),
4153
+ });
4154
+ const fullJobName = (0, jobName_1.getFullJobName)(context, jobName);
4155
+ return `${(0, common_1.gcloudRunCmd)()} jobs execute ${fullJobName.toString()} ${argString}`;
4156
+ };
4157
+ const getCloudRunJobArgsArg = (args) => {
4158
+ return args !== undefined
4159
+ ? args.length > 0
4160
+ ? args === null || args === void 0 ? void 0 : args.map((arg) => `"${arg}"`).join(",")
4161
+ : ""
4162
+ : undefined;
4163
+ };
4164
+ exports.getCloudRunJobArgsArg = getCloudRunJobArgsArg;
4165
+ //# sourceMappingURL=onDeploy.js.map
4166
+
4167
+ /***/ }),
4168
+
4169
+ /***/ 3697:
4170
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4171
+
4172
+ "use strict";
4173
+
4174
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
4175
+ exports.getCreateScheduleScript = exports.getDeleteSchedulesScript = void 0;
4176
+ const bash_1 = __nccwpck_require__(2990);
4177
+ const utils_1 = __nccwpck_require__(2497);
4178
+ const cloudRunExecutionUrl_1 = __nccwpck_require__(4856);
4179
+ const createArgsString_1 = __nccwpck_require__(9598);
4180
+ const jobName_1 = __nccwpck_require__(9626);
4181
+ const cloudRunJobs_1 = __nccwpck_require__(1224);
4182
+ const common_1 = __nccwpck_require__(3325);
4183
+ const getDeleteSchedulesScript = (context) => {
4184
+ const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
4185
+ const schedules = getSchedules(context);
4186
+ const argsString = (0, createArgsString_1.createArgsString)({
4187
+ project: deployConfig.projectId,
4188
+ location: deployConfig.region,
4189
+ });
4190
+ return schedules
4191
+ .map(({ fullName }) => {
4192
+ return [`${(0, common_1.gcloudSchedulerCmd)()} jobs delete ${fullName} ${argsString}`];
4193
+ })
4194
+ .flat();
4195
+ };
4196
+ exports.getDeleteSchedulesScript = getDeleteSchedulesScript;
4197
+ const getCreateScheduleScript = (context) => {
4198
+ const schedules = getSchedules(context);
4199
+ const { region: location, projectId: project } = (0, common_1.getCloudRunDeployConfig)(context);
4200
+ return schedules.map(({ fullName, config }, jobIndex) => {
4201
+ var _a;
4202
+ const { uri, ...args } = getSchedulerArgs(config, context);
4203
+ const argsString = (0, createArgsString_1.createArgsString)({
4204
+ project,
4205
+ location,
4206
+ uri: `"$current_job_uri"`,
4207
+ ...args,
4208
+ schedule: `"${config.schedule}"`,
4209
+ "max-retry-attempts": (_a = config.maxRetryAttempts) !== null && _a !== void 0 ? _a : 0,
4210
+ });
4211
+ return [
4212
+ jobIndex === 0
4213
+ ? `exist_scheduler_names="$(\n ${(0, common_1.gcloudSchedulerCmd)()} jobs list --filter='httpTarget.uri ~ ${context.env}.*${context.name}' --format='value(name)' --limit=999 --location='${location}' --project='${project}'\n)"`
4214
+ : null,
4215
+ `current_job_uri="${uri}"`,
4216
+ `current_scheduler_name="${fullName}"`,
4217
+ `if grep "$current_scheduler_name" <<<"$exist_scheduler_names" >/dev/null; then`,
4218
+ ` ${(0, common_1.gcloudSchedulerCmd)()} jobs update http "$current_scheduler_name" ${argsString}`,
4219
+ `else`,
4220
+ ` ${(0, common_1.gcloudSchedulerCmd)()} jobs create http "$current_scheduler_name" ${argsString}`,
4221
+ `fi`,
4222
+ ]
4223
+ .filter(utils_1.notNil)
4224
+ .join("\n");
4225
+ });
4226
+ };
4227
+ exports.getCreateScheduleScript = getCreateScheduleScript;
4228
+ const getSchedulerArgs = (scheduler, context) => {
4229
+ var _a;
4230
+ if (scheduler.type === "job") {
4231
+ const { projectId, region } = (0, common_1.getCloudRunDeployConfig)(context);
4232
+ const body = scheduler.args !== undefined
4233
+ ? {
4234
+ overrides: {
4235
+ containerOverrides: [
4236
+ ((_a = scheduler.args) === null || _a === void 0 ? void 0 : _a.length) > 0
4237
+ ? {
4238
+ args: scheduler.args,
4239
+ }
4240
+ : {
4241
+ args: [],
4242
+ clearArgs: true, // not sure why this is neeeded, but it is
4243
+ },
4244
+ ],
4245
+ },
4246
+ }
4247
+ : null;
4248
+ return {
4249
+ uri: (0, cloudRunExecutionUrl_1.getCloudRunJobExecuteUrl)(scheduler.job, {
4250
+ appFullName: context.environment.fullName,
4251
+ projectId,
4252
+ region,
4253
+ }),
4254
+ "message-body": body
4255
+ ? '"' + (0, bash_1.bashEscape)(JSON.stringify(body)) + '"'
4256
+ : undefined,
4257
+ "http-method": "POST",
4258
+ "oauth-service-account-email": `"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com"`,
4259
+ };
4260
+ }
4261
+ if (scheduler.type === "http") {
4262
+ return {
4263
+ uri: scheduler.url,
4264
+ "message-body": scheduler.body,
4265
+ "http-method": scheduler.method,
4266
+ "oidc-service-account-email": `"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com"`,
4267
+ };
4268
+ }
4269
+ throw new Error(`Unknown scheduler type: ${scheduler.type}`);
4270
+ };
4271
+ const getSchedules = (context) => {
4272
+ const legacyScheduleJobs = getLegacyJobSchedules(context);
4273
+ const schedules = getScheduledExecutes(context);
4274
+ return Object.entries({ ...legacyScheduleJobs, ...schedules }).map(([name, config]) => ({
4275
+ name,
4276
+ fullName: (0, jobName_1.getFullSchedulerName)(context, name),
4277
+ config,
4278
+ }));
4279
+ };
4280
+ const getLegacyJobSchedules = (context) => {
4281
+ const jobsWithNames = (0, cloudRunJobs_1.getCloudRunJobsWithNames)(context);
4282
+ return Object.fromEntries(jobsWithNames
4283
+ .filter((entry) => entry.job.when === "schedule")
4284
+ .map(({ job: { maxRetryAttempts, schedule }, jobName }) => {
4285
+ const schedulerName = jobName.concat("-scheduler");
4286
+ return [
4287
+ schedulerName,
4288
+ {
4289
+ type: "job",
4290
+ job: jobName,
4291
+ maxRetryAttempts,
4292
+ schedule,
4293
+ when: "schedule",
4294
+ },
4295
+ ];
4296
+ }));
4297
+ };
4298
+ const getScheduledExecutes = (context) => {
4299
+ var _a;
4300
+ const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
4301
+ return Object.fromEntries(Object.entries((_a = deployConfig.execute) !== null && _a !== void 0 ? _a : {}).flatMap(([key, value]) => {
4302
+ if (!value || value.when !== "schedule") {
4303
+ return [];
4304
+ }
4305
+ return [[key, value]];
4306
+ }));
4307
+ };
4308
+ //# sourceMappingURL=schedules.js.map
4309
+
4310
+ /***/ }),
4311
+
4159
4312
  /***/ 3695:
4160
4313
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4161
4314
 
@@ -4172,9 +4325,11 @@ const cleanup_1 = __nccwpck_require__(7888);
4172
4325
  const database_1 = __nccwpck_require__(8206);
4173
4326
  const gcloudServiceAccountLoginCommands_1 = __nccwpck_require__(6320);
4174
4327
  const cloudRunJobs_1 = __nccwpck_require__(1224);
4328
+ const onDeploy_1 = __nccwpck_require__(2358);
4175
4329
  const cloudRunServices_1 = __nccwpck_require__(7334);
4176
4330
  const common_1 = __nccwpck_require__(3325);
4177
4331
  const constants_1 = __nccwpck_require__(8865);
4332
+ const schedules_1 = __nccwpck_require__(3697);
4178
4333
  function getCloudRunDeployScripts(context) {
4179
4334
  var _a;
4180
4335
  const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
@@ -4189,14 +4344,14 @@ function getCloudRunDeployScripts(context) {
4189
4344
  ...(deployConfig.cloudSql
4190
4345
  ? (0, database_1.getDatabaseCreateScript)(context, deployConfig) // we create the db, so that we can also delete it afterwards
4191
4346
  : []),
4192
- ...(0, cloudRunJobs_1.getCreateScheduleScripts)(context),
4347
+ ...(0, schedules_1.getCreateScheduleScript)(context),
4193
4348
  ...(0, cloudRunJobs_1.getJobCreateScripts)(context),
4194
- ...(0, cloudRunJobs_1.getJobRunScripts)(context, "preDeploy"),
4349
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "preDeploy"),
4195
4350
  ...(deployConfig.service !== false
4196
4351
  ? [(0, cloudRunServices_1.getServiceDeployScript)(context, deployConfig.service)]
4197
4352
  : []),
4198
4353
  ...Object.entries((_a = deployConfig.additionalServices) !== null && _a !== void 0 ? _a : {}).map(([name, service]) => (0, cloudRunServices_1.getServiceDeployScript)(context, service, "-" + name)),
4199
- ...(0, cloudRunJobs_1.getJobRunScripts)(context, "postDeploy"),
4354
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "postDeploy"),
4200
4355
  ]),
4201
4356
  ...(0, gitlab_1.collapseableSection)("cleanup", "Cleanup")((0, cleanup_1.getRemoveOldRevisionsAndImagesCommand)(context, "postDeploy")),
4202
4357
  ...(0, sbom_1.getDependencyTrackUploadScript)(context),
@@ -4219,6 +4374,8 @@ const cleanup_1 = __nccwpck_require__(7888);
4219
4374
  const database_1 = __nccwpck_require__(8206);
4220
4375
  const gcloudServiceAccountLoginCommands_1 = __nccwpck_require__(6320);
4221
4376
  const cloudRunJobs_1 = __nccwpck_require__(1224);
4377
+ const onDeploy_1 = __nccwpck_require__(2358);
4378
+ const schedules_1 = __nccwpck_require__(3697);
4222
4379
  const cloudRunServices_1 = __nccwpck_require__(7334);
4223
4380
  const common_1 = __nccwpck_require__(3325);
4224
4381
  function getCloudRunStopScripts(context) {
@@ -4226,11 +4383,11 @@ function getCloudRunStopScripts(context) {
4226
4383
  const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
4227
4384
  return [
4228
4385
  ...(0, gcloudServiceAccountLoginCommands_1.gcloudServiceAccountLoginCommands)(context),
4229
- ...(0, cloudRunJobs_1.getJobRunScripts)(context, "preStop"),
4386
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "preStop"),
4230
4387
  ...(deployConfig.service !== false ? (0, cloudRunServices_1.getServiceDeleteScript)(context) : []),
4231
4388
  ...Object.entries((_a = deployConfig.additionalServices) !== null && _a !== void 0 ? _a : {}).flatMap(([name]) => (0, cloudRunServices_1.getServiceDeleteScript)(context, name)),
4232
- ...(0, cloudRunJobs_1.getJobRunScripts)(context, "postStop"),
4233
- ...(0, cloudRunJobs_1.getDeleteSchedulesScripts)(context),
4389
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "postStop"),
4390
+ ...(0, schedules_1.getDeleteSchedulesScript)(context),
4234
4391
  ...(0, cloudRunJobs_1.getDeleteJobsScripts)(context),
4235
4392
  ...(deployConfig.cloudSql && deployConfig.cloudSql.deleteDatabaseOnStop
4236
4393
  ? (0, database_1.getDatabaseDeleteScript)(context, deployConfig)
@@ -4335,8 +4492,8 @@ const context_1 = __nccwpck_require__(5875);
4335
4492
  const gitlab_1 = __nccwpck_require__(8490);
4336
4493
  const utils_1 = __nccwpck_require__(2089);
4337
4494
  const createJobs_1 = __nccwpck_require__(4069);
4495
+ const cloudRunExecutionUrl_1 = __nccwpck_require__(4856);
4338
4496
  const database_1 = __nccwpck_require__(8206);
4339
- const jobName_1 = __nccwpck_require__(9626);
4340
4497
  exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
4341
4498
  // FIXME: rename to internalHostSuffix, but this means that project-setup needs to be rerun, so its kindof a breaking change
4342
4499
  exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = "GCLOUD_RUN_canonicalHostSuffix";
@@ -4392,7 +4549,11 @@ exports.GCLOUD_RUN_DEPLOY_TYPE = {
4392
4549
  const jobTriggers = deployConfigRaw && deployConfigRaw.jobs
4393
4550
  ? Object.fromEntries(Object.entries(deployConfigRaw.jobs).map(([name, job]) => [
4394
4551
  "CLOUD_RUN_JOB_TRIGGER_URL_" + (0, gitlab_1.sanitizeForBashVariable)(name),
4395
- `https://${deployConfigRaw.region}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${deployConfigRaw.projectId}/jobs/${(0, jobName_1.getCloudRunJobName)(fullName, name)}:run`,
4552
+ (0, cloudRunExecutionUrl_1.getCloudRunJobExecuteUrl)(name, {
4553
+ appFullName: fullName,
4554
+ projectId: deployConfigRaw.projectId,
4555
+ region: deployConfigRaw.region,
4556
+ }),
4396
4557
  ]))
4397
4558
  : {};
4398
4559
  return {
@@ -4412,6 +4573,24 @@ exports.GCLOUD_RUN_DEPLOY_TYPE = {
4412
4573
 
4413
4574
  /***/ }),
4414
4575
 
4576
+ /***/ 4856:
4577
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4578
+
4579
+ "use strict";
4580
+
4581
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
4582
+ exports.getCloudRunJobExecuteUrl = void 0;
4583
+ const jobName_1 = __nccwpck_require__(9626);
4584
+ function getCloudRunJobExecuteUrl(jobName, { region, projectId, appFullName, }) {
4585
+ const uriBase = `https://${region}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${projectId}/jobs`;
4586
+ const fullJobName = (0, jobName_1.getCloudRunJobName)(appFullName, jobName);
4587
+ return `${uriBase}/${fullJobName}:run`;
4588
+ }
4589
+ exports.getCloudRunJobExecuteUrl = getCloudRunJobExecuteUrl;
4590
+ //# sourceMappingURL=cloudRunExecutionUrl.js.map
4591
+
4592
+ /***/ }),
4593
+
4415
4594
  /***/ 9598:
4416
4595
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4417
4596
 
@@ -4546,9 +4725,15 @@ exports.getServiceName = getServiceName;
4546
4725
  "use strict";
4547
4726
 
4548
4727
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4549
- exports.getCloudRunJobName = void 0;
4728
+ exports.getFullSchedulerName = exports.getCloudRunSchedulerName = exports.getFullJobName = exports.getCloudRunJobName = void 0;
4550
4729
  const getCloudRunJobName = (fullAppName, jobName) => fullAppName.toLowerCase().concat("-" + jobName.toLowerCase());
4551
4730
  exports.getCloudRunJobName = getCloudRunJobName;
4731
+ const getFullJobName = (context, name) => (0, exports.getCloudRunJobName)(context.environment.fullName, name);
4732
+ exports.getFullJobName = getFullJobName;
4733
+ const getCloudRunSchedulerName = (fullAppName, schedulerName) => fullAppName.toLowerCase().concat("-" + schedulerName.toLowerCase());
4734
+ exports.getCloudRunSchedulerName = getCloudRunSchedulerName;
4735
+ const getFullSchedulerName = (context, name) => (0, exports.getCloudRunSchedulerName)(context.environment.fullName, name);
4736
+ exports.getFullSchedulerName = getFullSchedulerName;
4552
4737
  //# sourceMappingURL=jobName.js.map
4553
4738
 
4554
4739
  /***/ }),