@catladder/cli 0.0.0-fix-config-move-not-working-again-8ba85846 → 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 (52) hide show
  1. package/dist/bundles/catenv/index.js +336 -135
  2. package/dist/bundles/cli/index.js +479 -192
  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/cli/src/utils/preferences.js +9 -11
  14. package/dist/cli/src/utils/preferences.js.map +1 -1
  15. package/dist/pipeline/src/bash/bashEscape.d.ts +4 -1
  16. package/dist/pipeline/src/bash/bashEscape.js +4 -2
  17. package/dist/pipeline/src/bash/bashEscape.js.map +1 -1
  18. package/dist/pipeline/src/context/getEnvConfig.js +14 -2
  19. package/dist/pipeline/src/context/getEnvConfig.js.map +1 -1
  20. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.d.ts +5 -3
  21. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js +18 -107
  22. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js.map +1 -1
  23. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.d.ts +4 -0
  24. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.js +85 -0
  25. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.js.map +1 -0
  26. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/schedules.d.ts +3 -0
  27. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/schedules.js +136 -0
  28. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/schedules.js.map +1 -0
  29. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +5 -3
  30. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js.map +1 -1
  31. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.js +5 -3
  32. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.js.map +1 -1
  33. package/dist/pipeline/src/deploy/cloudRun/index.js +6 -2
  34. package/dist/pipeline/src/deploy/cloudRun/index.js.map +1 -1
  35. package/dist/pipeline/src/deploy/cloudRun/utils/cloudRunExecutionUrl.d.ts +6 -0
  36. package/dist/pipeline/src/deploy/cloudRun/utils/cloudRunExecutionUrl.js +11 -0
  37. package/dist/pipeline/src/deploy/cloudRun/utils/cloudRunExecutionUrl.js.map +1 -0
  38. package/dist/pipeline/src/deploy/cloudRun/utils/jobName.d.ts +5 -1
  39. package/dist/pipeline/src/deploy/cloudRun/utils/jobName.js +7 -1
  40. package/dist/pipeline/src/deploy/cloudRun/utils/jobName.js.map +1 -1
  41. package/dist/pipeline/src/deploy/types/googleCloudRun.d.ts +99 -1
  42. package/dist/pipeline/src/deploy/types/index.d.ts +1 -0
  43. package/dist/pipeline/src/deploy/types/index.js +7 -1
  44. package/dist/pipeline/src/deploy/types/index.js.map +1 -1
  45. package/dist/pipeline/src/types/config.d.ts +11 -6
  46. package/dist/tsconfig.tsbuildinfo +1 -1
  47. package/package.json +1 -1
  48. package/src/apps/catenv/printVariables.ts +4 -1
  49. package/src/apps/catenv/utils.ts +12 -3
  50. package/src/apps/cli/commands/project/commandCloudSqlProxy.ts +130 -66
  51. package/src/utils/log.ts +104 -8
  52. package/src/utils/preferences.ts +13 -23
@@ -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, "_");
@@ -726,21 +731,19 @@ const yaml_1 = __nccwpck_require__(8033);
726
731
  const legacyPreferencesPath = (0, path_1.join)((0, os_1.homedir)(), ".catladder/preferences.yml");
727
732
  const preferencesPath = (0, path_1.join)((0, os_1.homedir)(), ".config/catladder/preferences.yml");
728
733
  const ensurePreferencesFile = async () => {
729
- if ((0, fs_1.existsSync)(legacyPreferencesPath) && !(0, fs_1.existsSync)(preferencesPath)) {
730
- await (0, promises_1.mkdir)((0, path_1.dirname)(preferencesPath), { recursive: true, mode: 0o700 });
731
- await (0, promises_1.cp)(legacyPreferencesPath, preferencesPath);
732
- await (0, promises_1.chmod)(preferencesPath, 0o600);
733
- await (0, promises_1.cp)(preferencesPath, (0, path_1.join)((0, path_1.dirname)(preferencesPath), "old_preferences_backup.yml"));
734
- return;
735
- }
736
734
  if ((0, fs_1.existsSync)(preferencesPath)) {
737
735
  return;
738
736
  }
739
737
  await (0, promises_1.mkdir)((0, path_1.dirname)(preferencesPath), { recursive: true, mode: 0o700 });
740
- await (0, promises_1.writeFile)(preferencesPath, "---\n{}", {
741
- encoding: "utf-8",
742
- mode: 0o600,
743
- });
738
+ if (!(0, fs_1.existsSync)(legacyPreferencesPath)) {
739
+ return (0, promises_1.writeFile)(preferencesPath, "---\n{}", {
740
+ encoding: "utf-8",
741
+ mode: 0o600,
742
+ });
743
+ }
744
+ await (0, promises_1.cp)(legacyPreferencesPath, preferencesPath);
745
+ await (0, promises_1.chmod)(preferencesPath, 0o600);
746
+ await (0, promises_1.cp)(preferencesPath, (0, path_1.join)((0, path_1.dirname)(preferencesPath), "old_preferences_backup.yml"));
744
747
  };
