@vaharoni/devops 1.1.8 → 1.1.10

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.
@@ -2,7 +2,7 @@ import { CLICommandParser, printUsageAndExit, StrongParams } from "./common";
2
2
  import { buildDev, deploy } from "../libs/cloudrun-helpers";
3
3
  const oneLiner = "Supports cloudrun images";
4
4
  const keyExamples = `
5
- $ devops cloudrun deploy cloudrun-image SHA --env staging --region us-central1 [--forward-env ENV1,ENV2 --allow-unauthenticated]
5
+ $ devops cloudrun deploy cloudrun-image SHA --env staging --region us-east1 [--forward-env ENV1,ENV2 --allow-unauthenticated]
6
6
  $ devops cloudrun build-dev cloudrun-image
7
7
  `.trim();
8
8
  const usage = `
@@ -1 +1 @@
1
- {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/cli/image.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAmC,MAAM,sBAAsB,CAAC;AAiKzF,iBAAS,GAAG,CAAC,MAAM,EAAE,gBAAgB,QA8BpC;;;;;;;;AAED,wBAEE"}
1
+ {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/cli/image.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAmC,MAAM,sBAAsB,CAAC;AA6KzF,iBAAS,GAAG,CAAC,MAAM,EAAE,gBAAgB,QAgCpC;;;;;;;;AAED,wBAEE"}
package/dist/cli/image.js CHANGED
@@ -2,8 +2,10 @@ import { deleteImageVersion, getImageVersion, getWorkspaceScale, resetWorkspaceS
2
2
  import { CLICommandParser, printUsageAndExit, StrongParams } from "../../src/cli/common";
3
3
  import { generateImageDeployments } from "../libs/k8s-generate";
4
4
  import { applyHandler } from "../libs/k8s-helpers";
5
+ import { getImageType } from "../libs/config";
5
6
  const oneLiner = "Applies image-related manifests, retrieves or set the version deployed, and scales deployments of applications";
6
7
  const keyExamples = `
8
+ $ devops image get type main-node
7
9
  $ devops image deployment gen main-node sha --env staging
8
10
  $ devops image deployment create main-node sha --env staging
9
11
  $ devops image deployment delete main-node --env staging
@@ -19,6 +21,11 @@ const keyExamples = `
19
21
  const usage = `
20
22
  ${oneLiner}
21
23
 
24
+ GET IMAGE TYPE
25
+ devops image get type <image-name>
26
+
27
+ Returns "k8s" or "cloudrun" depending on the image type.
28
+
22
29
  GENERATING DEPLOYMENT MANIFESTS
23
30
  devops image deployment gen|create|delete <image-name> <sha>
24
31
 
@@ -46,6 +53,11 @@ EXAMPLES
46
53
  ${keyExamples}
