pepr 0.52.2-nightly.1 → 0.52.2-nightly.3

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.
@@ -50,7 +50,7 @@ if (process.env.LOG_LEVEL) {
50
50
  var logger_default = Log;
51
51
 
52
52
  // src/templates/data.json
53
- var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!src/fixtures/**", "!dist/**/*.test.d.ts*"], version: "0.52.2-nightly.1", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { build: "tsc -p config/tsconfig.root.json && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", "build:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr/private:dev $(node scripts/read-unicorn-build-args.mjs) .", ci: "npm ci", "format:check": "npm run format:src && npm run format:tests && npm run format:markdown && npm run format:integration && npm run format:prettier -- --check", "format:fix": "npm run format:src -- --fix && npm run format:markdown -- --fix && npm run format:integration -- --fix && npm run format:prettier -- --write", "format:integration": "eslint --config config/eslint.integration.config.mjs integration/cli integration/helpers", "format:markdown": 'npx -y markdownlint-cli --config config/.markdownlint.json --ignore adr --ignore integration/testroot --ignore pepr-test-module --ignore node_modules "**/*.md"', "format:prettier": "prettier --config config/.prettierrc src integration/cli/**/*.ts integration/helpers/**/*.ts", "format:src": "eslint --config config/eslint.root.config.mjs 'src/**/*.ts' --ignore-pattern '**/*.test.ts' --ignore-pattern 'src/templates/**'", "format:tests": "eslint --config config/eslint.test.config.mjs 'src/**/*.test.ts'", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi`, "set:version": "node scripts/set-version.js", test: "npm run test:unit && npm run test:journey && npm run test:journey-wasm", "test:artifacts": "npm run build && vitest run src/build-artifact.test.ts", "test:docs": "vitest run --config=config/vitest.integration.config.ts integration/cli/docs/*.test.ts", "test:integration": "npm run test:integration:prep && npm run test:integration:run", "test:integration:prep": "./integration/prep.sh", "test:integration:run": "vitest run --config=config/vitest.integration.config.ts integration", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey-wasm:unicorn": "npm run test:journey:k3d && npm run build && npm run test:journey:image:unicorn && npm run test:journey:run-wasm", "test:journey:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr/private:dev $(node scripts/read-unicorn-build-args.mjs) . && k3d image import pepr/private:dev -c pepr-dev", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:run": "vitest run --config=config/vitest.journey.config.ts journey/entrypoint.test.ts", "test:journey:run-wasm": "vitest run --config=config/vitest.journey.config.ts journey/entrypoint-wasm.test.ts", "test:journey:unicorn": "npm run test:journey:k3d && npm run test:journey:image:unicorn && npm run test:journey:run", "test:unit": "npm run gen-data-json && NODE_OPTIONS=--no-deprecation vitest --config config/vitest.root.config.ts run --coverage", "test:upgrade:unicorn": "npm run test:journey:k3d && npm run test:journey:image:unicorn && vitest run integration/cluster/upgrade.test.ts", "test:upgrade:upstream": "npm run test:journey:k3d && npm run test:journey:image && vitest run integration/cluster/upgrade.test.ts" }, dependencies: { "@types/ramda": "0.30.2", commander: "14.0.0", express: "5.1.0", "fast-json-patch": "3.1.1", heredoc: "^1.3.1", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.9.0", pino: "9.7.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.31.3", sigstore: "3.1.0", "ts-morph": "^26.0.0" }, devDependencies: { "@commitlint/cli": "19.8.1", "@commitlint/config-conventional": "19.8.1", "@fast-check/vitest": "^0.2.1", "@types/eslint": "9.6.1", "@types/express": "5.0.3", "@types/json-pointer": "^1.0.34", "@types/node": "24.x.x", "@types/node-forge": "1.3.13", "@types/uuid": "10.0.0", "@types/ws": "^8.18.1", "@vitest/coverage-v8": "^3.2.3", "fast-check": "^4.0.0", globals: "^16.0.0", husky: "^9.1.6", "js-yaml": "^4.1.0", shellcheck: "^3.0.0", tsx: "^4.20.3", undici: "^7.0.1", vitest: "^3.2.3" }, overrides: { glob: "^9.0.0" }, peerDependencies: { "@types/prompts": "2.4.9", "@typescript-eslint/eslint-plugin": "8.33.0", "@typescript-eslint/parser": "8.33.0", esbuild: "0.25.5", eslint: "^9.26.0", "node-forge": "1.3.1", prettier: "3.5.3", prompts: "2.4.2", typescript: "5.8.3", uuid: "11.1.0" } };
53
+ var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!src/fixtures/**", "!dist/**/*.test.d.ts*"], version: "0.52.2-nightly.3", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { build: "tsc -p config/tsconfig.root.json && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", "build:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr/private:dev $(node scripts/read-unicorn-build-args.mjs) .", ci: "npm ci", "format:check": "npm run format:src && npm run format:tests && npm run format:markdown && npm run format:integration && npm run format:prettier -- --check", "format:fix": "npm run format:src -- --fix && npm run format:markdown -- --fix && npm run format:integration -- --fix && npm run format:prettier -- --write", "format:integration": "eslint --config config/eslint.integration.config.mjs integration/cli integration/helpers", "format:markdown": 'npx -y markdownlint-cli --config config/.markdownlint.json --ignore adr --ignore integration/testroot --ignore pepr-test-module --ignore node_modules "**/*.md"', "format:prettier": "prettier --config config/.prettierrc src integration/cli/**/*.ts integration/helpers/**/*.ts", "format:src": "eslint --config config/eslint.root.config.mjs 'src/**/*.ts' --ignore-pattern '**/*.test.ts' --ignore-pattern 'src/templates/**'", "format:tests": "eslint --config config/eslint.test.config.mjs 'src/**/*.test.ts'", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi`, "set:version": "node scripts/set-version.js", test: "npm run test:unit && npm run test:journey && npm run test:journey-wasm", "test:artifacts": "npm run build && vitest run src/build-artifact.test.ts", "test:docs": "vitest run --config=config/vitest.integration.config.ts integration/cli/docs/*.test.ts", "test:integration": "npm run test:integration:prep && npm run test:integration:run", "test:integration:prep": "./integration/prep.sh", "test:integration:run": "vitest run --config=config/vitest.integration.config.ts integration", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey-wasm:unicorn": "npm run test:journey:k3d && npm run build && npm run test:journey:image:unicorn && npm run test:journey:run-wasm", "test:journey:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr/private:dev $(node scripts/read-unicorn-build-args.mjs) . && k3d image import pepr/private:dev -c pepr-dev", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:run": "vitest run --config=config/vitest.journey.config.ts journey/entrypoint.test.ts", "test:journey:run-wasm": "vitest run --config=config/vitest.journey.config.ts journey/entrypoint-wasm.test.ts", "test:journey:unicorn": "npm run test:journey:k3d && npm run test:journey:image:unicorn && npm run test:journey:run", "test:unit": "npm run gen-data-json && NODE_OPTIONS=--no-deprecation vitest --config config/vitest.root.config.ts run --coverage", "test:upgrade:unicorn": "npm run test:journey:k3d && npm run test:journey:image:unicorn && vitest run integration/cluster/upgrade.test.ts", "test:upgrade:upstream": "npm run test:journey:k3d && npm run test:journey:image && vitest run integration/cluster/upgrade.test.ts" }, dependencies: { "@types/ramda": "0.31.0", commander: "14.0.0", express: "5.1.0", "fast-json-patch": "3.1.1", heredoc: "^1.3.1", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.10.0", pino: "9.7.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.31.3", sigstore: "3.1.0", "ts-morph": "^26.0.0" }, devDependencies: { "@commitlint/cli": "19.8.1", "@commitlint/config-conventional": "19.8.1", "@fast-check/vitest": "^0.2.1", "@types/eslint": "9.6.1", "@types/express": "5.0.3", "@types/json-pointer": "^1.0.34", "@types/node": "24.x.x", "@types/node-forge": "1.3.13", "@types/uuid": "10.0.0", "@types/ws": "^8.18.1", "@vitest/coverage-v8": "^3.2.3", "fast-check": "^4.0.0", globals: "^16.0.0", husky: "^9.1.6", "js-yaml": "^4.1.0", shellcheck: "^3.0.0", tsx: "^4.20.3", undici: "^7.0.1", vitest: "^3.2.3" }, overrides: { glob: "^9.0.0" }, peerDependencies: { "@types/prompts": "2.4.9", "@typescript-eslint/eslint-plugin": "8.33.0", "@typescript-eslint/parser": "8.33.0", esbuild: "0.25.5", eslint: "^9.26.0", "node-forge": "1.3.1", prettier: "3.5.3", prompts: "2.4.2", typescript: "5.8.3", uuid: "11.1.0" } };
54
54
 
55
55
  // src/lib/k8s.ts
56
56
  var import_kubernetes_fluent_client = require("kubernetes-fluent-client");
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "!src/fixtures/**",
17
17
  "!dist/**/*.test.d.ts*"
18
18
  ],
