@vaharoni/devops 1.1.8 → 1.1.9

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.
@@ -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.9",
5
5
  "description": "Devops utility",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
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);