47
54
  `;
48
55
  const handlers = {
56
+ get: {
57
+ type: (opts) => {
58
+ console.log(getImageType(opts.required("image")));
59
+ },
60
+ },
49
61
  deployment: {
50
62
  gen: (opts) => {
51
63
  console.log(generateImageDeployments(opts.required("env"), opts.required("image"), opts.required("sha")));
@@ -120,7 +132,10 @@ function run(cmdObj) {
120
132
  printUsageAndExit(usage);
121
133
  }
122
134
  function getExtraParams() {
123
- if (command === 'scale') {
135
+ if (command === 'get') {
136
+ return {};
137
+ }
138
+ else if (command === 'scale') {
124
139
  return subcommand === 'set' ? { workspace: param1, replicas: param2 } : { workspace: param1 };
125
140
  }
126
141
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/cli/registry.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAmC,MAAM,UAAU,CAAC;AA6D7E,iBAAS,GAAG,CAAC,MAAM,EAAE,gBAAgB,QAYpC;;;;;;;;AAED,wBAEE"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/cli/registry.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAmC,MAAM,UAAU,CAAC;AA8D7E,iBAAS,GAAG,CAAC,MAAM,EAAE,gBAAgB,QAYpC;;;;;;;;AAED,wBAEE"}
@@ -45,8 +45,9 @@ const handlers = {
45
45
  },
46
46
  prune: (opts) => {
47
47
  const regName = containerRegistryPath();
48
- const repoName = containerRegistryImageName(opts.required("image"), opts.required("env"));
49
- prune(regName, repoName);
48
+ const image = opts.required("image");
49
+ const repoName = containerRegistryImageName(image, opts.required("env"));
50
+ prune(regName, repoName, image);
50
51
  },
51
52
  };
52
53
  function run(cmdObj) {
@@ -3,4 +3,5 @@ export declare const getConst: <T extends keyof ConstFileSchema>(key: T, opts?:
3
3
  ignoreIfInvalid?: boolean;
4
4
  }) => ConstFileSchema[T] | undefined;
5
5
  export declare const getImageData: (imageName: string) => SingleImageSchema, getImageNames: () => string[], getTemplateData: (templateName: string) => SingleTemplateSchema;
6
+ export declare function getImageType(image: string): "cloudrun" | "k8s";
6
7
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/libs/config.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoC,KAAK,eAAe,EAAwB,KAAK,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAM3J,eAAO,MAAQ,QAAQ,GA2BH,CAAC,SAAS,MAAM,eAAe,OAAO,CAAC,SAAQ;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,KAAQ,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,AA3BxF,CAAC;AAC/C,eAAO,MAAQ,YAAY,cAkEQ,MAAM,KAAG,iBAAiB,EAlEhC,aAAa,kBAAE,eAAe,iBAwFlB,MAAM,KAAG,oBAAoB,AAxFa,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/libs/config.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoC,KAAK,eAAe,EAAwB,KAAK,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAM3J,eAAO,MAAQ,QAAQ,GAgCH,CAAC,SAAS,MAAM,eAAe,OAAO,CAAC,SAAQ;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,KAAQ,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,AAhCxF,CAAC;AAC/C,eAAO,MAAQ,YAAY,cAuEQ,MAAM,KAAG,iBAAiB,EAvEhC,aAAa,kBAAE,eAAe,iBA6FlB,MAAM,KAAG,oBAAoB,AA7Fa,CAAC;AAEpF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,sBAGzC"}
@@ -8,6 +8,10 @@ const imagesFilePath = path.join(process.cwd(), ".devops/config/images.yaml");
8
8
  // We want these to be lazy loaded so that calling devops in a context that does not need the config files won't fail
9
9
  export const { getConst } = processConstFile();
10
10
  export const { getImageData, getImageNames, getTemplateData } = processImagesFile();
11
+ export function getImageType(image) {
12
+ const imageData = getImageData(image);
13
+ return imageData["cloudrun"] ? "cloudrun" : "k8s";
14
+ }
11
15
  // Process config/constants.yaml
12
16
  function processConstFile() {
13
17
  let constants;
@@ -2,5 +2,5 @@ export declare function prune(
2
2
  /** To keep the image-related constants simple, this accepts the full URL including the prefix registry.digitalocean.com */
3
3
  registryFullName: string,
4
4
  /** The name of the repository inside the registry */
5
- repoName: string): void;
5
+ repoName: string, image: string): void;
6
6
  //# sourceMappingURL=container-reg.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"container-reg.d.ts","sourceRoot":"","sources":["../../../src/libs/digital-ocean/container-reg.ts"],"names":[],"mappings":"AA0DA,wBAAgB,KAAK;AACnB,2HAA2H;AAC3H,gBAAgB,EAAE,MAAM;AACxB,qDAAqD;AACrD,QAAQ,EAAE,MAAM,QAkBjB"}
1
+ {"version":3,"file":"container-reg.d.ts","sourceRoot":"","sources":["../../../src/libs/digital-ocean/container-reg.ts"],"names":[],"mappings":"AA0DA,wBAAgB,KAAK;AACnB,2HAA2H;AAC3H,gBAAgB,EAAE,MAAM;AACxB,qDAAqD;AACrD,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,QAyBd"}
@@ -1,6 +1,6 @@
1
1
  import { CommandExecutor } from "../../cli/common";
2
2
  import { z } from "zod";
3
- import { getConst } from "../config";
3
+ import { getConst, getImageData } from "../config";
4
4
  const repoTagMetadataSchema = z.object({
5
5
  // What we rely on
6
6
  tag: z.string().optional(),
@@ -50,12 +50,17 @@ export function prune(
50
50
  /** To keep the image-related constants simple, this accepts the full URL including the prefix registry.digitalocean.com */
51
51
  registryFullName,
52
52
  /** The name of the repository inside the registry */
53
- repoName) {
53
+ repoName, image) {
54
54
  const infra = getConst("infra");
55
55
  if (infra !== "digitalocean") {
56
56
  console.warn("Pruning is only supported for the DigitalOcean container registry");
57
57
  return;
58
58
  }
59
+ const imageData = getImageData(image);
60
+ if (imageData["cloudrun"]) {
61
+ console.warn("Pruning is skipped for cloudrun images");
62
+ return;
63
+ }
59
64
  const tags = getRepoTagMetadata(repoName);
60
65
  const versionsToKeep = Number(getConst("image-versions-to-keep"));
61
66
  if (!tags.length || tags.length <= versionsToKeep)
@@ -1 +1 @@
1
- {"version":3,"file":"k8s-generate.d.ts","sourceRoot":"","sources":["../../src/libs/k8s-generate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAqB3I,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,UAaf;AAED,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAMvH;AAED,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,sBAQf;AAED,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,UAMf;AA6FD,qBAAa,qBAAqB;IAIb,WAAW,EAAE,MAAM;IAAS,KAAK,EAAE,MAAM;IAAS,MAAM,EAAE,MAAM;IAHnF,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,YAAY,EAAE,IAAI,CAAC,qBAAqB,EAAE,cAAc,CAAC,CAAC;gBAEvC,WAAW,EAAE,MAAM,EAAS,KAAK,EAAE,MAAM,EAAS,MAAM,EAAE,MAAM;IAYnF,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,wBAAwB;IAmB7D,YAAY,IAAI,uBAAuB;IAOvC,QAAQ,IAAI,mBAAmB;CAMhC"}
1
+ {"version":3,"file":"k8s-generate.d.ts","sourceRoot":"","sources":["../../src/libs/k8s-generate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA6B3I,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,UAcf;AAED,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAOvH;AAED,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,sBASf;AAED,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,UAOf;AA6FD,qBAAa,qBAAqB;IAIb,WAAW,EAAE,MAAM;IAAS,KAAK,EAAE,MAAM;IAAS,MAAM,EAAE,MAAM;IAHnF,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,YAAY,EAAE,IAAI,CAAC,qBAAqB,EAAE,cAAc,CAAC,CAAC;gBAEvC,WAAW,EAAE,MAAM,EAAS,KAAK,EAAE,MAAM,EAAS,MAAM,EAAE,MAAM;IAYnF,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,wBAAwB;IAmB7D,YAAY,IAAI,uBAAuB;IAOvC,QAAQ,IAAI,mBAAmB;CAMhC"}
@@ -12,8 +12,16 @@ import { getImageDescendentData } from "./discovery/images";
12
12
  const MANIFEST_FOLDER_PATH = path.join(process.cwd(), '.devops/manifests');
13
13
  const MANIFEST_INDEX_FILE_PATH = path.join(MANIFEST_FOLDER_PATH, '_index.yaml');
14
14
  const DB_MIGRATE_TEMPLATE_NAME = 'db-migrate';
15
+ function verifyNotCloudrunImage(image) {
16
+ const imageData = getImageData(image);
17
+ if (imageData["cloudrun"]) {
18
+ console.error(`Image ${image} is a cloudrun image. Cloudrun images are not supported for k8s generation`);
19
+ process.exit(1);
20
+ }
21
+ }
15
22
  // = Interface
16
23
  export function generateImageDeployments(monorepoEnv, image, gitSha) {
24
+ verifyNotCloudrunImage(image);
17
25
  const generator = new ImageContextGenerator(monorepoEnv, image, gitSha);
18
26
  const apps = getImageDescendentData(image)
19
27
  .filter((packageData) => packageData.deployment)
@@ -27,6 +35,7 @@ export function generateImageDeployments(monorepoEnv, image, gitSha) {
27
35
  return ensureProperDomainsPresent(manifest, monorepoEnv, image);
28
36
  }
29
37
  export function generateWorkspaceDeployment(packageData, monorepoEnv, image, gitSha) {
38
+ verifyNotCloudrunImage(image);
30
39
  const generator = new ImageContextGenerator(monorepoEnv, image, gitSha);
31
40
  const context = generator.getDeployment(packageData);
32
41
  const renderFn = (template) => Handlebars.compile(template)(context);
@@ -34,6 +43,7 @@ export function generateWorkspaceDeployment(packageData, monorepoEnv, image, git
34
43
  return ensureProperDomainsPresent(manifest, monorepoEnv, image);
35
44
  }
36
45
  export function generateDebugDeployment(monorepoEnv, image, gitSha) {
46
+ verifyNotCloudrunImage(image);
37
47
  const generator = new ImageContextGenerator(monorepoEnv, image, gitSha);
38
48
  const context = generator.getDebug();
39
49
  const renderFn = (template) => Handlebars.compile(template)(context);
@@ -43,6 +53,7 @@ export function generateDebugDeployment(monorepoEnv, image, gitSha) {
43
53
  return generateManifestsFromTemplateName(debugTemplate, renderFn).map(x => yaml.stringify(x)).join("\n---\n");
44
54
  }
45
55
  export function generateDbMigrateJob(monorepoEnv, image, gitSha) {
56
+ verifyNotCloudrunImage(image);
46
57
  const generator = new ImageContextGenerator(monorepoEnv, image, gitSha);
47
58
  const context = generator.getDbMigrate();
48
59
  const renderFn = (template) => Handlebars.compile(template)(context);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vaharoni/devops",
3
3
  "type": "module",
4
- "version": "1.1.8",
4
+ "version": "1.1.10",
5
5
  "description": "Devops utility",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -4,7 +4,7 @@ import { buildDev, deploy } from "../libs/cloudrun-helpers";
4
4
  const oneLiner =
5
5
  "Supports cloudrun images";
6
6
  const keyExamples = `