19
- "version": "0.52.2-nightly.1",
19
+ "version": "0.52.2-nightly.3",
20
20
  "main": "dist/lib.js",
21
21
  "types": "dist/lib.d.ts",
22
22
  "scripts": {
@@ -55,14 +55,14 @@
55
55
  "test:upgrade:upstream": "npm run test:journey:k3d && npm run test:journey:image && vitest run integration/cluster/upgrade.test.ts"
56
56
  },
57
57
  "dependencies": {
58
- "@types/ramda": "0.30.2",
58
+ "@types/ramda": "0.31.0",
59
59
  "commander": "14.0.0",
60
60
  "express": "5.1.0",
61
61
  "fast-json-patch": "3.1.1",
62
62
  "heredoc": "^1.3.1",
63
63
  "http-status-codes": "^2.3.0",
64
64
  "json-pointer": "^0.6.2",
65
- "kubernetes-fluent-client": "3.9.0",
65
+ "kubernetes-fluent-client": "3.10.0",
66
66
  "pino": "9.7.0",
67
67
  "pino-pretty": "13.0.0",
68
68
  "prom-client": "15.1.3",
@@ -1,24 +1,24 @@
1
- import { createDirectoryIfNotExists } from "../lib/filesystemService";
2
- import { sanitizeResourceName } from "../sdk/sdk";
3
- import { createDockerfile } from "../lib/included-files";
1
+ import { createDirectoryIfNotExists } from "../../lib/filesystemService";
2
+ import { sanitizeResourceName } from "../../sdk/sdk";
3
+ import { createDockerfile } from "../../lib/included-files";
4
4
  import { execSync } from "child_process";
5
- import { CapabilityExport } from "../lib/types";
6
- import { validateCapabilityNames } from "../lib/helpers";
5
+ import { CapabilityExport } from "../../lib/types";
6
+ import { validateCapabilityNames } from "../../lib/helpers";
7
7
  import { BuildOptions, context, BuildContext } from "esbuild";
8
- import { Assets } from "../lib/assets/assets";
8
+ import { Assets } from "../../lib/assets/assets";
9
9
  import { resolve } from "path";
10
10
  import { promises as fs } from "fs";
11
- import { generateAllYaml } from "../lib/assets/yaml/generateAllYaml";
12
- import { webhookConfigGenerator } from "../lib/assets/webhooks";
13
- import { generateZarfYamlGeneric } from "../lib/assets/yaml/generateZarfYaml";
11
+ import { generateAllYaml } from "../../lib/assets/yaml/generateAllYaml";
12
+ import { webhookConfigGenerator } from "../../lib/assets/webhooks";
13
+ import { generateZarfYamlGeneric } from "../../lib/assets/yaml/generateZarfYaml";
14
14
  import {
15
15
  getDeployment,
16
16
  getModuleSecret,
17
17
  getWatcher,
18
18
  service,
19
19
  watcherService,
20
- } from "../lib/assets/k8sObjects";
21
- import { Reloader } from "./types";
20
+ } from "../../lib/assets/k8sObjects";
21
+ import { Reloader } from "../types";
22
22
 
