@catladder/cli 0.0.0-fix-config-move-not-working-again-bf012644 → 0.0.0-fix-handle-missing-cloud-sql-proxy-command-error-and-show-nice-17045900

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 (49) hide show
  1. package/dist/bundles/catenv/index.js +327 -124
  2. package/dist/bundles/cli/index.js +470 -181
  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/cli/src/apps/cli/commands/project/commandCloudSqlProxy.js +84 -51
  9. package/dist/cli/src/apps/cli/commands/project/commandCloudSqlProxy.js.map +1 -1
  10. package/dist/cli/src/utils/log.d.ts +65 -1
  11. package/dist/cli/src/utils/log.js +66 -8
  12. package/dist/cli/src/utils/log.js.map +1 -1
  13. package/dist/pipeline/src/bash/bashEscape.d.ts +4 -1
  14. package/dist/pipeline/src/bash/bashEscape.js +4 -2
  15. package/dist/pipeline/src/bash/bashEscape.js.map +1 -1
  16. package/dist/pipeline/src/context/getEnvConfig.js +14 -2
  17. package/dist/pipeline/src/context/getEnvConfig.js.map +1 -1
  18. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.d.ts +5 -3
  19. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js +18 -107
  20. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js.map +1 -1
  21. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.d.ts +4 -0
  22. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.js +85 -0
  23. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.js.map +1 -0
  24. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/schedules.d.ts +3 -0
  25. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/schedules.js +136 -0
  26. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/schedules.js.map +1 -0
  27. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +5 -3
  28. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js.map +1 -1
  29. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.js +5 -3
  30. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.js.map +1 -1
  31. package/dist/pipeline/src/deploy/cloudRun/index.js +6 -2
  32. package/dist/pipeline/src/deploy/cloudRun/index.js.map +1 -1
  33. package/dist/pipeline/src/deploy/cloudRun/utils/cloudRunExecutionUrl.d.ts +6 -0
  34. package/dist/pipeline/src/deploy/cloudRun/utils/cloudRunExecutionUrl.js +11 -0
  35. package/dist/pipeline/src/deploy/cloudRun/utils/cloudRunExecutionUrl.js.map +1 -0
  36. package/dist/pipeline/src/deploy/cloudRun/utils/jobName.d.ts +5 -1
  37. package/dist/pipeline/src/deploy/cloudRun/utils/jobName.js +7 -1
  38. package/dist/pipeline/src/deploy/cloudRun/utils/jobName.js.map +1 -1
  39. package/dist/pipeline/src/deploy/types/googleCloudRun.d.ts +99 -1
  40. package/dist/pipeline/src/deploy/types/index.d.ts +1 -0
  41. package/dist/pipeline/src/deploy/types/index.js +7 -1
  42. package/dist/pipeline/src/deploy/types/index.js.map +1 -1
  43. package/dist/pipeline/src/types/config.d.ts +11 -6
  44. package/dist/tsconfig.tsbuildinfo +1 -1
  45. package/package.json +1 -1
  46. package/src/apps/catenv/printVariables.ts +4 -1
  47. package/src/apps/catenv/utils.ts +12 -3
  48. package/src/apps/cli/commands/project/commandCloudSqlProxy.ts +130 -66
  49. package/src/utils/log.ts +104 -8
@@ -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(`"`)
@@ -2995,7 +3002,7 @@ exports.getBuildInfoVariables = getBuildInfoVariables;
2995
3002
 
2996
3003
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2997
3004
  exports.getEnvConfig = void 0;
2998
- const utils_1 = __nccwpck_require__(2497);
3005
+ const lodash_1 = __nccwpck_require__(3255);
2999
3006
  const getEnvConfig = (config, componentName, env) => {
3000
3007
  var _a, _b;
3001
3008
  const defaultConfig = config.components[componentName];
@@ -3007,7 +3014,19 @@ const getEnvConfig = (config, componentName, env) => {
3007
3014
  // env is disabled, still return the default config
3008
3015
  return defaultConfig;
3009
3016
  }
3010
- return (0, utils_1.mergeWithMergingArrays)(defaultConfig, envCustomizations);
3017
+ /**
3018
+ * env config is merged with default. Arrays are not merged.
3019
+ * you can customize this by providing a function that takes the default value as argument
3020
+ */
3021
+ return (0, lodash_1.mergeWith)({}, defaultConfig, envCustomizations, (defaultValue, customValue) => {
3022
+ // check if custom value is a function (and default is not),
3023
+ // we currently don't have config options that are functions, but we might in the future
3024
+ if (typeof customValue === "function" &&
3025
+ typeof defaultValue !== "function") {
3026
+ return customValue(defaultValue);
3027
+ }
3028
+ return undefined;
3029
+ });
3011
3030
  };