745
748
  const loadPreferences = async () => {
746
749
  await ensurePreferencesFile();
@@ -961,14 +964,16 @@ exports.escapeSingleQuotes = escapeSingleQuotes;
961
964
  *
962
965
  * - other languages are currently only partially supported, since most .env implementations are slightly different
963
966
  */
964
- const escapeForDotEnv = (value) => {
967
+ const escapeForDotEnv = (value, options = {
968
+ quoteMode: "auto",
969
+ }) => {
965
970
  if (value === undefined || value === null) {
966
971
  return "";
967
972
  }
968
973
  if (typeof value === "string") {
969
974
  // if string contains newlines, we need to wrap it in quotes
970
975
  // we additionaly escape newlines, that give best compatibility
971
- if (value.includes("\n")) {
976
+ if (options.quoteMode === "always" || value.includes("\n")) {
972
977
  const newlinesReplaces = value.replace(/\n/g, "\\n");
973
978
  // default to ", but if this is not possible, we try to use ' or `
974
979
  const quote = value.includes(`"`)
@@ -2997,7 +3002,7 @@ exports.getBuildInfoVariables = getBuildInfoVariables;
2997
3002
 
2998
3003
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2999
3004
  exports.getEnvConfig = void 0;
3000
- const utils_1 = __nccwpck_require__(2497);
3005
+ const lodash_1 = __nccwpck_require__(3255);
3001
3006
  const getEnvConfig = (config, componentName, env) => {
3002
3007
  var _a, _b;
3003
3008
  const defaultConfig = config.components[componentName];
@@ -3009,7 +3014,19 @@ const getEnvConfig = (config, componentName, env) => {
3009
3014
  // env is disabled, still return the default config
3010
3015
  return defaultConfig;
3011
3016
  }
3012
- 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
+ });
3013
3030
  };
3014
3031
  exports.getEnvConfig = getEnvConfig;
3015
3032
  //# sourceMappingURL=getEnvConfig.js.map
@@ -3843,69 +3860,35 @@ exports.getDeleteUnusedRevisionsCommands = getDeleteUnusedRevisionsCommands;
3843
3860
  "use strict";
3844
3861
 
3845
3862
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3846
- 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);
3847
3866
  const createArgsString_1 = __nccwpck_require__(9598);
3848
3867
  const jobName_1 = __nccwpck_require__(9626);
3849
3868
  const common_1 = __nccwpck_require__(3325);
3850
- const getLabels_1 = __nccwpck_require__(920);
3851
- const volumes_1 = __nccwpck_require__(847);
3852
3869
  const constants_1 = __nccwpck_require__(8865);
3853
- const utils_1 = __nccwpck_require__(2497);
3854
- const getJobRunScriptForJob = (context, jobName, wait) => {
3855
- const commonArgs = (0, common_1.getCommonCloudRunArgs)(context);
3856
- const commonArgsString = (0, createArgsString_1.createArgsString)(commonArgs);
3857
- return `${(0, common_1.gcloudRunCmd)()} jobs execute ${jobName.toString()} ${commonArgsString}${wait ? " --wait" : ""}`;
3858
- };
3859
- const getDeleteSchedulesScripts = (context) => {
3860
- const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
3861
- const schedules = getSchedules(context);
3862
- const argsString = (0, createArgsString_1.createArgsString)({
3863
- project: deployConfig.projectId,
3864
- location: deployConfig.region,
3865
- });
3866
- return schedules
3867
- .map(({ name }) => {
3868
- return [`${(0, common_1.gcloudSchedulerCmd)()} jobs delete ${name} ${argsString}`];
3869
- })
3870
- .flat();
3871
- };
3872
- exports.getDeleteSchedulesScripts = getDeleteSchedulesScripts;
3870
+ const volumes_1 = __nccwpck_require__(847);
3871
+ const onDeploy_1 = __nccwpck_require__(2358);
3873
3872
  const getDeleteJobsScripts = (context) => {
3874
3873
  const commonArgs = (0, common_1.getCommonCloudRunArgs)(context);
3875
3874
  const commonArgsString = (0, createArgsString_1.createArgsString)(commonArgs);
3876
- const jobsWithNames = getCloudRunJobsWithNames(context);
3877
- return jobsWithNames.flatMap(({ jobName }) => [
3875
+ const jobsWithNames = (0, exports.getCloudRunJobsWithNames)(context);
3876
+ return jobsWithNames.flatMap(({ fullJobName }) => [
3878
3877
  // first delete all job executions. Otherwise delete might fail if one of those is still running
3879
- `${(0, common_1.gcloudRunCmd)()} jobs executions list ${commonArgsString} --job ${jobName} --format="value(name)" | xargs -I {} ${(0, common_1.gcloudRunCmd)()} jobs executions delete {} --quiet ${commonArgsString}`,
3880
- `${(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}`,
3881
3880
  ]);
3882
3881
  };
3883
3882
  exports.getDeleteJobsScripts = getDeleteJobsScripts;
3884
- const getJobRunScripts = (context, when) => {
3885
- const jobsWithNames = getCloudRunJobsWithNames(context);
3886
- return jobsWithNames
3887
- .filter(({ job }) => job.when === when)
3888
- .map(({ jobName, job }) => {
3889
- var _a;
3890
- // always wait for completion for preStop and postStop jobs
3891
- // since stop will delete the jobs afterwards, so they will fail
3892
- const waitForCompletion = ["preStop", "postStop"].includes(when)
3893
- ? true
3894
- : "waitForCompletion" in job
3895
- ? ((_a = job.waitForCompletion) !== null && _a !== void 0 ? _a : false)
3896
- : false;
3897
- return getJobRunScriptForJob(context, jobName, waitForCompletion);
3898
- });
3899
- };
3900
- exports.getJobRunScripts = getJobRunScripts;
3901
- const getJobCreateScripts = (context) => getCloudRunJobsWithNames(context).map(({ job, jobName }, jobIndex) => {
3902
- var _a, _b, _c, _d;
3883
+ const getJobCreateScripts = (context) => (0, exports.getCloudRunJobsWithNames)(context).map(({ job, fullJobName }, jobIndex) => {
3884
+ var _a, _b, _c, _d, _e;
3903
3885
  const commandArray = Array.isArray(job.command)
3904
3886
  ? job.command
3905
3887
  : job.command.split(" ");
3906
3888
  const { image: commonImage, project, region, ...deployArgs } = (0, common_1.getCommonDeployArgs)(context);
3907
3889
  const commonDeployArgsString = (0, createArgsString_1.createArgsString)({
3908
3890
  command: `"${commandArray.join(",")}"`,
3891
+ args: (0, onDeploy_1.getCloudRunJobArgsArg)(job.args),
3909
3892
  labels: `"${(0, common_1.makeLabelString)((0, getLabels_1.getLabels)(context))},cloud-run-job-name=$current_job_name"`,
3910
3893
  image: `"${(_a = job.image) !== null && _a !== void 0 ? _a : commonImage}"`,
3911
3894
  project,
@@ -3915,7 +3898,7 @@ const getJobCreateScripts = (context) => getCloudRunJobsWithNames(context).map((
3915
3898
  parallelism: (_c = job.parallelism) !== null && _c !== void 0 ? _c : 1,
3916
3899
  "task-timeout": (_d = job.timeout) !== null && _d !== void 0 ? _d : "10m",
3917
3900
  "env-vars-file": constants_1.ENV_VARS_FILENAME,
3918
- "max-retries": 0,
3901
+ "max-retries": (_e = job.maxRetries) !== null && _e !== void 0 ? _e : 0,
3919
3902
  ...deployArgs,
3920
3903
  // network
3921
3904
  "vpc-connector": job === null || job === void 0 ? void 0 : job.vpcConnector,
@@ -3927,7 +3910,7 @@ const getJobCreateScripts = (context) => getCloudRunJobsWithNames(context).map((
3927
3910
  jobIndex === 0
3928
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)"`
3929
3912
  : null,
3930
- `current_job_name="${jobName}"`,
3913
+ `current_job_name="${fullJobName}"`,
3931
3914
  'if grep "$current_job_name" <<<"$exist_job_names" >/dev/null; then',
3932
3915
  ` ${(0, common_1.gcloudRunCmd)()} jobs update "$current_job_name" ${commonDeployArgsString}`,
3933
3916
  "else",
@@ -3938,75 +3921,20 @@ const getJobCreateScripts = (context) => getCloudRunJobsWithNames(context).map((
3938
3921
  .join("\n");
3939
3922
  });
3940
3923
  exports.getJobCreateScripts = getJobCreateScripts;
3941
- const getCreateScheduleScripts = (context) => {
3942
- const schedules = getSchedules(context);
3943
- const { region: location, projectId: project } = (0, common_1.getCloudRunDeployConfig)(context);
3944
- return schedules.map((scheduler, jobIndex) => {
3945
- var _a;
3946
- const uri = getSchedulerUrl(scheduler, context);
3947
- const argsString = (0, createArgsString_1.createArgsString)({
3948
- project,
3949
- location,
3950
- uri: `"$current_job_uri"`,
3951
- "http-method": "POST",
3952
- "oauth-service-account-email": `"$GCLOUD_PROJECT_NUMBER-compute@developer.gserviceaccount.com"`,
3953
- schedule: `"${scheduler.schedule}"`,
3954
- "max-retry-attempts": (_a = scheduler.maxRetryAttempts) !== null && _a !== void 0 ? _a : 0,
3955
- });
3956
- return [
3957
- jobIndex === 0
3958
- ? `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)"`
3959
- : null,
3960
- `current_job_uri="${uri}"`,
3961
- `current_scheduler_name="${scheduler.name}"`,
3962
- `if grep "$current_scheduler_name" <<<"$exist_scheduler_names" >/dev/null; then`,
3963
- ` ${(0, common_1.gcloudSchedulerCmd)()} jobs update http "$current_scheduler_name" ${argsString}`,
3964
- `else`,
3965
- ` ${(0, common_1.gcloudSchedulerCmd)()} jobs create http "$current_scheduler_name" ${argsString}`,
3966
- `fi`,
3967
- ]
3968
- .filter(utils_1.notNil)
3969
- .join("\n");
3970
- });
3971
- };
3972
- exports.getCreateScheduleScripts = getCreateScheduleScripts;
3973
- const getSchedulerUrl = (scheduler, context) => {
3974
- if (scheduler.type === "cloudRunJob") {
3975
- const { region: location, projectId: project } = (0, common_1.getCloudRunDeployConfig)(context);
3976
- const uriBase = `https://${location}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${project}/jobs`;
3977
- return `${uriBase}/${scheduler.jobName}:run`;
3978
- }
3979
- throw new Error(`Unknown scheduler type: ${scheduler.type}`);
3980
- };
3981
- const getSchedules = (context) => {
3982
- const jobsWithNames = getCloudRunJobsWithNames(context);
3983
- return jobsWithNames
3984
- .filter((entry) => entry.job.when === "schedule")
3985
- .map(({ job: { maxRetryAttempts, schedule }, jobName }) => {
3986
- const schedulerName = jobName.concat("-scheduler");
3987
- return {
3988
- name: schedulerName,
3989
- maxRetryAttempts,
3990
- schedule,
3991
- type: "cloudRunJob",
3992
- jobName,
3993
- };
3994
- });
3995
- };
3996
3924
  const getCloudRunJobsWithNames = (context) => {
3997
3925
  var _a;
3998
3926
  const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
3999
- const getFullJobName = (name) => (0, jobName_1.getCloudRunJobName)(context.environment.fullName, name);
4000
3927
  const jobsWithNames = Object.entries((_a = deployConfig.jobs) !== null && _a !== void 0 ? _a : {})
4001
3928
  // filter out disabled jobs
4002
3929
  .filter((entry) => Boolean(entry[1]))
4003
- .map(([jobKey, job]) => ({
4004
- jobName: getFullJobName(jobKey),
3930
+ .map(([jobName, job]) => ({
3931
+ fullJobName: (0, jobName_1.getFullJobName)(context, jobName),
4005
3932
  job,
4006
- jobKey,
3933
+ jobName,
4007
3934
  }));
4008
3935
  return jobsWithNames;
4009
3936
  };
3937
+ exports.getCloudRunJobsWithNames = getCloudRunJobsWithNames;
4010
3938
  //# sourceMappingURL=cloudRunJobs.js.map
4011
3939
 
4012
3940
  /***/ }),
@@ -4158,6 +4086,241 @@ exports.ENV_VARS_FILENAME = "____envvars.yaml";
4158
4086
 
4159
4087
  /***/ }),
4160
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
+
4161
4324
  /***/ 3695:
4162
4325
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4163
4326
 
@@ -4174,9 +4337,11 @@ const cleanup_1 = __nccwpck_require__(7888);
4174
4337
  const database_1 = __nccwpck_require__(8206);
4175
4338
  const gcloudServiceAccountLoginCommands_1 = __nccwpck_require__(6320);
4176
4339
  const cloudRunJobs_1 = __nccwpck_require__(1224);
4340
+ const onDeploy_1 = __nccwpck_require__(2358);
4177
4341
  const cloudRunServices_1 = __nccwpck_require__(7334);
4178
4342
  const common_1 = __nccwpck_require__(3325);
4179
4343
  const constants_1 = __nccwpck_require__(8865);
4344
+ const schedules_1 = __nccwpck_require__(3697);
4180
4345
  function getCloudRunDeployScripts(context) {
4181
4346
  var _a;
4182
4347
  const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
@@ -4191,14 +4356,14 @@ function getCloudRunDeployScripts(context) {
4191
4356
  ...(deployConfig.cloudSql
4192
4357
  ? (0, database_1.getDatabaseCreateScript)(context, deployConfig) // we create the db, so that we can also delete it afterwards
4193
4358
  : []),
4194
- ...(0, cloudRunJobs_1.getCreateScheduleScripts)(context),
4359
+ ...(0, schedules_1.getCreateScheduleScript)(context),
4195
4360
  ...(0, cloudRunJobs_1.getJobCreateScripts)(context),
4196
- ...(0, cloudRunJobs_1.getJobRunScripts)(context, "preDeploy"),
4361
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "preDeploy"),
4197
4362
  ...(deployConfig.service !== false
4198
4363
  ? [(0, cloudRunServices_1.getServiceDeployScript)(context, deployConfig.service)]
4199
4364
  : []),
4200
4365
  ...Object.entries((_a = deployConfig.additionalServices) !== null && _a !== void 0 ? _a : {}).map(([name, service]) => (0, cloudRunServices_1.getServiceDeployScript)(context, service, "-" + name)),
4201
- ...(0, cloudRunJobs_1.getJobRunScripts)(context, "postDeploy"),
4366
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "postDeploy"),
4202
4367
  ]),
4203
4368
  ...(0, gitlab_1.collapseableSection)("cleanup", "Cleanup")((0, cleanup_1.getRemoveOldRevisionsAndImagesCommand)(context, "postDeploy")),
4204
4369
  ...(0, sbom_1.getDependencyTrackUploadScript)(context),
@@ -4221,6 +4386,8 @@ const cleanup_1 = __nccwpck_require__(7888);
4221
4386
  const database_1 = __nccwpck_require__(8206);
4222
4387
  const gcloudServiceAccountLoginCommands_1 = __nccwpck_require__(6320);
4223
4388
  const cloudRunJobs_1 = __nccwpck_require__(1224);
4389
+ const onDeploy_1 = __nccwpck_require__(2358);
4390
+ const schedules_1 = __nccwpck_require__(3697);
4224
4391
  const cloudRunServices_1 = __nccwpck_require__(7334);
4225
4392
  const common_1 = __nccwpck_require__(3325);
4226
4393
  function getCloudRunStopScripts(context) {
@@ -4228,11 +4395,11 @@ function getCloudRunStopScripts(context) {
4228
4395
  const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
4229
4396
  return [
4230
4397
  ...(0, gcloudServiceAccountLoginCommands_1.gcloudServiceAccountLoginCommands)(context),
4231
- ...(0, cloudRunJobs_1.getJobRunScripts)(context, "preStop"),
4398
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "preStop"),
4232
4399
  ...(deployConfig.service !== false ? (0, cloudRunServices_1.getServiceDeleteScript)(context) : []),
4233
4400
  ...Object.entries((_a = deployConfig.additionalServices) !== null && _a !== void 0 ? _a : {}).flatMap(([name]) => (0, cloudRunServices_1.getServiceDeleteScript)(context, name)),
4234
- ...(0, cloudRunJobs_1.getJobRunScripts)(context, "postStop"),
4235
- ...(0, cloudRunJobs_1.getDeleteSchedulesScripts)(context),
4401
+ ...(0, onDeploy_1.getOnDeployExecuteScript)(context, "postStop"),
4402
+ ...(0, schedules_1.getDeleteSchedulesScript)(context),
4236
4403
  ...(0, cloudRunJobs_1.getDeleteJobsScripts)(context),
4237
4404
  ...(deployConfig.cloudSql && deployConfig.cloudSql.deleteDatabaseOnStop
4238
4405
  ? (0, database_1.getDatabaseDeleteScript)(context, deployConfig)
@@ -4337,8 +4504,8 @@ const context_1 = __nccwpck_require__(5875);
4337
4504
  const gitlab_1 = __nccwpck_require__(8490);
4338
4505
  const utils_1 = __nccwpck_require__(2089);
4339
4506
  const createJobs_1 = __nccwpck_require__(4069);
4507
+ const cloudRunExecutionUrl_1 = __nccwpck_require__(4856);
4340
4508
  const database_1 = __nccwpck_require__(8206);
4341
- const jobName_1 = __nccwpck_require__(9626);
4342
4509
  exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
4343
4510
  // FIXME: rename to internalHostSuffix, but this means that project-setup needs to be rerun, so its kindof a breaking change
4344
4511
  exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = "GCLOUD_RUN_canonicalHostSuffix";
@@ -4394,7 +4561,11 @@ exports.GCLOUD_RUN_DEPLOY_TYPE = {
4394
4561
  const jobTriggers = deployConfigRaw && deployConfigRaw.jobs
4395
4562
  ? Object.fromEntries(Object.entries(deployConfigRaw.jobs).map(([name, job]) => [
4396
4563
  "CLOUD_RUN_JOB_TRIGGER_URL_" + (0, gitlab_1.sanitizeForBashVariable)(name),
4397
- `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
+ }),
4398
4569
  ]))
4399
4570
  : {};
4400
4571
  return {
@@ -4414,6 +4585,24 @@ exports.GCLOUD_RUN_DEPLOY_TYPE = {
4414
4585
 
4415
4586
  /***/ }),
4416
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
+
4417
4606
  /***/ 9598:
4418
4607
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4419
4608
 
@@ -4548,9 +4737,15 @@ exports.getServiceName = getServiceName;
4548
4737
  "use strict";
4549
4738
 
4550
4739
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4551
- exports.getCloudRunJobName = void 0;
4740
+ exports.getFullSchedulerName = exports.getCloudRunSchedulerName = exports.getFullJobName = exports.getCloudRunJobName = void 0;
4552
4741
  const getCloudRunJobName = (fullAppName, jobName) => fullAppName.toLowerCase().concat("-" + jobName.toLowerCase());
4553
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;
4554
4749
  //# sourceMappingURL=jobName.js.map
4555
4750
 
4556
4751
  /***/ }),
@@ -5321,7 +5516,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
5321
5516
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
5322
5517
  };
5323
5518
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5324
- exports.isOfDeployType = void 0;
5519
+ exports.getDeployConfigType = exports.isOfDeployType = void 0;
5325
5520
  __exportStar(__nccwpck_require__(461), exports);
5326
5521
  __exportStar(__nccwpck_require__(6938), exports);
5327
5522
  __exportStar(__nccwpck_require__(8189), exports);
@@ -5330,6 +5525,12 @@ const isOfDeployType = (t, ...types) => {
5330
5525
  return t && types.includes(t.type) ? true : false;
5331
5526
  };
5332
5527
  exports.isOfDeployType = isOfDeployType;
5528
+ const getDeployConfigType = (t) => {
5529
+ if (!t)
5530
+ return undefined;
5531
+ return t.type;
5532
+ };
5533
+ exports.getDeployConfigType = getDeployConfigType;
5333
5534
  //# sourceMappingURL=index.js.map
5334
5535
 
5335
5536
  /***/ }),