@catladder/cli 0.0.0-next-8b9ad5ca → 0.0.0-next-1cd29c1f

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 (119) hide show
  1. package/dist/bundles/catenv/index.js +19666 -1581
  2. package/dist/bundles/cli/index.js +18360 -195
  3. package/dist/cli/src/apps/cli/commands/project/commandConfigSecrets.js +22 -4
  4. package/dist/cli/src/apps/cli/commands/project/commandConfigSecrets.js.map +1 -1
  5. package/dist/cli/src/apps/cli/commands/project/setup/setupCloudRun.js +16 -14
  6. package/dist/cli/src/apps/cli/commands/project/setup/setupCloudRun.js.map +1 -1
  7. package/dist/cli/src/commands/project/commandSecretsSyncGithub.d.ts +11 -2
  8. package/dist/cli/src/commands/project/commandSecretsSyncGithub.js +37 -14
  9. package/dist/cli/src/commands/project/commandSecretsSyncGithub.js.map +1 -1
  10. package/dist/cli/src/gcloud/getProjectNumber.d.ts +5 -0
  11. package/dist/cli/src/gcloud/getProjectNumber.js +20 -0
  12. package/dist/cli/src/gcloud/getProjectNumber.js.map +1 -0
  13. package/dist/cli/src/store/updateCatladderStore.d.ts +10 -0
  14. package/dist/cli/src/store/updateCatladderStore.js +32 -0
  15. package/dist/cli/src/store/updateCatladderStore.js.map +1 -0
  16. package/dist/cli/src/utils/github.d.ts +6 -1
  17. package/dist/cli/src/utils/github.js +16 -9
  18. package/dist/cli/src/utils/github.js.map +1 -1
  19. package/dist/pipeline/src/backends/github/GithubBackend.d.ts +4 -1
  20. package/dist/pipeline/src/backends/github/GithubBackend.js +70 -12
  21. package/dist/pipeline/src/backends/github/GithubBackend.js.map +1 -1
  22. package/dist/pipeline/src/backends/github/ciVariables.js +3 -1
  23. package/dist/pipeline/src/backends/github/ciVariables.js.map +1 -1
  24. package/dist/pipeline/src/backends/github/createGithubJobs.d.ts +13 -3
  25. package/dist/pipeline/src/backends/github/createGithubJobs.js +80 -14
  26. package/dist/pipeline/src/backends/github/createGithubJobs.js.map +1 -1
  27. package/dist/pipeline/src/backends/github/githubReleaseJobs.d.ts +2 -1
  28. package/dist/pipeline/src/backends/github/githubReleaseJobs.js +46 -33
  29. package/dist/pipeline/src/backends/github/githubReleaseJobs.js.map +1 -1
  30. package/dist/pipeline/src/backends/github/index.d.ts +2 -1
  31. package/dist/pipeline/src/backends/github/index.js +2 -1
  32. package/dist/pipeline/src/backends/github/index.js.map +1 -1
  33. package/dist/pipeline/src/backends/github/scriptFiles.d.ts +25 -0
  34. package/dist/pipeline/src/backends/github/scriptFiles.js +50 -0
  35. package/dist/pipeline/src/backends/github/scriptFiles.js.map +1 -0
  36. package/dist/pipeline/src/backends/gitlab/GitlabBackend.d.ts +1 -0
  37. package/dist/pipeline/src/backends/gitlab/GitlabBackend.js +18 -8
  38. package/dist/pipeline/src/backends/gitlab/GitlabBackend.js.map +1 -1
  39. package/dist/pipeline/src/backends/gitlab/ciVariables.js +2 -1
  40. package/dist/pipeline/src/backends/gitlab/ciVariables.js.map +1 -1
  41. package/dist/pipeline/src/backends/gitlab/createGitlabJobs.d.ts +3 -2
  42. package/dist/pipeline/src/backends/gitlab/createGitlabJobs.js +84 -10
  43. package/dist/pipeline/src/backends/gitlab/createGitlabJobs.js.map +1 -1
  44. package/dist/pipeline/src/backends/gitlab/createGitlabPipeline.js +1 -1
  45. package/dist/pipeline/src/backends/gitlab/createGitlabPipeline.js.map +1 -1
  46. package/dist/pipeline/src/backends/gitlab/gitlabReleaseJobs.js +2 -2
  47. package/dist/pipeline/src/backends/gitlab/gitlabReleaseJobs.js.map +1 -1
  48. package/dist/pipeline/src/backends/types.d.ts +2 -1
  49. package/dist/pipeline/src/bash/ciVariables.d.ts +1 -1
  50. package/dist/pipeline/src/bash/ciVariables.js.map +1 -1
  51. package/dist/pipeline/src/build/node/yarn.js +4 -1
  52. package/dist/pipeline/src/build/node/yarn.js.map +1 -1
  53. package/dist/pipeline/src/build/types.d.ts +1 -1
  54. package/dist/pipeline/src/config/readConfig.js +15 -4
  55. package/dist/pipeline/src/config/readConfig.js.map +1 -1
  56. package/dist/pipeline/src/constants.js +1 -1
  57. package/dist/pipeline/src/context/getEnvironmentVariables.d.ts +8 -0
  58. package/dist/pipeline/src/context/getEnvironmentVariables.js +3 -3
  59. package/dist/pipeline/src/context/getEnvironmentVariables.js.map +1 -1
  60. package/dist/pipeline/src/context/transformJobOnlyVars.js +2 -2
  61. package/dist/pipeline/src/context/transformJobOnlyVars.js.map +1 -1
  62. package/dist/pipeline/src/context/utils/envVars.d.ts +7 -0
  63. package/dist/pipeline/src/context/utils/envVars.js +22 -1
  64. package/dist/pipeline/src/context/utils/envVars.js.map +1 -1
  65. package/dist/pipeline/src/customImages/hash.d.ts +15 -0
  66. package/dist/pipeline/src/customImages/hash.js +71 -0
  67. package/dist/pipeline/src/customImages/hash.js.map +1 -0
  68. package/dist/pipeline/src/customImages/jobImagesPlan.d.ts +59 -0
  69. package/dist/pipeline/src/customImages/jobImagesPlan.js +172 -0
  70. package/dist/pipeline/src/customImages/jobImagesPlan.js.map +1 -0
  71. package/dist/pipeline/src/customImages/shippedImages.d.ts +28 -0
  72. package/dist/pipeline/src/customImages/shippedImages.js +60 -0
  73. package/dist/pipeline/src/customImages/shippedImages.js.map +1 -0
  74. package/dist/pipeline/src/deploy/cloudRun/createJobs/common.d.ts +6 -3
  75. package/dist/pipeline/src/deploy/cloudRun/createJobs/common.js +11 -3
  76. package/dist/pipeline/src/deploy/cloudRun/createJobs/common.js.map +1 -1
  77. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/schedules.js +2 -2
  78. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/schedules.js.map +1 -1
  79. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +1 -1
  80. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js.map +1 -1
  81. package/dist/pipeline/src/deploy/cloudRun/index.d.ts +0 -1
  82. package/dist/pipeline/src/deploy/cloudRun/index.js +11 -13
  83. package/dist/pipeline/src/deploy/cloudRun/index.js.map +1 -1
  84. package/dist/pipeline/src/deploy/cloudRun/utils/database.js +4 -1
  85. package/dist/pipeline/src/deploy/cloudRun/utils/database.js.map +1 -1
  86. package/dist/pipeline/src/index.d.ts +1 -0
  87. package/dist/pipeline/src/index.js +1 -0
  88. package/dist/pipeline/src/index.js.map +1 -1
  89. package/dist/pipeline/src/pipeline/generatePipelineFiles.js +16 -1
  90. package/dist/pipeline/src/pipeline/generatePipelineFiles.js.map +1 -1
  91. package/dist/pipeline/src/runner/index.d.ts +20 -1
  92. package/dist/pipeline/src/runner/index.js +16 -3
  93. package/dist/pipeline/src/runner/index.js.map +1 -1
  94. package/dist/pipeline/src/store/index.d.ts +36 -0
  95. package/dist/pipeline/src/store/index.js +64 -0
  96. package/dist/pipeline/src/store/index.js.map +1 -0
  97. package/dist/pipeline/src/types/config.d.ts +36 -2
  98. package/dist/pipeline/src/types/config.js.map +1 -1
  99. package/dist/pipeline/src/types/github-types.d.ts +5 -0
  100. package/dist/pipeline/src/types/jobs.d.ts +10 -2
  101. package/dist/pipeline/src/types/jobs.js.map +1 -1
  102. package/dist/pipeline/src/utils/gitlab.d.ts +5 -0
  103. package/dist/pipeline/src/utils/gitlab.js +6 -0
  104. package/dist/pipeline/src/utils/gitlab.js.map +1 -1
  105. package/dist/pipeline/src/utils/writeFiles.d.ts +6 -0
  106. package/dist/pipeline/src/utils/writeFiles.js +8 -0
  107. package/dist/pipeline/src/utils/writeFiles.js.map +1 -1
  108. package/dist/tsconfig.tsbuildinfo +1 -1
  109. package/package.json +1 -1
  110. package/src/apps/cli/commands/project/commandConfigSecrets.ts +25 -5
  111. package/src/apps/cli/commands/project/setup/setupCloudRun.ts +13 -21
  112. package/src/commands/project/commandSecretsSyncGithub.ts +34 -11
  113. package/src/gcloud/getProjectNumber.ts +20 -0
  114. package/src/store/updateCatladderStore.ts +33 -0
  115. package/src/utils/github.ts +24 -7
  116. package/dist/cli/src/gcloud/cloudRun/getCloudRunDomainSuffix.d.ts +0 -2
  117. package/dist/cli/src/gcloud/cloudRun/getCloudRunDomainSuffix.js +0 -29
  118. package/dist/cli/src/gcloud/cloudRun/getCloudRunDomainSuffix.js.map +0 -1
  119. package/src/gcloud/cloudRun/getCloudRunDomainSuffix.ts +0 -35
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "0.0.0-next-8b9ad5ca",
56
+ "version": "0.0.0-next-1cd29c1f",
57
57
  "scripts": {
58
58
  "lint": "eslint \"src/**/*.ts\"",
59
59
  "lint:fix": "eslint \"src/**/*.ts\" --fix",
@@ -243,15 +243,35 @@ const mirrorSecretsToCiBackends = async (
243
243
  if (!enabled.includes("github")) {
244
244
  return;
245
245
  }
246
+ const kinds = new Map<string, "secret" | "variable">();
247
+ for (const [componentName, envs] of Object.entries(envAndComponents)) {
248
+ for (const env of envs) {
249
+ const { secretEnvVarKeys, jobOnlyVars } = await getEnvironment(
250
+ env,
251
+ componentName,
252
+ );
253
+ [
254
+ ...secretEnvVarKeys,
255
+ ...jobOnlyVars.build.secretEnvVarKeys,
256
+ ...jobOnlyVars.deploy.secretEnvVarKeys,
257
+ ].forEach(({ key, kind }) =>
258
+ kinds.set(getSecretVarName(env, componentName, key), kind ?? "secret"),
259
+ );
260
+ }
261
+ }
246
262
  const secrets = Object.entries(envAndComponents).flatMap(
247
263
  ([componentName, envs]) =>
248
264
  envs.flatMap((env) =>
249
265
  Object.entries(valuesToEdit[componentName][env] ?? {}).map(
250
- ([key, value]) => ({
251
- name: getSecretVarName(env, componentName, key),
252
- value:
253
- typeof value === "string" ? value : JSON.stringify(value ?? ""),
254
- }),
266
+ ([key, value]) => {
267
+ const name = getSecretVarName(env, componentName, key);
268
+ return {
269
+ name,
270
+ value:
271
+ typeof value === "string" ? value : JSON.stringify(value ?? ""),
272
+ kind: kinds.get(name) ?? ("secret" as const),
273
+ };
274
+ },
255
275
  ),
256
276
  ),
257
277
  );
@@ -1,16 +1,15 @@
1
1
  import type { ComponentContext } from "@catladder/pipeline";
2
2
  import {
3
3
  GCLOUD_DEPLOY_CREDENTIALS_KEY,
4
- GCLOUD_RUN_CANONICAL_HOST_SUFFIX,
5
4
  isOfDeployType,
6
5
  } from "@catladder/pipeline";
7
6
 
8
7
  import type { IO } from "../../../../../core/types";
9
8
  import { upsertGcloudArtifactsRegistry } from "../../../../../gcloud/artifactsRegistry";
10
- import { getCloudRunDomainSuffix } from "../../../../../gcloud/cloudRun/getCloudRunDomainSuffix";
11
9
  import { enableGCloudServices } from "../../../../../gcloud/enableServices";
10
+ import { fetchGcloudProjectNumber } from "../../../../../gcloud/getProjectNumber";
12
11
  import { upsertGcloudServiceAccountAndSaveSecret } from "../../../../../gcloud/serviceAccounts";
13
- import { upsertAllVariables } from "../../../../../utils/gitlab";
12
+ import { updateCatladderStore } from "../../../../../store/updateCatladderStore";
14
13
 
15
14
  export const setupCloudRun = async (
16
15
  instance: IO,
@@ -61,24 +60,17 @@ export const setupCloudRun = async (
61
60
  GCLOUD_DEPLOY_CREDENTIALS_KEY,
62
61
  );
63
62
 
64
- // gcloud run automatically gives us a hostname
65
- // but the pipeline need to know it before deployment
66
- // so we get this through some magic and add this as a ci/cd variable
67
- // the pipeline than can use this to construct the canonical host
68
- instance.log(
69
- "get service domain suffix... that might take a while initially",
70
- );
71
- const suffix = await getCloudRunDomainSuffix(config);
72
- instance.log("domain suffix: " + suffix);
63
+ // the project number is needed at generation time to construct cloud
64
+ // run's deterministic urls (<service>-<projectNumber>.<region>.run.app)
65
+ instance.log("fetch gcloud project number...");
66
+ const projectNumber = await fetchGcloudProjectNumber(config.projectId);
67
+ instance.log("project number: " + projectNumber);
73
68
 
74
- await upsertAllVariables(
75
- instance,
76
- {
77
- [GCLOUD_RUN_CANONICAL_HOST_SUFFIX]: suffix,
69
+ await updateCatladderStore((store) => ({
70
+ ...store,
71
+ gcloudProjects: {
72
+ ...store.gcloudProjects,
73
+ [config.projectId]: { projectNumber },
78
74
  },
79
- context.env,
80
- context.name,
81
- false, // backup
82
- false, // masked
83
- );
75
+ }));
84
76
  };
@@ -14,18 +14,22 @@ import {
14
14
  getGithubRepoFromRemote,
15
15
  isGhAuthenticated,
16
16
  setGithubSecret,
17
+ setGithubVariable,
17
18
  } from "../../utils/github";
18
19
 
19
20
  /**
20
21
  * all secrets declared in the config, with their values read from the
21
22
  * vault (github secrets are write-only and can never act as a source)
22
23
  */
23
- export const collectSecretsFromVault = async (io: IO) => {
24
+ export const collectSecretsFromVault = async (io: IO, envFilter?: string[]) => {
24
25
  const envAndComponents = await getAllComponentsWithAllEnvsHierarchical();
25
26
 
26
- const names: string[] = [];
27
+ const kinds = new Map<string, "secret" | "variable">();
27
28
  for (const [componentName, envs] of Object.entries(envAndComponents)) {
28
29
  for (const env of envs) {
30
+ if (envFilter && !envFilter.includes(env)) {
31
+ continue;
32
+ }
29
33
  const { secretEnvVarKeys, jobOnlyVars } = await getEnvironment(
30
34
  env,
31
35
  componentName,
@@ -35,31 +39,42 @@ export const collectSecretsFromVault = async (io: IO) => {
35
39
  ...jobOnlyVars.build.secretEnvVarKeys,
36
40
  ...jobOnlyVars.deploy.secretEnvVarKeys,
37
41
  ];
38
- keys.forEach(({ key }) =>
39
- names.push(getSecretVarName(env, componentName, key)),
42
+ keys.forEach(({ key, kind }) =>
43
+ kinds.set(getSecretVarName(env, componentName, key), kind ?? "secret"),
40
44
  );
41
45
  }
42
46
  }
43
47
 
48
+ const names = [...kinds.keys()];
44
49
  const values = await (await io.getVaultManager()).readSecrets(names, io);
45
50
  const secrets = names
46
51
  .filter((name) => values[name] !== undefined)
47
- .map((name) => ({ name, value: values[name] }));
52
+ .map((name) => ({
53
+ name,
54
+ value: values[name],
55
+ kind: kinds.get(name) ?? ("secret" as const),
56
+ }));
48
57
  const missing = names.filter((name) => values[name] === undefined);
49
58
  return { secrets, missing };
50
59
  };
51
60
 
52
61
  /**
53
- * pushes secrets to github repository secrets via the gh cli
62
+ * pushes vault values to github via the gh cli: sensitive ones as repo
63
+ * secrets (masked), "variable"-kind ones as repo variables (plain)
54
64
  */
55
65
  export const pushSecretsToGithub = async (
56
66
  io: IO,
57
67
  repo: string,
58
- secrets: { name: string; value: string }[],
68
+ secrets: { name: string; value: string; kind: "secret" | "variable" }[],
59
69
  ) => {
60
- for (const { name, value } of secrets) {
61
- await setGithubSecret(repo, name, value);
62
- io.log(`✅ ${name}`);
70
+ for (const { name, value, kind } of secrets) {
71
+ if (kind === "variable") {
72
+ await setGithubVariable(repo, name, value);
73
+ io.log(`📖 ${name} (variable)`);
74
+ } else {
75
+ await setGithubSecret(repo, name, value);
76
+ io.log(`✅ ${name}`);
77
+ }
63
78
  }
64
79
  };
65
80
 
@@ -94,6 +109,13 @@ export const commandSecretsSyncGithub = defineCommand({
94
109
  positional: true,
95
110
  required: false,
96
111
  },
112
+ env: {
113
+ type: "string",
114
+ message:
115
+ "only sync these environments (comma-separated, e.g. review,dev) — github allows at most 100 repo secrets",
116
+ positional: true,
117
+ required: false,
118
+ },
97
119
  },
98
120
  execute: async (ctx) => {
99
121
  const config = await getProjectConfig();
@@ -118,7 +140,8 @@ export const commandSecretsSyncGithub = defineCommand({
118
140
  );
119
141
  }
120
142
 
121
- const { secrets, missing } = await collectSecretsFromVault(ctx);
143
+ const envFilter = (await ctx.get("env"))?.split(",").map((e) => e.trim());
144
+ const { secrets, missing } = await collectSecretsFromVault(ctx, envFilter);
122
145
 
123
146
  if (missing.length > 0) {
124
147
  ctx.log(
@@ -0,0 +1,20 @@
1
+ import { exec } from "child-process-promise";
2
+
3
+ /**
4
+ * resolves the numeric gcloud project number for a project id.
5
+ * Requires `cloudresourcemanager.googleapis.com` to be enabled.
6
+ */
7
+ export const fetchGcloudProjectNumber = async (
8
+ projectId: string,
9
+ ): Promise<string> => {
10
+ const result = await exec(
11
+ `gcloud projects describe ${projectId} --format="value(projectNumber)"`,
12
+ );
13
+ const projectNumber = result.stdout.trim();
14
+ if (!/^\d+$/.test(projectNumber)) {
15
+ throw new Error(
16
+ `could not determine the gcloud project number for "${projectId}" (got: "${projectNumber}")`,
17
+ );
18
+ }
19
+ return projectNumber;
20
+ };
@@ -0,0 +1,33 @@
1
+ import { mkdir, writeFile } from "fs/promises";
2
+ import { dirname } from "path";
3
+
4
+ import type { CatladderStore } from "@catladder/pipeline";
5
+ import {
6
+ catladderStoreSchema,
7
+ getCatladderStorePath,
8
+ readCatladderStore,
9
+ } from "@catladder/pipeline";
10
+ import { stringify } from "yaml";
11
+
12
+ import { getGitRoot } from "../utils/projects";
13
+
14
+ const HEADER = `# managed by catladder — written by \`catladder project setup\`.
15
+ # Non-secret, machine-fetched values needed to generate the pipeline.
16
+ # Check this file in. If it is missing, rerun \`catladder project setup\`.
17
+ `;
18
+
19
+ /**
20
+ * applies an update to `.catladder-store/store.yml` at the git root,
21
+ * creating the folder on first use
22
+ */
23
+ export const updateCatladderStore = async (
24
+ update: (store: CatladderStore) => CatladderStore,
25
+ ) => {
26
+ const root = (await getGitRoot()) ?? process.cwd();
27
+ const store = readCatladderStore(root);
28
+ const updated = catladderStoreSchema.parse(update(store));
29
+ const path = getCatladderStorePath(root);
30
+ await mkdir(dirname(path), { recursive: true });
31
+ await writeFile(path, HEADER + stringify(updated));
32
+ return updated;
33
+ };
@@ -34,17 +34,14 @@ export const getGithubRepoFromRemote = async (
34
34
  }
35
35
  };
36
36
 
37
- /**
38
- * sets a github actions repository secret via the gh cli.
39
- * The value is passed via stdin so it never shows up in a process list.
40
- */
41
- export const setGithubSecret = async (
37
+ const ghSetViaStdin = (
38
+ kind: "secret" | "variable",
42
39
  repo: string,
43
40
  name: string,
44
41
  value: string,
45
42
  ): Promise<void> =>
46
43
  new Promise<void>((resolve, reject) => {
47
- const child = spawn("gh", ["secret", "set", name, "--repo", repo], {
44
+ const child = spawn("gh", [kind, "set", name, "--repo", repo], {
48
45
  stdio: ["pipe", "ignore", "pipe"],
49
46
  });
50
47
  let stderr = "";
@@ -53,7 +50,27 @@ export const setGithubSecret = async (
53
50
  child.on("close", (code) =>
54
51
  code === 0
55
52
  ? resolve()
56
- : reject(new Error(`gh secret set ${name} failed: ${stderr.trim()}`)),
53
+ : reject(new Error(`gh ${kind} set ${name} failed: ${stderr.trim()}`)),
57
54
  );
58
55
  child.stdin?.end(value);
59
56
  });
57
+
58
+ /**
59
+ * sets a github actions repository secret via the gh cli.
60
+ * The value is passed via stdin so it never shows up in a process list.
61
+ */
62
+ export const setGithubSecret = async (
63
+ repo: string,
64
+ name: string,
65
+ value: string,
66
+ ): Promise<void> => ghSetViaStdin("secret", repo, name, value);
67
+
68
+ /**
69
+ * sets a github actions repository variable (plain, unmasked) via the
70
+ * gh cli — for vault values classified as not sensitive
71
+ */
72
+ export const setGithubVariable = async (
73
+ repo: string,
74
+ name: string,
75
+ value: string,
76
+ ): Promise<void> => ghSetViaStdin("variable", repo, name, value);
@@ -1,2 +0,0 @@
1
- import type { DeployConfigCloudRun } from "../../../../pipeline/src/index.js";
2
- export declare const getCloudRunDomainSuffix: (config: DeployConfigCloudRun) => Promise<any>;
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getCloudRunDomainSuffix = void 0;
7
- const child_process_promise_1 = require("child-process-promise");
8
- const getSuffixFromService = service => {
9
- const fullUrl = service.status.url;
10
- const name = service.metadata.name;
11
- return fullUrl.replace("https://" + name + "-", "");
12
- };
13
- const getCloudRunDomainSuffix = async config => {
14
- /* google cloud run domains are partially predictable, they have a fixed suffix that depends on the region and project, but we don't know it beforehand
15
- So what we do is either:
16
- - get one service and extract its suffix
17
- - create a dummy project, extract the suffix and save that as a gitlab variable
18
-
19
-
20
- */
21
- const dummyServiceName = "cl-dummy-service-delete-me";
22
- const existingServices = await (0, child_process_promise_1.exec)(`gcloud run services list --format=json --project="${config.projectId}" --region=${config.region} --limit=1`).then(r => JSON.parse(r.stdout));
23
- if (existingServices.length > 0) {
24
- return getSuffixFromService(existingServices[0]);
25
- }
26
- const result = await (0, child_process_promise_1.exec)(`gcloud run deploy ${dummyServiceName} --region=${config.region} --allow-unauthenticated --project ${config.projectId} --image=us-docker.pkg.dev/cloudrun/container/hello --format=json`).then(r => JSON.parse(r.stdout));
27
- return await getSuffixFromService(result);
28
- };
29
- exports.getCloudRunDomainSuffix = getCloudRunDomainSuffix;
@@ -1 +0,0 @@
1
- {"version":3,"file":"getCloudRunDomainSuffix.js","sourceRoot":"","sources":["../../../../../src/gcloud/cloudRun/getCloudRunDomainSuffix.ts"],"names":[],"mappings":";;;AACA,iEAA6C;AAE7C,MAAM,oBAAoB,GAAG,CAAC,OAAY,EAAE,EAAE;IAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC;IACnC,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IAEnC,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,GAAG,IAAI,GAAG,GAAG,EAAE,EAAE,CAAC,CAAC;AACtD,CAAC,CAAC;AACK,MAAM,uBAAuB,GAAG,KAAK,EAAE,MAA4B,EAAE,EAAE;IAC5E;;;;;;;MAOE;IAEF,MAAM,gBAAgB,GAAG,4BAA4B,CAAC;IAEtD,MAAM,gBAAgB,GAAG,MAAM,IAAA,4BAAI,EACjC,sDAAsD,MAAM,CAAC,SAAS,eAAe,MAAM,CAAC,MAAM,YAAY,CAC/G,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAEpC,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,OAAO,oBAAoB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,IAAA,4BAAI,EACvB,qBAAqB,gBAAgB,aAAa,MAAM,CAAC,MAAM,sCAAsC,MAAM,CAAC,SAAS,mEAAmE,CACzL,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAEpC,OAAO,MAAM,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC,CAAC;AAzBW,QAAA,uBAAuB,2BAyBlC"}
@@ -1,35 +0,0 @@
1
- import type { DeployConfigCloudRun } from "@catladder/pipeline";
2
- import { exec } from "child-process-promise";
3
-
4
- const getSuffixFromService = (service: any) => {
5
- const fullUrl = service.status.url;
6
- const name = service.metadata.name;
7
-
8
- return fullUrl.replace("https://" + name + "-", "");
9
- };
10
- export const getCloudRunDomainSuffix = async (config: DeployConfigCloudRun) => {
11
- /* google cloud run domains are partially predictable, they have a fixed suffix that depends on the region and project, but we don't know it beforehand
12
-
13
- So what we do is either:
14
- - get one service and extract its suffix
15
- - create a dummy project, extract the suffix and save that as a gitlab variable
16
-
17
-
18
- */
19
-
20
- const dummyServiceName = "cl-dummy-service-delete-me";
21
-
22
- const existingServices = await exec(
23
- `gcloud run services list --format=json --project="${config.projectId}" --region=${config.region} --limit=1`,
24
- ).then((r) => JSON.parse(r.stdout));
25
-
26
- if (existingServices.length > 0) {
27
- return getSuffixFromService(existingServices[0]);
28
- }
29
-
30
- const result = await exec(
31
- `gcloud run deploy ${dummyServiceName} --region=${config.region} --allow-unauthenticated --project ${config.projectId} --image=us-docker.pkg.dev/cloudrun/container/hello --format=json`,
32
- ).then((r) => JSON.parse(r.stdout));
33
-
34
- return await getSuffixFromService(result);
35
- };