@vaharoni/devops 1.1.7 → 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.
- package/README.md +5 -1
- package/dist/cli/cloudrun.d.ts +11 -0
- package/dist/cli/cloudrun.d.ts.map +1 -0
- package/dist/cli/cloudrun.js +121 -0
- package/dist/cli/common.d.ts +10 -12
- package/dist/cli/common.d.ts.map +1 -1
- package/dist/cli/common.js +28 -22
- package/dist/cli/env.js +2 -2
- package/dist/cli/image.d.ts.map +1 -1
- package/dist/cli/image.js +16 -1
- package/dist/cli/prep-build.d.ts.map +1 -1
- package/dist/cli/prep-build.js +35 -6
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/cli/registry.js +15 -5
- package/dist/devops.js +3 -1
- package/dist/libs/cloudrun-helpers.d.ts +16 -0
- package/dist/libs/cloudrun-helpers.d.ts.map +1 -0
- package/dist/libs/cloudrun-helpers.js +79 -0
- package/dist/libs/config.d.ts +1 -0
- package/dist/libs/config.d.ts.map +1 -1
- package/dist/libs/config.js +4 -0
- package/dist/libs/digital-ocean/container-reg.d.ts +1 -1
- package/dist/libs/digital-ocean/container-reg.d.ts.map +1 -1
- package/dist/libs/digital-ocean/container-reg.js +7 -2
- package/dist/libs/k8s-constants.d.ts +1 -0
- package/dist/libs/k8s-constants.d.ts.map +1 -1
- package/dist/libs/k8s-constants.js +35 -10
- package/dist/libs/k8s-generate.d.ts +1 -1
- package/dist/libs/k8s-generate.d.ts.map +1 -1
- package/dist/libs/k8s-generate.js +15 -2
- package/dist/libs/k8s-secrets-manager.d.ts +2 -1
- package/dist/libs/k8s-secrets-manager.d.ts.map +1 -1
- package/dist/libs/k8s-secrets-manager.js +8 -5
- package/dist/types/index.d.ts +19 -8
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -1
- package/package.json +1 -1
- package/src/cli/cloudrun.ts +133 -0
- package/src/cli/common.ts +46 -38
- package/src/cli/db.ts +1 -1
- package/src/cli/dml.ts +1 -1
- package/src/cli/env.ts +2 -2
- package/src/cli/exec.ts +1 -1
- package/src/cli/image.ts +15 -1
- package/src/cli/job.ts +1 -1
- package/src/cli/prep-build.ts +34 -6
- package/src/cli/redis.ts +1 -1
- package/src/cli/registry.ts +15 -5
- package/src/devops.ts +3 -1
- package/src/libs/cloudrun-helpers.ts +118 -0
- package/src/libs/config.ts +5 -0
- package/src/libs/digital-ocean/container-reg.ts +10 -2
- package/src/libs/k8s-constants.ts +36 -12
- package/src/libs/k8s-generate.ts +15 -2
- package/src/libs/k8s-secrets-manager.ts +9 -5
- package/src/target-templates/lang-variants-common/python/.devops/config/images.yaml +3 -1
- package/src/target-templates/lang-variants-common/typescript/.devops/docker-images/cloudrun.Dockerfile +31 -0
- package/src/target-templates/lang-variants-common/typescript/.github/actions/deploy-image@v1/action.yaml +4 -0
- package/src/types/index.ts +3 -1
package/src/libs/k8s-generate.ts
CHANGED
@@ -6,7 +6,7 @@ import path from "path";
|
|
6
6
|
import yaml from "yaml";
|
7
7
|
import fs from 'fs';
|
8
8
|
import { globSync } from "glob";
|
9
|
-
import _
|
9
|
+
import _ from 'lodash';
|
10
10
|
import Handlebars from "handlebars";
|
11
11
|
import { getImageData } from "./config";
|
12
12
|
import { getImageDescendentData } from "./discovery/images";
|
@@ -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)
|
@@ -33,11 +42,12 @@ export function generateImageDeployments(
|
|
33
42
|
return generateManifestForDeployment(projectData.rootPath, projectData.deployment!.template, renderFn);
|
34
43
|
});
|
35
44
|
const debug = generateDebugDeployment(monorepoEnv, image, gitSha);
|
36
|
-
const manifest = [debug, ...apps].join("\n---\n");
|
45
|
+
const manifest = [debug, ...apps].filter(Boolean).join("\n---\n");
|
37
46
|
return ensureProperDomainsPresent(manifest, monorepoEnv, image);
|
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,10 +60,12 @@ 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);
|
56
67
|
const debugTemplate = getImageData(image)["debug-template"];
|
68
|
+
if (!debugTemplate) return;
|
57
69
|
return generateManifestsFromTemplateName(debugTemplate, renderFn).map(x => yaml.stringify(x)).join("\n---\n");
|
58
70
|
}
|
59
71
|
|
@@ -62,6 +74,7 @@ export function generateDbMigrateJob(
|
|
62
74
|
image: string,
|
63
75
|
gitSha: string
|
64
76
|
) {
|
77
|
+
verifyNotCloudrunImage(image);
|
65
78
|
const generator = new ImageContextGenerator(monorepoEnv, image, gitSha);
|
66
79
|
const context = generator.getDbMigrate();
|
67
80
|
const renderFn = (template: string) => Handlebars.compile(template)(context);
|
@@ -16,7 +16,7 @@ function execUpdateSecret(
|
|
16
16
|
new CommandExecutor(fullCommand, { quiet: true, redactedCommand }).exec();
|
17
17
|
}
|
18
18
|
|
19
|
-
function
|
19
|
+
export function getMonorepoSecretObject(monorepoEnv: string, keys: string[] = []) {
|
20
20
|
// Dots in jsonpath can only be accessed with a \ prefix
|
21
21
|
const escapedSecretFileName = SECRET_FILE_NAME.replaceAll(".", "\\.");
|
22
22
|
// prettier-ignore
|
@@ -39,7 +39,7 @@ function updateSecret(monorepoEnv: string, vars: Record<string, string>) {
|
|
39
39
|
);
|
40
40
|
process.exit(1);
|
41
41
|
}
|
42
|
-
const current =
|
42
|
+
const current = getMonorepoSecretObject(monorepoEnv);
|
43
43
|
const newVars = { ...current, ...vars };
|
44
44
|
execUpdateSecret(monorepoEnv, newVars);
|
45
45
|
}
|
@@ -49,15 +49,19 @@ function deleteSecretKeys(monorepoEnv: string, keys: string[] = []) {
|
|
49
49
|
console.error("Keys to delete must be provided");
|
50
50
|
process.exit(1);
|
51
51
|
}
|
52
|
-
const secretValue =
|
52
|
+
const secretValue = getMonorepoSecretObject(monorepoEnv);
|
53
53
|
keys.forEach((key) => delete secretValue[key]);
|
54
54
|
execUpdateSecret(monorepoEnv, secretValue);
|
55
55
|
}
|
56
56
|
|
57
57
|
//= Interface (L3)
|
58
58
|
|
59
|
-
export function
|
60
|
-
const value =
|
59
|
+
export function getMonorepoSecretStr(monorepoEnv: string, keys: string[] = []) {
|
60
|
+
const value = getMonorepoSecretObject(monorepoEnv, keys);
|
61
|
+
if (Object.keys(value).length === 1) {
|
62
|
+
return Object.values(value)[0];
|
63
|
+
}
|
64
|
+
|
61
65
|
return Object.entries(value)
|
62
66
|
.map((pair) => pair.join("="))
|
63
67
|
.join("\n");
|
@@ -37,11 +37,13 @@
|
|
37
37
|
# This is also the basis for the name of the image in the registry.
|
38
38
|
# image-template The build process copies .devops/docker-images/<image-template>.Dockerfile and .devops/docker-images/<image-template>/ to the image.
|
39
39
|
# language The language of the image. Currently only "node" and "python" are supported.
|
40
|
-
# debug-template Each image comes with a debug pod that can be acccessed as a console. This is the name of the template to use.
|
40
|
+
# debug-template Each image comes with a debug pod that can be acccessed as a console. This is the name of the template to use.
|
41
|
+
# Only "debug-console" is currently supported. Can be left out if the image should not have a debug pod.
|
41
42
|
# can-db-migrate Whether this image can be used to run DB migrations. If set to true, the image could be used to run DB migrations if any project that uses this image depends
|
42
43
|
# on the db project and if the db project changed.
|
43
44
|
# domains The domains for the image. This is used to generate the ingress rules.
|
44
45
|
# This can be left out if the image does not have ingress rules, such as a worker image.
|
46
|
+
# cloudrun If this image should be pushed to cloudrun instead of the cluster registry, set to "true".
|
45
47
|
# applications List of applications that use this image. There is no need to specify dependencies - they will be derived as long as they are declared in package.json.
|
46
48
|
#
|
47
49
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
FROM node:24-bookworm-slim AS builder
|
2
|
+
|
3
|
+
RUN apt-get update && apt-get install -y jq curl
|
4
|
+
|
5
|
+
WORKDIR /app
|
6
|
+
|
7
|
+
ENV NODE_ENV=production
|
8
|
+
|
9
|
+
ARG MONOREPO_ENV
|
10
|
+
ENV MONOREPO_ENV=${MONOREPO_ENV}
|
11
|
+
RUN echo "Building for environment: $MONOREPO_ENV"
|
12
|
+
|
13
|
+
RUN npm install -g bun
|
14
|
+
|
15
|
+
# This assumes devops prep-build was called by the host, which creates the config/ folder with necessary env variables
|
16
|
+
# that are needed to be statitcally resolved by devops run-many build (e.g. NEXT_PUBLIC_*)
|
17
|
+
COPY . .
|
18
|
+
|
19
|
+
# Install dependencies using bun
|
20
|
+
RUN --mount=type=cache,target=/root/.bun/install/cache bun install
|
21
|
+
|
22
|
+
# This assumes the image has only one application that has a build script which outputs to dist/
|
23
|
+
RUN ./devops run-many build
|
24
|
+
|
25
|
+
|
26
|
+
FROM gcr.io/distroless/nodejs24-debian12 AS runner
|
27
|
+
WORKDIR /app
|
28
|
+
ENV NODE_ENV=production
|
29
|
+
COPY --from=builder /app/dist ./dist
|
30
|
+
EXPOSE 8080
|
31
|
+
CMD ["dist/index.js"]
|
@@ -4,6 +4,10 @@ inputs:
|
|
4
4
|
image_name:
|
5
5
|
description: 'The image key in images.yaml'
|
6
6
|
required: true
|
7
|
+
outputs:
|
8
|
+
affected:
|
9
|
+
description: 'Whether the specified image is affected (computed before deploy)'
|
10
|
+
value: ${{ steps.check_affected.outputs.affected }}
|
7
11
|
runs:
|
8
12
|
using: "composite"
|
9
13
|
steps:
|
package/src/types/index.ts
CHANGED
@@ -11,6 +11,7 @@ export const constFileSchema = z.object({
|
|
11
11
|
"image-versions-to-keep": z.number().optional(),
|
12
12
|
"registry-base-url": z.string(),
|
13
13
|
"registry-image-path-prefix": z.string().optional(),
|
14
|
+
"cloudrun-artifact-registry-repo-path": z.string().optional(),
|
14
15
|
"extra-remote-environments": z.array(z.string()),
|
15
16
|
"extra-local-environments": z.array(z.string()),
|
16
17
|
})
|
@@ -26,7 +27,8 @@ const singleImageSchema = z.object({
|
|
26
27
|
"image-template": z.string(),
|
27
28
|
"language": z.enum(SUPPORTED_LANGUAGES),
|
28
29
|
"domains": z.record(z.string()).optional(),
|
29
|
-
"debug-template": z.string(),
|
30
|
+
"debug-template": z.string().optional(),
|
31
|
+
"cloudrun": z.boolean().optional(),
|
30
32
|
"can-db-migrate": z.boolean().optional(),
|
31
33
|
applications: z.array(z.string()),
|
32
34
|
});
|