23
23
  interface ImageOptions {
24
24
  customImage?: string;
@@ -0,0 +1,160 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
+
4
+ import { execFileSync } from "child_process";
5
+ import { BuildOptions, analyzeMetafile } from "esbuild";
6
+ import { basename, extname, resolve } from "path";
7
+ import { dependencies } from "../init/templates";
8
+ import { peprFormat } from "../format";
9
+ import { watchForChanges } from "./build.helpers";
10
+ import { PeprConfig, Reloader } from "../types";
11
+ import { BuildContext } from "esbuild";
12
+ import { loadModule } from "./loadModule";
13
+
14
+ type BuildModuleReturn = {
15
+ ctx: BuildContext<BuildOptions>;
16
+ path: string;
17
+ cfg: PeprConfig;
18
+ uuid: string;
19
+ };
20
+ // Create a list of external libraries to exclude from the bundle, these are already stored in the container
21
+ const externalLibs = Object.keys(dependencies);
22
+
23
+ // Add the pepr library to the list of external libraries
24
+ externalLibs.push("pepr");
25
+
26
+ // Add the kubernetes client to the list of external libraries as it is pulled in by kubernetes-fluent-client
27
+ externalLibs.push("@kubernetes/client-node");
28
+
29
+ export async function buildModule(
30
+ outputDir: string,
31
+ reloader?: Reloader,
32
+ entryPoint = "pepr.ts",
33
+ embed = true,
34
+ ): Promise<BuildModuleReturn | void> {
35
+ try {
36
+ const { cfg, modulePath, path, uuid } = await loadModule(outputDir, entryPoint);
37
+
38
+ await checkFormat();
39
+ // Resolve node_modules folder (in support of npm workspaces!)
40
+ const npmRoot = execFileSync("npm", ["root"]).toString().trim();
41
+
42
+ // Run `tsc` to validate the module's types & output sourcemaps
43
+ const args = ["--project", `${modulePath}/tsconfig.json`, "--outdir", outputDir];
44
+ execFileSync(`${npmRoot}/.bin/tsc`, args);
45
+
46
+ // Common build options for all builds
47
+ const ctxCfg: BuildOptions = {
48
+ bundle: true,
49
+ entryPoints: [entryPoint],
50
+ external: externalLibs,
51
+ format: "cjs",
52
+ keepNames: true,
53
+ legalComments: "external",
54
+ metafile: true,
55
+ minify: true,
56
+ outfile: path,
57
+ plugins: [
58
+ {
59
+ name: "reload-server",
60
+ setup(build): void | Promise<void> {
61
+ build.onEnd(async r => {
62
+ // Print the build size analysis
63
+ if (r?.metafile) {
64
+ console.info(await analyzeMetafile(r.metafile));
65
+ }
66
+
67
+ // If we're in dev mode, call the reloader function
68
+ if (reloader) {
69
+ await reloader(r);
70
+ }
71
+ });
72
+ },
73
+ },
74
+ ],
75
+ platform: "node",
76
+ sourcemap: true,
77
+ treeShaking: true,
78
+ };
79
+
80
+ if (reloader) {
81
+ // Only minify the code if we're not in dev mode
82
+ ctxCfg.minify = false;
83
+ }
84
+
85
+ // If not embedding (i.e. making a library module to be distro'd via NPM)
86
+ if (!embed) {
87
+ // Don't minify
88
+ ctxCfg.minify = false;
89
+
90
+ // Preserve the original file name
91
+ ctxCfg.outfile = resolve(outputDir, basename(entryPoint, extname(entryPoint))) + ".js";
92
+
93
+ // Don't bundle
94
+ ctxCfg.packages = "external";
95
+
96
+ // Don't tree shake
97
+ ctxCfg.treeShaking = false;
98
+ }
99
+
100
+ const ctx = await watchForChanges(ctxCfg, reloader);
101
+
102
+ return { ctx, path, cfg, uuid };
103
+ } catch (e) {
104
+ handleModuleBuildError(e);
105
+ }
106
+ }
107
+
108
+ interface BuildModuleResult {
109
+ stdout?: Buffer;
110
+ stderr: Buffer;
111
+ }
112
+
113
+ function handleModuleBuildError(e: BuildModuleResult): void {
114
+ console.error(`Error building module:`, e);
115
+
116
+ if (!e.stdout) process.exit(1); // Exit with a non-zero exit code on any other error
117
+
118
+ const out = e.stdout.toString() as string;
119
+ const err = e.stderr.toString();
120
+
121
+ console.info(out);
122
+ console.error(err);
123
+
124
+ // Check for version conflicts
125
+ if (out.includes("Types have separate declarations of a private property '_name'.")) {
126
+ // Try to find the conflicting package
127
+ const pgkErrMatch = /error TS2322: .*? 'import\("\/.*?\/node_modules\/(.*?)\/node_modules/g;
128
+ out.matchAll(pgkErrMatch);
129
+
130
+ // Look for package conflict errors
131
+ const conflicts = [...out.matchAll(pgkErrMatch)];
132
+
133
+ // If the regex didn't match, leave a generic error
134
+ if (conflicts.length < 1) {
135
+ console.info(
136
+ `\n\tOne or more imported Pepr Capabilities seem to be using an incompatible version of Pepr.\n\tTry updating your Pepr Capabilities to their latest versions.`,
137
+ "Version Conflict",
138
+ );
139
+ }
140
+
141
+ // Otherwise, loop through each conflicting package and print an error
142
+ conflicts.forEach(match => {
143
+ console.info(
144
+ `\n\tPackage '${match[1]}' seems to be incompatible with your current version of Pepr.\n\tTry updating to the latest version.`,
145
+ "Version Conflict",
146
+ );
147
+ });
148
+ }
149
+ }
150
+
151
+ async function checkFormat(): Promise<void> {
152
+ const validFormat = await peprFormat(true);
153
+
154
+ if (!validFormat) {
155
+ console.info(
156
+ "\x1b[33m%s\x1b[0m",
157
+ "Formatting errors were found. The build will continue, but you may want to run `npx pepr format` to address any issues.",
158
+ );
159
+ }
160
+ }
@@ -0,0 +1,150 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
+
4
+ import { Assets } from "../../lib/assets/assets";
5
+ import { Command } from "commander";
6
+ import { Option } from "commander";
7
+ import { parseTimeout } from "../../lib/helpers";
8
+ import {
9
+ determineRbacMode,
10
+ assignImage,
11
+ createOutputDirectory,
12
+ handleValidCapabilityNames,
13
+ handleCustomImageBuild,
14
+ validImagePullSecret,
15
+ generateYamlAndWriteToDisk,
16
+ } from "./build.helpers";
17
+ import { buildModule } from "./buildModule";
18
+
19
+ export default function (program: Command): void {
20
+ program
21
+ .command("build")
22
+ .description("Build a Pepr Module for deployment")
23
+ .addOption(
24
+ new Option("-M, --rbac-mode <mode>", "Override module config and set RBAC mode.").choices([
25
+ "admin",
26
+ "scoped",
27
+ ]),
28
+ )
29
+ .addOption(
30
+ new Option(
31
+ "-I, --registry-info <registry/username>",
32
+ "Provide the image registry and username for building and pushing a custom WASM container. Requires authentication. Conflicts with --custom-image and --registry. Builds and pushes `'<registry/username>/custom-pepr-controller:<current-version>'`.",
33
+ ).conflicts(["customImage", "registry"]),
34
+ )
35
+ .option("-P, --with-pull-secret <name>", "Use image pull secret for controller Deployment.", "")
36
+ .addOption(
37
+ new Option(
38
+ "-c, --custom-name <name>",
39
+ "Set name for zarf component and service monitors in helm charts.",
40
+ ),
41
+ )
42
+ .option("-e, --entry-point <file>", "Specify the entry point file to build with.", "pepr.ts")
43
+ .addOption(
44
+ new Option(
45
+ "-i, --custom-image <image>",
46
+ "Specify a custom image with version for deployments. Conflicts with --registry-info and --registry. Example: 'docker.io/username/custom-pepr-controller:v1.0.0'",
47
+ ).conflicts(["registryInfo", "registry"]),
48
+ )
49
+ .option(
50
+ "-n, --no-embed",
51
+ "Disable embedding of deployment files into output module. Useful when creating library modules intended solely for reuse/distribution via NPM.",
52
+ )
53
+ .option("-o, --output <directory>", "Set output directory.", "dist")
54
+ .addOption(
55
+ new Option(
56
+ "-r, --registry <GitHub|Iron Bank>",
57
+ "Container registry: Choose container registry for deployment manifests. Conflicts with --custom-image and --registry-info.",
58
+ )
59
+ .conflicts(["customImage", "registryInfo"])
60
+ .choices(["GitHub", "Iron Bank"]),
61
+ )
62
+ .option(
63
+ "-t, --timeout <seconds>",
64
+ "How long the API server should wait for a webhook to respond before treating the call as a failure.",
65
+ parseTimeout,
66
+ )
67
+ .addOption(
68
+ new Option("-z, --zarf <manifest|chart>", "Set Zarf package type")
69
+ .choices(["manifest", "chart"])
70
+ .default("manifest"),
71
+ )
72
+ .action(async opts => {
73
+ const outputDir = await createOutputDirectory(opts.output);
74
+
75
+ // Build the module
76
+ const buildModuleResult = await buildModule(
77
+ outputDir,
78
+ undefined,
79
+ opts.entryPoint,
80
+ opts.embed,
81
+ );
82
+
83
+ const { cfg, path } = buildModuleResult!;
84
+ // override the name if provided
85
+ if (opts.customName) {
86
+ process.env.PEPR_CUSTOM_BUILD_NAME = opts.customName;
87
+ }
88
+
89
+ const image = assignImage({
90
+ customImage: opts.customImage,
91
+ registryInfo: opts.registryInfo,
92
+ peprVersion: cfg.pepr.peprVersion,
93
+ registry: opts.registry,
94
+ });
95
+
96
+ // Check if there is a custom timeout defined
97
+ if (opts.timeout !== undefined) {
98
+ cfg.pepr.webhookTimeout = opts.timeout;
99
+ }
100
+
101
+ if (opts.registryInfo !== undefined) {
102
+ console.info(`Including ${cfg.pepr.includedFiles.length} files in controller image.`);
103
+ // for journey test to make sure the image is built
104
+
105
+ // only actually build/push if there are files to include
106
+ await handleCustomImageBuild(
107
+ cfg.pepr.includedFiles,
108
+ cfg.pepr.peprVersion,
109
+ cfg.description,
110
+ image,
111
+ );
112
+ }
113
+
114
+ // If building without embedding, exit after building
115
+ if (!opts.embed) {
116
+ console.info(`Module built successfully at ${path}`);
117
+ return;
118
+ }
119
+
120
+ // Generate a secret for the module
121
+ const assets = new Assets(
122
+ {
123
+ ...cfg.pepr,
124
+ appVersion: cfg.version,
125
+ description: cfg.description,
126
+ alwaysIgnore: {
127
+ namespaces: cfg.pepr.alwaysIgnore?.namespaces,
128
+ },
129
+ // Can override the rbacMode with the CLI option
130
+ rbacMode: determineRbacMode(opts, cfg),
131
+ },
132
+ path,
133
+ opts.withPullSecret === "" ? [] : [opts.withPullSecret],
134
+ );
135
+
136
+ if (image !== "") assets.image = image;
137
+
138
+ // Ensure imagePullSecret is valid
139
+ validImagePullSecret(opts.withPullSecret);
140
+
141
+ handleValidCapabilityNames(assets.capabilities);
142
+ await generateYamlAndWriteToDisk({
143
+ uuid: cfg.pepr.uuid,
144
+ outputDir,
145
+ imagePullSecret: opts.withPullSecret,
146
+ zarf: opts.zarf,
147
+ assets,
148
+ });
149
+ });
150
+ }
@@ -0,0 +1,54 @@
1
+ import fs from "fs/promises";
2
+ import { resolve, dirname } from "path/posix";
3
+ import { version } from "../init/templates";
4
+ import { PeprConfig } from "../types";
5
+
6
+ export type LoadModuleReturn = {
7
+ cfg: PeprConfig;
8
+ entryPointPath: string;
9
+ modulePath: string;
10
+ name: string;
11
+ path: string;
12
+ uuid: string;
13
+ };
14
+
15
+ export async function loadModule(outputDir: string, entryPoint: string): Promise<LoadModuleReturn> {
16
+ // Resolve path to the module / files
17
+ const entryPointPath = resolve(".", entryPoint);
18
+ const modulePath = dirname(entryPointPath);
19
+ const cfgPath = resolve(modulePath, "package.json");
20
+
21
+ // Ensure the module's package.json and entrypoint files exist
22
+ try {
23
+ await fs.access(cfgPath);
24
+ await fs.access(entryPointPath);
25
+ } catch {
26
+ console.error(
27
+ `Could not find ${cfgPath} or ${entryPointPath} in the current directory. Please run this command from the root of your module's directory.`,
28
+ );
29
+ process.exit(1);
30
+ }
31
+
32
+ // Read the module's UUID from the package.json file
33
+ const moduleText = await fs.readFile(cfgPath, { encoding: "utf-8" });
34
+ const cfg = JSON.parse(moduleText);
35
+ const { uuid } = cfg.pepr;
36
+ const name = `pepr-${uuid}.js`;
37
+
38
+ // Set the Pepr version from the current running version
39
+ cfg.pepr.peprVersion = version;
40
+
41
+ // Exit if the module's UUID could not be found
42
+ if (!uuid) {
43
+ throw new Error("Could not load the uuid in package.json");
44
+ }
45
+
46
+ return {
47
+ cfg,
48
+ entryPointPath,
49
+ modulePath,
50
+ name,
51
+ path: resolve(outputDir, name),
52
+ uuid,
53
+ };
54
+ }
package/src/cli/deploy.ts CHANGED
@@ -6,7 +6,7 @@ import { CapabilityExport } from "../lib/types";
6
6
  import { Assets } from "../lib/assets/assets";
7
7
  import { ImagePullSecret } from "../lib/types";
8
8
  import { Command } from "commander";
9
- import { buildModule } from "./build";
9
+ import { buildModule } from "./build/buildModule";
10
10
  import { deployImagePullSecret, deployWebhook } from "../lib/assets/deploy";
11
11
  import { namespaceDeploymentsReady } from "../lib/deploymentChecks";
12
12
  import { sanitizeName } from "./init/utils";
@@ -96,7 +96,7 @@ export async function getUserConfirmation(opts: { yes: boolean }): Promise<boole
96
96
  }