7
- $ devops cloudrun deploy cloudrun-image SHA --env staging --region us-central1 [--forward-env ENV1,ENV2 --allow-unauthenticated]
7
+ $ devops cloudrun deploy cloudrun-image SHA --env staging --region us-east1 [--forward-env ENV1,ENV2 --allow-unauthenticated]
8
8
  $ devops cloudrun build-dev cloudrun-image
9
9
  `.trim();
10
10
 
package/src/cli/image.ts CHANGED
@@ -2,9 +2,11 @@ import { deleteImageVersion, getImageVersion, getWorkspaceScale, resetWorkspaceS
2
2
  import { CLICommandParser, printUsageAndExit, StrongParams } from "../../src/cli/common";
3
3
  import { generateImageDeployments } from "../libs/k8s-generate";
4
4
  import { applyHandler } from "../libs/k8s-helpers";
5
+ import { getImageType } from "../libs/config";
5
6
 
6
7
  const oneLiner = "Applies image-related manifests, retrieves or set the version deployed, and scales deployments of applications";
7
8
  const keyExamples = `
9
+ $ devops image get type main-node
8
10
  $ devops image deployment gen main-node sha --env staging
9
11
  $ devops image deployment create main-node sha --env staging
10
12
  $ devops image deployment delete main-node --env staging