3012
3031
  exports.getEnvConfig = getEnvConfig;
3013
3032
  //# sourceMappingURL=getEnvConfig.js.map
@@ -3841,69 +3860,35 @@ exports.getDeleteUnusedRevisionsCommands = getDeleteUnusedRevisionsCommands;
3841
3860
  "use strict";
3842
3861
 
3843
3862
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3844
- exports.getCreateScheduleScripts = exports.getJobCreateScripts = exports.getJobRunScripts = exports.getDeleteJobsScripts = exports.getDeleteSchedulesScripts = void 0;
3863
+ exports.getCloudRunJobsWithNames = exports.getJobCreateScripts = exports.getDeleteJobsScripts = void 0;
3864
+ const getLabels_1 = __nccwpck_require__(920);
3865
+ const utils_1 = __nccwpck_require__(2497);
3845
3866
  const createArgsString_1 = __nccwpck_require__(9598);
3846
3867
  const jobName_1 = __nccwpck_require__(9626);
3847
3868
  const common_1 = __nccwpck_require__(3325);
3848
- const getLabels_1 = __nccwpck_require__(920);
3849
- const volumes_1 = __nccwpck_require__(847);
3850
3869
  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;
3870
+ const volumes_1 = __nccwpck_require__(847);
3871
+ const onDeploy_1 = __nccwpck_require__(2358);
3871
3872
  const getDeleteJobsScripts = (context) => {
3872
3873
  const commonArgs = (0, common_1.getCommonCloudRunArgs)(context);
3873
3874
  const commonArgsString = (0, createArgsString_1.createArgsString)(commonArgs);
3874
- const jobsWithNames = getCloudRunJobsWithNames(context);
3875
- return jobsWithNames.flatMap(({ jobName }) => [
3875
+ const jobsWithNames = (0, exports.getCloudRunJobsWithNames)(context);
3876
+ return jobsWithNames.flatMap(({ fullJobName }) => [
3876
3877
  // 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}`,
3878
+ `${(0, common_1.gcloudRunCmd)()} jobs executions list ${commonArgsString} --job ${fullJobName} --format="value(name)" | xargs -I {} ${(0, common_1.gcloudRunCmd)()} jobs executions delete {} --quiet ${commonArgsString}`,
3879
+ `${(0, common_1.gcloudRunCmd)()} jobs delete ${fullJobName} ${commonArgsString}`,
3879
3880
  ]);
3880
3881
  };
3881
3882
  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) => {
3900
- var _a, _b, _c, _d;
3883
+ const getJobCreateScripts = (context) => (0, exports.getCloudRunJobsWithNames)(context).map(({ job, fullJobName }, jobIndex) => {
3884
+ var _a, _b, _c, _d, _e;
3901
3885
  const commandArray = Array.isArray(job.command)
3902
3886
  ? job.command
3903
3887
  : job.command.split(" ");
3904
3888
  const { image: commonImage, project, region, ...deployArgs } = (0, common_1.getCommonDeployArgs)(context);
3905
3889
  const commonDeployArgsString = (0, createArgsString_1.createArgsString)({
3906
3890
  command: `"${commandArray.join(",")}"`,
3891
+ args: (0, onDeploy_1.getCloudRunJobArgsArg)(job.args),
3907
3892
  labels: `"${(0, common_1.makeLabelString)((0, getLabels_1.getLabels)(context))},cloud-run-job-name=$current_job_name"`,
3908
3893
  image: `"${(_a = job.image) !== null && _a !== void 0 ? _a : commonImage}"`,
3909
3894
  project,
@@ -3913,7 +3898,7 @@ const getJobCreateScripts = (context) => getCloudRunJobsWithNames(context).map((
3913
3898
  parallelism: (_c = job.parallelism) !== null && _c !== void 0 ? _c : 1,
3914
3899
  "task-timeout": (_d = job.timeout) !== null && _d !== void 0 ? _d : "10m",
3915
3900
  "env-vars-file": constants_1.ENV_VARS_FILENAME,
3916
- "max-retries": 0,
3901
+ "max-retries": (_e = job.maxRetries) !== null && _e !== void 0 ? _e : 0,
3917
3902
  ...deployArgs,
3918
3903
  // network
3919
3904
  "vpc-connector": job === null || job === void 0 ? void 0 : job.vpcConnector,
@@ -3925,7 +3910,7 @@ const getJobCreateScripts = (context) => getCloudRunJobsWithNames(context).map((
3925
3910
  jobIndex === 0
3926
3911
  ? `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
3912
  : null,
3928
- `current_job_name="${jobName}"`,
3913
+ `current_job_name="${fullJobName}"`,
3929
3914
  'if grep "$current_job_name" <<<"$exist_job_names" >/dev/null; then',
3930
3915
  ` ${(0, common_1.gcloudRunCmd)()} jobs update "$current_job_name" ${commonDeployArgsString}`,
3931
3916
  "else",
@@ -3936,75 +3921,20 @@ const getJobCreateScripts = (context) => getCloudRunJobsWithNames(context).map((
3936
3921
  .join("\n");
3937
3922
  });
3938
3923
  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
3924
  const getCloudRunJobsWithNames = (context) => {
3995
3925
  var _a;
3996
3926
  const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
3997
- const getFullJobName = (name) => (0, jobName_1.getCloudRunJobName)(context.environment.fullName, name);
3998
3927
  const jobsWithNames = Object.entries((_a = deployConfig.jobs) !== null && _a !== void 0 ? _a : {})
3999
3928
  // filter out disabled jobs
4000
3929
  .filter((entry) => Boolean(entry[1]))
4001
- .map(([jobKey, job]) => ({
4002
- jobName: getFullJobName(jobKey),
3930
+ .map(([jobName, job]) => ({
3931
+ fullJobName: (0, jobName_1.getFullJobName)(context, jobName),
4003
3932
  job,
4004
- jobKey,
3933
+ jobName,
4005
3934
  }));
4006
3935
  return jobsWithNames;
4007
3936
  };
3937
+ exports.getCloudRunJobsWithNames = getCloudRunJobsWithNames;
4008
3938
  //# sourceMappingURL=cloudRunJobs.js.map
4009
3939
 
4010
3940
  /***/ }),
@@ -4156,6 +4086,241 @@ exports.ENV_VARS_FILENAME = "____envvars.yaml";
4156
4086
 
4157
4087
  /***/ }),
4158
4088
 
4089
+ /***/ 2358:
4090
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4091
+
4092
+ "use strict";
4093
+
4094
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
4095
+ exports.getCloudRunJobArgsArg = exports.getOnDeployExecuteScript = void 0;
4096
+ const createArgsString_1 = __nccwpck_require__(9598);
4097
+ const jobName_1 = __nccwpck_require__(9626);
4098
+ const cloudRunJobs_1 = __nccwpck_require__(1224);
4099
+ const common_1 = __nccwpck_require__(3325);
4100
+ const getOnDeployExecuteScript = (context, when) => {
4101
+ const executes = getExecutes(context);
4102
+ return executes
4103
+ .filter(({ config }) => config.when === when)
4104
+ .map((execute) => {
4105
+ return getJobRunScriptForExecute(context, execute);
4106
+ });
4107
+ };
4108
+ exports.getOnDeployExecuteScript = getOnDeployExecuteScript;
4109
+ const getExecutes = (context) => {
4110
+ var _a;
4111
+ const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
4112
+ return [
4113
+ ...getLegacyExecutes(context),
4114
+ ...Object.entries((_a = deployConfig.execute) !== null && _a !== void 0 ? _a : {}).flatMap(([key, value]) => {
4115
+ if (!value || (value.when !== "schedule" && value.type !== "job")) {
4116
+ return [];
4117
+ }
4118
+ return [
4119
+ {
4120
+ jobName: key,
4121
+ config: value,
4122
+ },
4123
+ ];
4124
+ }),
4125
+ ];
4126
+ };
4127
+ const getLegacyExecutes = (context) => {
4128
+ const jobsWithNames = (0, cloudRunJobs_1.getCloudRunJobsWithNames)(context);
4129
+ return jobsWithNames.flatMap(({ jobName, job }) => {
4130
+ if (!job.when ||
4131
+ !["preDeploy", "postDeploy", "preStop", "postStop"].includes(job.when)) {
4132
+ return [];
4133
+ }
4134
+ return [
4135
+ {
4136
+ jobName,
4137
+ config: {
4138
+ job: jobName,
4139
+ type: "job",
4140
+ when: job.when,
4141
+ ...(job.when === "preDeploy" || job.when === "postDeploy"
4142
+ ? {
4143
+ waitForCompletion: job.waitForCompletion,
4144
+ }
4145
+ : {}),
4146
+ },
4147
+ },
4148
+ ];
4149
+ });
4150
+ };
4151
+ const getJobRunScriptForExecute = (context, { jobName, config }) => {
4152
+ var _a;
4153
+ const commonArgs = (0, common_1.getCommonCloudRunArgs)(context);
4154
+ // always wait for completion for preStop and postStop jobs
4155
+ // since stop will delete the jobs afterwards, so they will fail
4156
+ const waitForCompletion = ["preStop", "postStop"].includes(config.when)
4157
+ ? true // always
4158
+ : "waitForCompletion" in config
4159
+ ? ((_a = config.waitForCompletion) !== null && _a !== void 0 ? _a : false) // depends on config
4160
+ : false;
4161
+ const argString = (0, createArgsString_1.createArgsString)({
4162
+ ...commonArgs,
4163
+ wait: waitForCompletion === true ? true : undefined,
4164
+ args: (0, exports.getCloudRunJobArgsArg)(config.args),
4165
+ });
4166
+ const fullJobName = (0, jobName_1.getFullJobName)(context, jobName);
4167
+ return `${(0, common_1.gcloudRunCmd)()} jobs execute ${fullJobName.toString()} ${argString}`;
4168
+ };
4169
+ const getCloudRunJobArgsArg = (args) => {
4170
+ return args !== undefined
4171
+ ? args.length > 0
4172
+ ? args === null || args === void 0 ? void 0 : args.map((arg) => `"${arg}"`).join(",")
4173
+ : ""
4174
+ : undefined;
4175
+ };
4176
+ exports.getCloudRunJobArgsArg = getCloudRunJobArgsArg;
4177
+ //# sourceMappingURL=onDeploy.js.map
4178
+
4179
+ /***/ }),
4180
+
4181
+ /***/ 3697:
4182
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4183
+
4184
+ "use strict";
4185
+
4186
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
4187
+ exports.getCreateScheduleScript = exports.getDeleteSchedulesScript = void 0;
4188
+ const bash_1 = __nccwpck_require__(2990);
4189
+ const utils_1 = __nccwpck_require__(2497);
4190
+ const cloudRunExecutionUrl_1 = __nccwpck_require__(4856);
4191
+ const createArgsString_1 = __nccwpck_require__(9598);
4192
+ const jobName_1 = __nccwpck_require__(9626);
4193
+ const cloudRunJobs_1 = __nccwpck_require__(1224);
4194
+ const common_1 = __nccwpck_require__(3325);
4195
+ const getDeleteSchedulesScript = (context) => {
4196
+ const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
4197
+ const schedules = getSchedules(context);
4198
+ const argsString = (0, createArgsString_1.createArgsString)({
4199
+ project: deployConfig.projectId,
4200
+ location: deployConfig.region,
4201
+ });
4202
+ return schedules
4203
+ .map(({ fullName }) => {
4204
+ return [`${(0, common_1.gcloudSchedulerCmd)()} jobs delete ${fullName} ${argsString}`];
4205
+ })
4206
+ .flat();
4207
+ };
4208
+ exports.getDeleteSchedulesScript = getDeleteSchedulesScript;
4209
+ const getCreateScheduleScript = (context) => {
4210
+ const schedules = getSchedules(context);
4211
+ const { region: location, projectId: project } = (0, common_1.getCloudRunDeployConfig)(context);
4212
+ return schedules.map(({ fullName, config }, jobIndex) => {
4213
+ var _a;
4214
+ const { uri, ...args } = getSchedulerArgs(config, context);
4215
+ const argsString = (0, createArgsString_1.createArgsString)({
4216
+ project,
4217
+ location,
4218
+ uri: `"$current_job_uri"`,
4219
+ ...args,
4220
+ schedule: `"${config.schedule}"`,
4221
+ "max-retry-attempts": (_a = config.maxRetryAttempts) !== null && _a !== void 0 ? _a : 0,
4222
+ });
4223
+ return [
4224
+ jobIndex === 0
4225
+ ? `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)"`
4226
+ : null,
4227
+ `current_job_uri="${uri}"`,
4228
+ `current_scheduler_name="${fullName}"`,
4229
+ `if grep "$current_scheduler_name" <<<"$exist_scheduler_names" >/dev/null; then`,
4230
+ ` ${(0, common_1.gcloudSchedulerCmd)()} jobs update http "$current_scheduler_name" ${argsString}`,
4231
+ `else`,
4232
+ ` ${(0, common_1.gcloudSchedulerCmd)()} jobs create http "$current_scheduler_name" ${argsString}`,
4233
+ `fi`,
4234
+ ]
4235
+ .filter(utils_1.notNil)
4236
+ .join("\n");
4237
+ });
4238
+ };
4239
+ exports.getCreateScheduleScript = getCreateScheduleScript;
4240
+ const getSchedulerArgs = (scheduler, context) => {
4241
+ var _a;
4242
+ if (scheduler.type === "job") {
4243
+ const { projectId, region } = (0, common_1.getCloudRunDeployConfig)(context);
4244
+ const body = scheduler.args !== undefined
4245
+ ? {
4246
+ overrides: {
4247
+ containerOverrides: [
4248
+ ((_a = scheduler.args) === null || _a === void 0 ? void 0 : _a.length) > 0
4249
+ ? {
4250
+ args: scheduler.args,
4251
+ }
4252
+ : {
4253
+ args: [],
4254
+ clearArgs: true, // not sure why this is neeeded, but it is
4255
+ },
4256
+ ],
4257
+ },
4258
+ }
4259
+ : null;
4260
+ return {
4261
+ uri: (0, cloudRunExecutionUrl_1.getCloudRunJobExecuteUrl)(scheduler.job, {
4262
+ appFullName: context.environment.fullName,
4263
+ projectId,
4264
+ region,
4265
+ }),
4266
+ "message-body": body
4267
+ ? '"' + (0, bash_1.bashEscape)(JSON.stringify(body)) + '"'
4268
+ : undefined,
4269
+ "http-method": "POST",
4270
+ "oauth-service-account-email": `"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com"`,
4271
+ };
4272
+ }
4273
+ if (scheduler.type === "http") {
4274
+ return {
4275
+ uri: scheduler.url,
4276
+ "message-body": scheduler.body,
4277
+ "http-method": scheduler.method,
4278
+ "oidc-service-account-email": `"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com"`,
4279
+ };
4280
+ }
4281
+ throw new Error(`Unknown scheduler type: ${scheduler.type}`);
4282
+ };
4283
+ const getSchedules = (context) => {
4284
+ const legacyScheduleJobs = getLegacyJobSchedules(context);
4285
+ const schedules = getScheduledExecutes(context);
4286
+ return Object.entries({ ...legacyScheduleJobs, ...schedules }).map(([name, config]) => ({
4287
+ name,
4288
+ fullName: (0, jobName_1.getFullSchedulerName)(context, name),
4289
+ config,
4290
+ }));
4291
+ };
4292
+ const getLegacyJobSchedules = (context) => {
4293
+ const jobsWithNames = (0, cloudRunJobs_1.getCloudRunJobsWithNames)(context);
4294
+ return Object.fromEntries(jobsWithNames
4295
+ .filter((entry) => entry.job.when === "schedule")
4296
+ .map(({ job: { maxRetryAttempts, schedule }, jobName }) => {
4297
+ const schedulerName = jobName.concat("-scheduler");
4298
+ return [
4299
+ schedulerName,
4300
+ {
4301
+ type: "job",
4302
+ job: jobName,
4303
+ maxRetryAttempts,
4304
+ schedule,
4305
+ when: "schedule",
4306
+ },
4307
+ ];
4308
+ }));
4309
+ };
4310
+ const getScheduledExecutes = (context) => {
4311
+ var _a;
4312
+ const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
4313
+ return Object.fromEntries(Object.entries((_a = deployConfig.execute) !== null && _a !== void 0 ? _a : {}).flatMap(([key, value]) => {
4314
+ if (!value || value.when !== "schedule") {
4315
+ return [];
4316
+ }
4317
+ return [[key, value]];
4318
+ }));
4319
+ };
4320
+ //# sourceMappingURL=schedules.js.map
4321
+
4322
+ /***/ }),
4323
+
4159
4324
  /***/ 3695:
4160
4325
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4161
4326
 
@@ -4172,9 +4337,11 @@ const cleanup_1 = __nccwpck_require__(7888);
4172
4337
  const database_1 = __nccwpck_require__(8206);
4173
4338
  const gcloudServiceAccountLoginCommands_1 = __nccwpck_require__(6320);
4174
4339
  const cloudRunJobs_1 = __nccwpck_require__(1224);
4340
+ const onDeploy_1 = __nccwpck_require__(2358);
4175
4341
  const cloudRunServices_1 = __nccwpck_require__(7334);
4176
4342
  const common_1 = __nccwpck_require__(3325);
4177
4343
  const constants_1 = __nccwpck_require__(8865);
4344
+ const schedules_1 = __nccwpck_require__(3697);
4178
4345
  function getCloudRunDeployScripts(context) {
4179
4346
  var _a;
4180
4347
  const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
@@ -4189,14 +4356,14 @@ function getCloudRunDeployScripts(context) {
4189
4356
  ...(deployConfig.cloudSql
4190
4357
  ? (0, database_1.getDatabaseCreateScript)(context, deployConfig) // we create the db, so that we can also delete it afterwards
4191
4358
  : []),
4192
- ...(0, cloudRunJobs_1.getCreateScheduleScripts)(context),
4359
+ ...(0, schedules_1.getCreateScheduleScript)(context),
4193
4360
  ...(0, cloudRunJobs_1.getJobCreateScripts)(context),
4194
- ...(0, cloudRunJobs_1.getJobRunScripts)(context, "preDeploy"),
4361
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "preDeploy"),
4195
4362
  ...(deployConfig.service !== false
4196
4363
  ? [(0, cloudRunServices_1.getServiceDeployScript)(context, deployConfig.service)]
4197
4364
  : []),
4198
4365
  ...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"),
4366
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "postDeploy"),
4200
4367
  ]),
4201
4368
  ...(0, gitlab_1.collapseableSection)("cleanup", "Cleanup")((0, cleanup_1.getRemoveOldRevisionsAndImagesCommand)(context, "postDeploy")),
4202
4369
  ...(0, sbom_1.getDependencyTrackUploadScript)(context),
@@ -4219,6 +4386,8 @@ const cleanup_1 = __nccwpck_require__(7888);
4219
4386
  const database_1 = __nccwpck_require__(8206);
4220
4387
  const gcloudServiceAccountLoginCommands_1 = __nccwpck_require__(6320);
4221
4388
  const cloudRunJobs_1 = __nccwpck_require__(1224);
4389
+ const onDeploy_1 = __nccwpck_require__(2358);
4390
+ const schedules_1 = __nccwpck_require__(3697);
4222
4391
  const cloudRunServices_1 = __nccwpck_require__(7334);
4223
4392
  const common_1 = __nccwpck_require__(3325);
4224
4393
  function getCloudRunStopScripts(context) {
@@ -4226,11 +4395,11 @@ function getCloudRunStopScripts(context) {
4226
4395
  const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
4227
4396
  return [
4228
4397
  ...(0, gcloudServiceAccountLoginCommands_1.gcloudServiceAccountLoginCommands)(context),
4229
- ...(0, cloudRunJobs_1.getJobRunScripts)(context, "preStop"),
4398
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "preStop"),
4230
4399
  ...(deployConfig.service !== false ? (0, cloudRunServices_1.getServiceDeleteScript)(context) : []),
4231
4400
  ...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),
4401
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "postStop"),
4402
+ ...(0, schedules_1.getDeleteSchedulesScript)(context),
4234
4403
  ...(0, cloudRunJobs_1.getDeleteJobsScripts)(context),
4235
4404
  ...(deployConfig.cloudSql && deployConfig.cloudSql.deleteDatabaseOnStop
4236
4405
  ? (0, database_1.getDatabaseDeleteScript)(context, deployConfig)
@@ -4335,8 +4504,8 @@ const context_1 = __nccwpck_require__(5875);
4335
4504
  const gitlab_1 = __nccwpck_require__(8490);
4336
4505
  const utils_1 = __nccwpck_require__(2089);
4337
4506
  const createJobs_1 = __nccwpck_require__(4069);
4507
+ const cloudRunExecutionUrl_1 = __nccwpck_require__(4856);
4338
4508
  const database_1 = __nccwpck_require__(8206);
4339
- const jobName_1 = __nccwpck_require__(9626);
4340
4509
  exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
4341
4510
  // FIXME: rename to internalHostSuffix, but this means that project-setup needs to be rerun, so its kindof a breaking change
4342
4511
  exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = "GCLOUD_RUN_canonicalHostSuffix";
@@ -4392,7 +4561,11 @@ exports.GCLOUD_RUN_DEPLOY_TYPE = {
4392
4561
  const jobTriggers = deployConfigRaw && deployConfigRaw.jobs
4393
4562
  ? Object.fromEntries(Object.entries(deployConfigRaw.jobs).map(([name, job]) => [
4394
4563
  "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`,
4564
+ (0, cloudRunExecutionUrl_1.getCloudRunJobExecuteUrl)(name, {
4565
+ appFullName: fullName,
4566
+ projectId: deployConfigRaw.projectId,
4567
+ region: deployConfigRaw.region,
4568
+ }),
4396
4569
  ]))
4397
4570
  : {};
4398
4571
  return {
@@ -4412,6 +4585,24 @@ exports.GCLOUD_RUN_DEPLOY_TYPE = {
4412
4585
 
4413
4586
  /***/ }),
4414
4587
 
4588
+ /***/ 4856:
4589
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4590
+
4591
+ "use strict";
4592
+
4593
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
4594
+ exports.getCloudRunJobExecuteUrl = void 0;
4595
+ const jobName_1 = __nccwpck_require__(9626);
4596
+ function getCloudRunJobExecuteUrl(jobName, { region, projectId, appFullName, }) {
4597
+ const uriBase = `https://${region}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${projectId}/jobs`;
4598
+ const fullJobName = (0, jobName_1.getCloudRunJobName)(appFullName, jobName);
4599
+ return `${uriBase}/${fullJobName}:run`;
4600
+ }
4601
+ exports.getCloudRunJobExecuteUrl = getCloudRunJobExecuteUrl;
4602
+ //# sourceMappingURL=cloudRunExecutionUrl.js.map
4603
+
4604
+ /***/ }),
4605
+
4415
4606
  /***/ 9598:
4416
4607
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4417
4608
 
@@ -4546,9 +4737,15 @@ exports.getServiceName = getServiceName;
4546
4737
  "use strict";
4547
4738
 
4548
4739
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4549
- exports.getCloudRunJobName = void 0;
4740
+ exports.getFullSchedulerName = exports.getCloudRunSchedulerName = exports.getFullJobName = exports.getCloudRunJobName = void 0;
4550
4741
  const getCloudRunJobName = (fullAppName, jobName) => fullAppName.toLowerCase().concat("-" + jobName.toLowerCase());
4551
4742
  exports.getCloudRunJobName = getCloudRunJobName;
4743
+ const getFullJobName = (context, name) => (0, exports.getCloudRunJobName)(context.environment.fullName, name);
4744
+ exports.getFullJobName = getFullJobName;
4745
+ const getCloudRunSchedulerName = (fullAppName, schedulerName) => fullAppName.toLowerCase().concat("-" + schedulerName.toLowerCase());
4746
+ exports.getCloudRunSchedulerName = getCloudRunSchedulerName;
4747
+ const getFullSchedulerName = (context, name) => (0, exports.getCloudRunSchedulerName)(context.environment.fullName, name);
4748
+ exports.getFullSchedulerName = getFullSchedulerName;
4552
4749
  //# sourceMappingURL=jobName.js.map
4553
4750
 
4554
4751
  /***/ }),
@@ -5319,7 +5516,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
5319
5516
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
5320
5517
  };
5321
5518
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5322
- exports.isOfDeployType = void 0;
5519
+ exports.getDeployConfigType = exports.isOfDeployType = void 0;
5323
5520
  __exportStar(__nccwpck_require__(461), exports);
5324
5521
  __exportStar(__nccwpck_require__(6938), exports);
5325
5522
  __exportStar(__nccwpck_require__(8189), exports);
@@ -5328,6 +5525,12 @@ const isOfDeployType = (t, ...types) => {
5328
5525
  return t && types.includes(t.type) ? true : false;
5329
5526
  };
5330
5527
  exports.isOfDeployType = isOfDeployType;
5528
+ const getDeployConfigType = (t) => {
5529
+ if (!t)
5530
+ return undefined;
5531
+ return t.type;
5532
+ };
5533
+ exports.getDeployConfigType = getDeployConfigType;
5331
5534
  //# sourceMappingURL=index.js.map
5332
5535
 
5333
5536
  /***/ }),