97
97
 
98
98
  async function buildAndDeployModule(image: string, force: boolean): Promise<void> {
99
- const builtModule = await buildModule();
99
+ const builtModule = await buildModule("dist");
100
100
  if (!builtModule) {
101
101
  return;
102
102
  }
package/src/cli/dev.ts CHANGED
@@ -7,7 +7,8 @@ import { ChildProcess, fork } from "child_process";
7
7
  import { K8s, kind } from "kubernetes-fluent-client";
8
8
  import { Command } from "commander";
9
9
  import { Store } from "../lib/k8s";
10
- import { buildModule, loadModule } from "./build";
10
+ import { buildModule } from "./build/buildModule";
11
+ import { loadModule } from "./build/loadModule";
11
12
  import { deployWebhook } from "../lib/assets/deploy";
12
13
  import { promises as fs } from "fs";
13
14
  import { validateCapabilityNames } from "../lib/helpers";
@@ -35,7 +36,7 @@ export default function (program: Command): void {
35
36
  }
36
37
 
37
38
  // Build the module
38
- const { cfg, path } = await loadModule();
39
+ const { cfg, path } = await loadModule("dist", "pepr.ts");
39
40
 
40
41
  // Generate a secret for the module
41
42
  const webhook = new Assets(
@@ -103,7 +104,7 @@ export default function (program: Command): void {
103
104
  });
104
105
  };