@@ -21,6 +23,11 @@ const keyExamples = `
21
23
  const usage = `
22
24
  ${oneLiner}
23
25
 
26
+ GET IMAGE TYPE
27
+ devops image get type <image-name>
28
+
29
+ Returns "k8s" or "cloudrun" depending on the image type.
30
+
24
31
  GENERATING DEPLOYMENT MANIFESTS
25
32
  devops image deployment gen|create|delete <image-name> <sha>
26
33
 
@@ -49,6 +56,11 @@ EXAMPLES
49
56
  `;
50
57
 
51
58
  const handlers = {
59
+ get: {
60
+ type: (opts: StrongParams) => {
61
+ console.log(getImageType(opts.required("image")));
62
+ },
63
+ },
52
64
  deployment: {
53
65
  gen: (opts: StrongParams) => {
54
66
  console.log(
@@ -176,7 +188,9 @@ function run(cmdObj: CLICommandParser) {
176
188
  }
177
189
 
178
190
  function getExtraParams() {
179
- if (command === 'scale') {
191
+ if (command === 'get') {
192
+ return {};
193
+ } else if (command === 'scale') {
180
194
  return subcommand === 'set' ? { workspace: param1, replicas: param2 } : { workspace: param1 };
181
195
  } else {
182
196
  return { sha: param1 };
@@ -58,11 +58,12 @@ const handlers = {
58
58
  },
59
59
  prune: (opts: StrongParams) => {
60
60
  const regName = containerRegistryPath();
61
+ const image = opts.required("image");
61
62
  const repoName = containerRegistryImageName(
62
- opts.required("image"),
63
+ image,
63
64
  opts.required("env")
64
65
  );
65
- prune(regName, repoName);
66
+ prune(regName, repoName, image);
66
67
  },
67
68
  };
68
69
 
@@ -11,6 +11,11 @@ const imagesFilePath = path.join(process.cwd(), ".devops/config/images.yaml");
11
11
  export const { getConst } = processConstFile();
12
12
  export const { getImageData, getImageNames, getTemplateData } = processImagesFile();
13
13
 
14
+ export function getImageType(image: string) {
15
+ const imageData = getImageData(image);
16
+ return imageData["cloudrun"] ? "cloudrun" : "k8s";
17
+ }
18
+
14
19
  // Process config/constants.yaml
15
20
 
16
21
  function processConstFile() {
@@ -1,6 +1,6 @@
1
1
  import { CommandExecutor } from "../../cli/common";
2
2
  import { z } from "zod";
3
- import { getConst } from "../config";
3
+ import { getConst, getImageData } from "../config";
4
4
 
5
5
  const repoTagMetadataSchema = z.object({
6
6
  // What we rely on
@@ -60,7 +60,8 @@ export function prune(
60
60
  /** To keep the image-related constants simple, this accepts the full URL including the prefix registry.digitalocean.com */
61
61
  registryFullName: string,
62
62
  /** The name of the repository inside the registry */
63
- repoName: string
63
+ repoName: string,
64
+ image: string
64
65
  ) {
65
66
  const infra = getConst("infra");
66
67
  if (infra !== "digitalocean") {
@@ -69,6 +70,13 @@ export function prune(
69
70
  );
70
71
  return;
71
72
  }
73
+ const imageData = getImageData(image);
74
+ if (imageData["cloudrun"]) {
75
+ console.warn(
76
+ "Pruning is skipped for cloudrun images"
77
+ );
78
+ return;
79
+ }
72
80
  const tags = getRepoTagMetadata(repoName);
73
81
  const versionsToKeep = Number(getConst("image-versions-to-keep"));
74
82
  if (!tags.length || tags.length <= versionsToKeep) return;
@@ -17,6 +17,14 @@ const DB_MIGRATE_TEMPLATE_NAME = 'db-migrate';
17
17
 
18
18
  type RenderFn = (template: string) => string;
19
19
 
20
+ function verifyNotCloudrunImage(image: string) {
21
+ const imageData = getImageData(image);
22
+ if (imageData["cloudrun"]) {
23
+ console.error(`Image ${image} is a cloudrun image. Cloudrun images are not supported for k8s generation`);
24
+ process.exit(1);
25
+ }
26
+ }
27
+
20
28
  // = Interface
21
29
 
22
30
  export function generateImageDeployments(
@@ -24,6 +32,7 @@ export function generateImageDeployments(
24
32
  image: string,
25
33
  gitSha: string
26
34
  ) {
35
+ verifyNotCloudrunImage(image);
27
36
  const generator = new ImageContextGenerator(monorepoEnv, image, gitSha);
28
37
  const apps = getImageDescendentData(image)
29
38
  .filter((packageData) => packageData.deployment)
@@ -38,6 +47,7 @@ export function generateImageDeployments(
38
47
  }
39
48
 
40
49
  export function generateWorkspaceDeployment(packageData: PackageData, monorepoEnv: string, image: string, gitSha: string) {
50
+ verifyNotCloudrunImage(image);
41
51
  const generator = new ImageContextGenerator(monorepoEnv, image, gitSha);
42
52
  const context = generator.getDeployment(packageData);
43
53
  const renderFn = (template: string) => Handlebars.compile(template)(context);
@@ -50,6 +60,7 @@ export function generateDebugDeployment(
50
60
  image: string,
51
61
  gitSha: string
52
62
  ) {
63
+ verifyNotCloudrunImage(image);
53
64
  const generator = new ImageContextGenerator(monorepoEnv, image, gitSha);
54
65
  const context = generator.getDebug();
55
66
  const renderFn = (template: string) => Handlebars.compile(template)(context);
@@ -63,6 +74,7 @@ export function generateDbMigrateJob(
63
74
  image: string,
64
75
  gitSha: string
65
76
  ) {
77
+ verifyNotCloudrunImage(image);
66
78
  const generator = new ImageContextGenerator(monorepoEnv, image, gitSha);
67
79
  const context = generator.getDbMigrate();
68
80
  const renderFn = (template: string) => Handlebars.compile(template)(context);
@@ -9,6 +9,8 @@ on:
9
9
  permissions:
10
10
  contents: read
11
11
  packages: read
12
+ # For deploying images to Cloud Run
13
+ # id-token: write
12
14
 
13
15
  jobs:
14
16
  build_images:
@@ -35,6 +37,14 @@ jobs:
35
37
  access_token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
36
38
  cluster_name: ${{ secrets.DIGITALOCEAN_CLUSTER_NAME }}
37
39
 
40
+ # For deploying images to Cloud Run
41
+ # - name: Connect to Cloud Run
42
+ # uses: ./.github/actions/connect-to-cloud-run@v1
43
+ # with:
44
+ # project_id: ${{ vars.GCP_PROJECT_ID }}
45
+ # project_number: ${{ vars.GCP_PROJECT_NUMBER }}
46
+ # region: ${{ vars.GCP_ARTIFACT_REGISTRY_REGION }}
47
+
38
48
  - name: Build image
39
49
  uses: ./.github/actions/build-image@v1
40
50
  with:
@@ -59,15 +69,23 @@ jobs:
59
69
  with:
60
70
  access_token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
61
71
  cluster_name: ${{ secrets.DIGITALOCEAN_CLUSTER_NAME }}
62
-
72
+
73
+ # For deploying images to Cloud Run
74
+ # - name: Connect to Cloud Run
75
+ # uses: ./.github/actions/connect-to-cloud-run@v1
76
+ # with:
77
+ # project_id: ${{ vars.GCP_PROJECT_ID }}
78
+ # project_number: ${{ vars.GCP_PROJECT_NUMBER }}
79
+ # region: ${{ vars.GCP_ARTIFACT_REGISTRY_REGION }}
80
+
63
81
  - name: Run DB Migrate
64
82
  uses: ./.github/actions/db-migrate@v1
65
83
 
66
84
  # Repeat per image (it checks if the image is affected and deploys it if it is)
67
85
  - name: Deploy main node
68
- uses: ./.github/actions/deploy-image@v1
86
+ uses: ./.github/actions/deploy-image-k8s@v1
69
87
  with: { "image_name": "main-node" }
70
88
 
71
89
  - name: Deploy main python
72
- uses: ./.github/actions/deploy-image@v1
90
+ uses: ./.github/actions/deploy-image-k8s@v1
73
91
  with: { "image_name": "main-python" }
@@ -9,6 +9,8 @@ on:
9
9
  permissions:
10
10
  contents: read
11
11
  packages: read
12
+ # For deploying images to Cloud Run
13
+ # id-token: write
12
14
 
13
15
  jobs:
14
16
  build_images:
@@ -35,7 +37,15 @@ jobs:
35
37
  project_id: ${{ secrets.GCLOUD_PROJECT_ID }}
36
38
  zone: ${{ secrets.GCLOUD_ZONE }}
37
39
  cluster_name: ${{ secrets.GCLOUD_CLUSTER_NAME }}
38
- service_account_key: ${{ secrets.GCLOUD_SA_KEY }}
40
+ service_account_key: ${{ secrets.GCLOUD_SA_KEY }}
41
+
42
+ # For deploying images to Cloud Run
43
+ # - name: Connect to Cloud Run
44
+ # uses: ./.github/actions/connect-to-cloud-run@v1
45
+ # with:
46
+ # project_id: ${{ vars.GCP_PROJECT_ID }}
47
+ # project_number: ${{ vars.GCP_PROJECT_NUMBER }}
48
+ # region: ${{ vars.GCP_ARTIFACT_REGISTRY_REGION }}
39
49
 
40
50
  - name: Build image
41
51
  uses: ./.github/actions/build-image@v1
@@ -64,14 +74,22 @@ jobs:
64
74
  cluster_name: ${{ secrets.GCLOUD_CLUSTER_NAME }}
65
75
  service_account_key: ${{ secrets.GCLOUD_SA_KEY }}
66
76
 
77
+ # For deploying images to Cloud Run
78
+ # - name: Connect to Cloud Run
79
+ # uses: ./.github/actions/connect-to-cloud-run@v1
80
+ # with:
81
+ # project_id: ${{ vars.GCP_PROJECT_ID }}
82
+ # project_number: ${{ vars.GCP_PROJECT_NUMBER }}
83
+ # region: ${{ vars.GCP_ARTIFACT_REGISTRY_REGION }}
84
+
67
85
  - name: Run DB Migrate
68
86
  uses: ./.github/actions/db-migrate@v1
69
87
 
70
88
  # Repeat per image (it checks if the image is affected and deploys it if it is)
71
89
  - name: Deploy main node
72
- uses: ./.github/actions/deploy-image@v1
90
+ uses: ./.github/actions/deploy-image-k8s@v1
73
91
  with: { "image_name": "main-node" }
74
92
 
75
93
  - name: Deploy main python
76
- uses: ./.github/actions/deploy-image@v1
94
+ uses: ./.github/actions/deploy-image-k8s@v1
77
95
  with: { "image_name": "main-python" }
@@ -9,6 +9,8 @@ on:
9
9
  permissions:
10
10
  contents: read
11
11
  packages: read
12
+ # For deploying images to Cloud Run
13
+ # id-token: write
12
14
 
13
15
  jobs:
14
16
  build_images:
@@ -34,7 +36,15 @@ jobs:
34
36
  with:
35
37
  kubeconfig: ${{ secrets.HCLOUD_KUBECONFIG }}
36
38
  harbor_user: ${{ secrets.HARBOR_USER }}
37
- harbor_password: ${{ secrets.HARBOR_PASSWORD }}
39
+ harbor_password: ${{ secrets.HARBOR_PASSWORD }}
40
+
41
+ # For deploying images to Cloud Run
42
+ # - name: Connect to Cloud Run
43
+ # uses: ./.github/actions/connect-to-cloud-run@v1
44
+ # with:
45
+ # project_id: ${{ vars.GCP_PROJECT_ID }}
46
+ # project_number: ${{ vars.GCP_PROJECT_NUMBER }}
47
+ # region: ${{ vars.GCP_ARTIFACT_REGISTRY_REGION }}
38
48
 
39
49
  - name: Build image
40
50
  uses: ./.github/actions/build-image@v1
@@ -60,16 +70,24 @@ jobs:
60
70
  with:
61
71
  kubeconfig: ${{ secrets.HCLOUD_KUBECONFIG }}
62
72
  harbor_user: ${{ secrets.HARBOR_USER }}
63
- harbor_password: ${{ secrets.HARBOR_PASSWORD }}
73
+ harbor_password: ${{ secrets.HARBOR_PASSWORD }}
74
+
75
+ # For deploying images to Cloud Run
76
+ # - name: Connect to Cloud Run
77
+ # uses: ./.github/actions/connect-to-cloud-run@v1
78
+ # with:
79
+ # project_id: ${{ vars.GCP_PROJECT_ID }}
80
+ # project_number: ${{ vars.GCP_PROJECT_NUMBER }}
81
+ # region: ${{ vars.GCP_ARTIFACT_REGISTRY_REGION }}
64
82
 
65
83
  - name: Run DB Migrate
66
84
  uses: ./.github/actions/db-migrate@v1
67
85
 
68
86
  # Repeat per image (it checks if the image is affected and deploys it if it is)
69
87
  - name: Deploy main node
70
- uses: ./.github/actions/deploy-image@v1
88
+ uses: ./.github/actions/deploy-image-k8s@v1
71
89
  with: { "image_name": "main-node" }
72
90
 
73
91
  - name: Deploy main python
74
- uses: ./.github/actions/deploy-image@v1
92
+ uses: ./.github/actions/deploy-image-k8s@v1
75
93
  with: { "image_name": "main-python" }
@@ -0,0 +1,71 @@
1
+ name: "Deploy image"
2
+ description: "Deploy the specified image if it's affected and set its version"
3
+ inputs:
4
+ project_id:
5
+ description: 'The GCP project ID of the Cloud Run service'
6
+ required: true
7
+ image_name:
8
+ description: 'The image key in images.yaml'
9
+ required: true
10
+ region:
11
+ description: 'The region of the Cloud Run service'
12
+ required: true
13
+ sa_id:
14
+ description: 'The name of the service account used to run the Cloud Run service'
15
+ required: true
16
+ forward_env:
17
+ description: 'The environment variables to forward to the Cloud Run service (comma separated, e.g. ENV1,ENV2)'
18
+ required: false
19
+ allow_unauthenticated:
20
+ description: 'Whether to allow unauthenticated access to the Cloud Run service. Send "true" to allow unauthenticated access.'
21
+ required: false
22
+ outputs:
23
+ affected:
24
+ description: 'Whether the specified image is affected (computed before deploy)'
25
+ value: ${{ steps.check_affected.outputs.affected }}
26
+ runs:
27
+ using: "composite"
28
+ steps:
29
+ - name: Setup basic vars
30
+ shell: bash
31
+ run: |
32
+ echo "IMAGE_NAME=${{ inputs.image_name }}" >> $GITHUB_ENV
33
+
34
+ - name: Check if affected
35
+ id: check_affected
36
+ shell: bash
37
+ run: |
38
+ AFFECTED=$(devops affected image $IMAGE_NAME --from-live-version)
39
+ echo "affected=$AFFECTED" >> $GITHUB_OUTPUT
40
+ echo "affected=$AFFECTED"
41
+ if [[ "$AFFECTED" == "true" ]]; then
42
+ echo "${{ env.IMAGE_NAME }} is affected. Proceeding with deployment."
43
+ else
44
+ echo "${{ env.IMAGE_NAME }} is not affected. Skipping."
45
+ fi
46
+
47
+ - name: Deploy
48
+ shell: bash
49
+ if: steps.check_affected.outputs.affected == 'true'
50
+ run: |
51
+ RUNTIME_SA="${{ inputs.sa_id }}@${{ inputs.project_id }}.iam.gserviceaccount.com"
52
+
53
+ if [[ -z "${{ inputs.forward_env }}" ]]; then
54
+ FORWARD_ENV=""
55
+ else
56
+ FORWARD_ENV="--forward-env ${{ inputs.forward_env }}"
57
+ fi
58
+
59
+ if [[ "${{ inputs.allow_unauthenticated }}" == "true" ]]; then
60
+ ALLOW_UNAUTHENTICATED="--allow-unauthenticated"
61
+ else
62
+ ALLOW_UNAUTHENTICATED="--no-allow-unauthenticated"
63
+ fi
64
+
65
+ devops cloudrun deploy ${{ env.IMAGE_NAME }} ${{ github.sha }} \
66
+ --region ${{ inputs.region }} \
67
+ --service-account ${RUNTIME_SA} \
68
+ ${FORWARD_ENV} \
69
+ ${ALLOW_UNAUTHENTICATED}
70
+
71
+ devops image version set ${{ env.IMAGE_NAME }} ${{ github.sha }}