105
106
 
106
- await buildModule(async r => {
107
+ await buildModule("dist", async r => {
107
108
  if (r.errors.length > 0) {
108
109
  console.error(`Error compiling module: ${r.errors}`);
109
110
  return;
package/src/cli/types.ts CHANGED
@@ -1,6 +1,29 @@
1
1
  import { BuildResult, BuildOptions } from "esbuild";
2
2
  import { Answers } from "prompts";
3
+ import { ModuleConfig } from "../lib/types";
3
4
 
4
5
  export type InitOptions = Answers<"name" | "description" | "errorBehavior" | "uuid">;
5
6
 
6
7
  export type Reloader = (opts: BuildResult<BuildOptions>) => void | Promise<void>;
8
+
9
+ export type PeprConfig = Omit<ModuleConfig, keyof PeprNestedFields> & {
10
+ pepr: PeprNestedFields & {
11
+ includedFiles: string[];
12
+ };
13
+ description: string;
14
+ version: string;
15
+ };
16
+
17
+ type PeprNestedFields = Pick<
18
+ ModuleConfig,
19
+ | "uuid"
20
+ | "onError"
21
+ | "webhookTimeout"
22
+ | "customLabels"
23
+ | "alwaysIgnore"
24
+ | "env"
25
+ | "rbac"
26
+ | "rbacMode"
27
+ > & {
28
+ peprVersion: string;
29
+ };
package/src/cli/uuid.ts CHANGED
@@ -13,12 +13,11 @@ export default function (program: Command): void {
13
13
  const deployments = await getPeprDeploymentsByUUID(uuid);
14
14
  const uuidTable = buildUUIDTable(deployments);
15
15
 
16
- console.log("UUID\t\tDescription");
17
- console.log("--------------------------------------------");
18
-
19
- Object.entries(uuidTable).forEach(([uuid, description]) => {
20
- console.log(`${uuid}\t${description}`);
21
- });
16
+ const uuidTableEntries = Object.entries(uuidTable).map(([uuid, description]) => ({
17
+ UUID: uuid,
18
+ Description: description,
19
+ }));
20
+ console.table(uuidTableEntries);
22
21
  });
23
22
  }
24
23
 
@@ -1,33 +0,0 @@
1
- import { BuildContext, BuildOptions } from "esbuild";
2
- import { Command } from "commander";
3
- import { ModuleConfig } from "../lib/types";
4
- import { Reloader } from "./types";
5
- type PeprNestedFields = Pick<ModuleConfig, "uuid" | "onError" | "webhookTimeout" | "customLabels" | "alwaysIgnore" | "env" | "rbac" | "rbacMode"> & {
6
- peprVersion: string;
7
- };
8
- type PeprConfig = Omit<ModuleConfig, keyof PeprNestedFields> & {
9
- pepr: PeprNestedFields & {
10
- includedFiles: string[];
11
- };
12
- description: string;
13
- version: string;
14
- };
15
- type LoadModuleReturn = {
16
- cfg: PeprConfig;
17
- entryPointPath: string;
18
- modulePath: string;
19
- name: string;
20
- path: string;
21
- uuid: string;
22
- };
23
- type BuildModuleReturn = {
24
- ctx: BuildContext<BuildOptions>;
25
- path: string;
26
- cfg: PeprConfig;
27
- uuid: string;
28
- };
29
- export default function (program: Command): void;
30
- export declare function loadModule(entryPoint?: string): Promise<LoadModuleReturn>;
31
- export declare function buildModule(reloader?: Reloader, entryPoint?: string, embed?: boolean): Promise<BuildModuleReturn | void>;
32
- export {};
33
- //# sourceMappingURL=build.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAmB,MAAM,SAAS,CAAC;AAKtE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAW5C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAInC,KAAK,gBAAgB,GAAG,IAAI,CAC1B,YAAY,EACV,MAAM,GACN,SAAS,GACT,gBAAgB,GAChB,cAAc,GACd,cAAc,GACd,KAAK,GACL,MAAM,GACN,UAAU,CACb,GAAG;IACF,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE,MAAM,gBAAgB,CAAC,GAAG;IAC7D,IAAI,EAAE,gBAAgB,GAAG;QACvB,aAAa,EAAE,MAAM,EAAE,CAAC;KACzB,CAAC;IACF,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACtB,GAAG,EAAE,UAAU,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,GAAG,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,UAAU,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,OAAO,GAAG,IAAI,CA8H/C;AAWD,wBAAsB,UAAU,CAAC,UAAU,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAuC/E;AAED,wBAAsB,WAAW,CAC/B,QAAQ,CAAC,EAAE,QAAQ,EACnB,UAAU,SAAS,EACnB,KAAK,UAAO,GACX,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAwEnC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"build.helpers.d.ts","sourceRoot":"","sources":["../../src/cli/build.helpers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAW,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAa9C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,UAAU,YAAY;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AACD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,CAe9D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,EAC3B,GAAG,EAAE;IAAE,IAAI,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GACnC,MAAM,CAaR;AAED;;;;GAIG;AAEH,wBAAsB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAS9E;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAI/F;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAStE;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,aAAa,EAAE,MAAM,EAAE,EACvB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAQf;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAQjF;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAC7B,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAarC;AAED,wBAAsB,0BAA0B,CAAC,GAAG,EAAE;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,IAAI,CAAC,CAiChB"}