pepr 0.14.1 → 0.14.2

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/dist/cli.js CHANGED
@@ -106,9 +106,25 @@ var banner = `\x1B[0m\x1B[38;2;96;96;96m \x1B[0m\x1B[38;2;96;96;96m \x1B[0m\x1B[
106
106
  // src/cli/build.ts
107
107
  var import_child_process2 = require("child_process");
108
108
  var import_esbuild = require("esbuild");
109
- var import_fs5 = require("fs");
109
+ var import_fs6 = require("fs");
110
110
  var import_path = require("path");
111
111
 
112
+ // src/lib/included-files.ts
113
+ var import_fs = require("fs");
114
+ async function createDockerfile(version3, description, includedFiles) {
115
+ const file = `
116
+ # Use an official Node.js runtime as the base image
117
+ FROM ghcr.io/defenseunicorns/pepr/controller:v${version3}
118
+
119
+ LABEL description="${description}"
120
+
121
+ # Add the included files to the image
122
+ ${includedFiles.map((f) => `ADD ${f} ${f}`).join("\n")}
123
+
124
+ `;
125
+ await import_fs.promises.writeFile("Dockerfile.controller", file, { encoding: "utf-8" });
126
+ }
127
+
112
128
  // src/lib/assets/index.ts
113
129
  var import_crypto3 = __toESM(require("crypto"));
114
130
 
@@ -171,7 +187,7 @@ function genCert(key, name2, issuer) {
171
187
 
172
188
  // src/lib/assets/deploy.ts
173
189
  var import_crypto = __toESM(require("crypto"));
174
- var import_fs = require("fs");
190
+ var import_fs2 = require("fs");
175
191
  var import_kubernetes_fluent_client2 = require("kubernetes-fluent-client");
176
192
 
177
193
  // src/lib/logger.ts
@@ -769,7 +785,7 @@ async function deploy(assets, webhookTimeout) {
769
785
  if (host) {
770
786
  return;
771
787
  }
772
- const code = await import_fs.promises.readFile(path);
788
+ const code = await import_fs2.promises.readFile(path);
773
789
  const hash = import_crypto.default.createHash("sha256").update(code).digest("hex");
774
790
  if (code.length < 1) {
775
791
  throw new Error("No code provided");
@@ -851,7 +867,7 @@ function loadCapabilities(path) {
851
867
  // src/lib/assets/yaml.ts
852
868
  var import_client_node = require("@kubernetes/client-node");
853
869
  var import_crypto2 = __toESM(require("crypto"));
854
- var import_fs2 = require("fs");
870
+ var import_fs3 = require("fs");
855
871
  function zarfYaml({ name: name2, image, config }, path) {
856
872
  const zarfCfg = {
857
873
  kind: "ZarfPackageConfig",
@@ -880,7 +896,7 @@ function zarfYaml({ name: name2, image, config }, path) {
880
896
  }
881
897
  async function allYaml(assets) {
882
898
  const { name: name2, tls, apiToken, path } = assets;
883
- const code = await import_fs2.promises.readFile(path);
899
+ const code = await import_fs3.promises.readFile(path);
884
900
  const hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
885
901
  const mutateWebhook = await webhookConfig(assets, "mutate");
886
902
  const validateWebhook = await webhookConfig(assets, "validate");
@@ -1146,7 +1162,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
1146
1162
  var readmeMd = '# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```\nModule Root\n\u251C\u2500\u2500 package.json\n\u251C\u2500\u2500 pepr.ts\n\u2514\u2500\u2500 capabilities\n \u251C\u2500\u2500 example-one.ts\n \u251C\u2500\u2500 example-three.ts\n \u2514\u2500\u2500 example-two.ts\n```\n';
1147
1163
  var peprTS = 'import { PeprModule } from "pepr";\n// cfg loads your pepr configuration from package.json\nimport cfg from "./package.json";\n\n// HelloPepr is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\nimport { HelloPepr } from "./capabilities/hello-pepr";\n\n/**\n * This is the main entrypoint for this Pepr module. It is run when the module is started.\n * This is where you register your Pepr configurations and capabilities.\n */\nnew PeprModule(cfg, [\n // "HelloPepr" is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n';
1148
1164
  var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\n .SetLabel("pepr", "was-here")\n .SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .InNamespace("pepr-demo-2")\n .WithName("example-4a")\n .Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://api.chucknorris.io/jokes/random?category=dev");\n * const joke = await fetch("https://api.chucknorris.io/jokes/random?category=dev") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://api.chucknorris.io/jokes/random?category=dev")\n * ```\n */\ninterface TheChuckNorrisJoke {\n icon_url: string;\n id: string;\n url: string;\n value: string;\n}\n\nWhen(a.ConfigMap)\n .IsCreated()\n .WithLabel("chuck-norris")\n .Mutate(async change => {\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(\n "https://api.chucknorris.io/jokes/random?category=dev",\n );\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n // Add the Chuck Norris joke to the configmap\n change.Raw.data["chuck-says"] = response.data.value;\n return;\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * A callback function that is called once the Pepr Store is fully loaded.\n */\nStore.onReady(data => {\n Log.info(data, "Pepr Store Ready");\n});\n';
1149
- 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" }, version: "0.14.1", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest journey/entrypoint.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "1.6.0", pino: "8.16.0", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "17.7.2", "@commitlint/config-conventional": "17.7.0", "@jest/globals": "29.7.0", "@types/eslint": "8.44.4", "@types/express": "4.17.19", "@types/node": "18.x.x", "@types/node-forge": "1.3.7", "@types/prompts": "2.4.6", "@types/ramda": "0.29.6", "@types/uuid": "9.0.5", jest: "29.7.0", nock: "13.3.4", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.7.3", "@typescript-eslint/parser": "6.7.3", commander: "11.0.0", esbuild: "0.19.4", eslint: "8.50.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.1" } };
1165
+ 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" }, version: "0.14.2", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest journey/entrypoint.test.ts", "test:journey:run-wasm": "jest journey/entrypoint-wasm.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "1.7.0", pino: "8.16.0", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "17.8.0", "@commitlint/config-conventional": "17.8.0", "@jest/globals": "29.7.0", "@types/eslint": "8.44.6", "@types/express": "4.17.20", "@types/node": "18.x.x", "@types/node-forge": "1.3.8", "@types/prompts": "2.4.7", "@types/ramda": "0.29.7", "@types/uuid": "9.0.6", jest: "29.7.0", nock: "13.3.4", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.7.3", "@typescript-eslint/parser": "6.7.3", commander: "11.0.0", esbuild: "0.19.4", eslint: "8.50.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.1" } };
1150
1166
 
1151
1167
  // src/templates/pepr.code-snippets.json
1152
1168
  var pepr_code_snippets_default = {
@@ -1204,7 +1220,7 @@ var tsconfig_module_default = {
1204
1220
  };
1205
1221
 
1206
1222
  // src/cli/init/utils.ts
1207
- var import_fs3 = require("fs");
1223
+ var import_fs4 = require("fs");
1208
1224
  function sanitizeName(name2) {
1209
1225
  let sanitized = name2.toLowerCase().replace(/[^a-z0-9-]+/gi, "-");
1210
1226
  sanitized = sanitized.replace(/^-+|-+$/g, "");
@@ -1213,7 +1229,7 @@ function sanitizeName(name2) {
1213
1229
  }
1214
1230
  async function createDir(dir) {
1215
1231
  try {
1216
- await import_fs3.promises.mkdir(dir);
1232
+ await import_fs4.promises.mkdir(dir);
1217
1233
  } catch (err) {
1218
1234
  if (err && err.code === "EEXIST") {
1219
1235
  throw new Error(`Directory ${dir} already exists`);
@@ -1226,7 +1242,7 @@ function write(path, data) {
1226
1242
  if (typeof data !== "string") {
1227
1243
  data = JSON.stringify(data, null, 2);
1228
1244
  }
1229
- return import_fs3.promises.writeFile(path, data);
1245
+ return import_fs4.promises.writeFile(path, data);
1230
1246
  }
1231
1247
 
1232
1248
  // src/cli/init/templates.ts
@@ -1250,7 +1266,8 @@ function genPkgJSON(opts, pgkVerOverride) {
1250
1266
  alwaysIgnore: {
1251
1267
  namespaces: [],
1252
1268
  labels: []
1253
- }
1269
+ },
1270
+ includedFiles: []
1254
1271
  },
1255
1272
  scripts: {
1256
1273
  "k3d-setup": scripts["test:journey:k3d"]
@@ -1313,7 +1330,7 @@ var eslint = {
1313
1330
 
1314
1331
  // src/cli/format.ts
1315
1332
  var import_eslint = require("eslint");
1316
- var import_fs4 = require("fs");
1333
+ var import_fs5 = require("fs");
1317
1334
  var import_prettier = require("prettier");
1318
1335
  function format_default(program2) {
1319
1336
  program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
@@ -1346,7 +1363,7 @@ async function peprFormat(validateOnly) {
1346
1363
  await import_eslint.ESLint.outputFixes(results);
1347
1364
  }
1348
1365
  for (const { filePath } of results) {
1349
- const content = await import_fs4.promises.readFile(filePath, "utf8");
1366
+ const content = await import_fs5.promises.readFile(filePath, "utf8");
1350
1367
  const cfg = await (0, import_prettier.resolveConfig)(filePath);
1351
1368
  const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
1352
1369
  if (validateOnly) {
@@ -1355,7 +1372,7 @@ async function peprFormat(validateOnly) {
1355
1372
  console.error(`File ${filePath} is not formatted correctly`);
1356
1373
  }
1357
1374
  } else {
1358
- await import_fs4.promises.writeFile(filePath, formatted);
1375
+ await import_fs5.promises.writeFile(filePath, formatted);
1359
1376
  }
1360
1377
  }
1361
1378
  return !hasFailure;
@@ -1373,8 +1390,22 @@ function build_default(program2) {
1373
1390
  "-e, --entry-point [file]",
1374
1391
  "Specify the entry point file to build with. Note that changing this disables embedding of NPM packages.",
1375
1392
  peprTS2
1393
+ ).option(
1394
+ "-r, --registry-info [<registry>/<username>]",
1395
+ "Where to upload the image. Note: You must be signed into the registry"
1376
1396
  ).action(async (opts) => {
1377
1397
  const { cfg, path, uuid } = await buildModule(void 0, opts.entryPoint);
1398
+ const { includedFiles } = cfg.pepr;
1399
+ let image = "";
1400
+ if (opts.registryInfo !== void 0) {
1401
+ console.info(`Including ${includedFiles.length} files in controller image.`);
1402
+ image = `${opts.registryInfo}/custom-pepr-controller:${cfg.dependencies.pepr}`;
1403
+ if (includedFiles.length > 0) {
1404
+ await createDockerfile(cfg.dependencies.pepr, cfg.description, includedFiles);
1405
+ (0, import_child_process2.execSync)(`docker build --tag ${image} -f Dockerfile.controller .`, { stdio: "inherit" });
1406
+ (0, import_child_process2.execSync)(`docker push ${image}`, { stdio: "inherit" });
1407
+ }
1408
+ }
1378
1409
  if (opts.entryPoint !== peprTS2) {
1379
1410
  console.info(`\u2705 Module built successfully at ${path}`);
1380
1411
  return;
@@ -1387,13 +1418,16 @@ function build_default(program2) {
1387
1418
  },
1388
1419
  path
1389
1420
  );
1421
+ if (image !== "") {
1422
+ assets.image = image;
1423
+ }
1390
1424
  const yamlFile = `pepr-module-${uuid}.yaml`;
1391
1425
  const yamlPath = (0, import_path.resolve)("dist", yamlFile);
1392
1426
  const yaml = await assets.allYaml();
1393
1427
  const zarfPath = (0, import_path.resolve)("dist", "zarf.yaml");
1394
1428
  const zarf = assets.zarfYaml(yamlFile);
1395
- await import_fs5.promises.writeFile(yamlPath, yaml);
1396
- await import_fs5.promises.writeFile(zarfPath, zarf);
1429
+ await import_fs6.promises.writeFile(yamlPath, yaml);
1430
+ await import_fs6.promises.writeFile(zarfPath, zarf);
1397
1431
  console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
1398
1432
  });
1399
1433
  }
@@ -1404,15 +1438,15 @@ async function loadModule(entryPoint = peprTS2) {
1404
1438
  const cfgPath = (0, import_path.resolve)(".", "package.json");
1405
1439
  const input = (0, import_path.resolve)(".", entryPoint);
1406
1440
  try {
1407
- await import_fs5.promises.access(cfgPath);
1408
- await import_fs5.promises.access(input);
1441
+ await import_fs6.promises.access(cfgPath);
1442
+ await import_fs6.promises.access(input);
1409
1443
  } catch (e) {
1410
1444
  console.error(
1411
1445
  `Could not find ${cfgPath} or ${input} in the current directory. Please run this command from the root of your module's directory.`
1412
1446
  );
1413
1447
  process.exit(1);
1414
1448
  }
1415
- const moduleText = await import_fs5.promises.readFile(cfgPath, { encoding: "utf-8" });
1449
+ const moduleText = await import_fs6.promises.readFile(cfgPath, { encoding: "utf-8" });
1416
1450
  const cfg = JSON.parse(moduleText);
1417
1451
  const { uuid } = cfg.pepr;
1418
1452
  const name2 = `pepr-${uuid}.js`;
@@ -1555,7 +1589,7 @@ function deploy_default(program2) {
1555
1589
 
1556
1590
  // src/cli/dev.ts
1557
1591
  var import_child_process3 = require("child_process");
1558
- var import_fs6 = require("fs");
1592
+ var import_fs7 = require("fs");
1559
1593
  var import_prompts2 = __toESM(require("prompts"));
1560
1594
  function dev_default(program2) {
1561
1595
  program2.command("dev").description("Setup a local webhook development environment").option("-h, --host [host]", "Host to listen on", "host.k3d.internal").option("--confirm", "Skip confirmation prompt").action(async (opts) => {
@@ -1578,8 +1612,8 @@ function dev_default(program2) {
1578
1612
  path,
1579
1613
  opts.host
1580
1614
  );
1581
- await import_fs6.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
1582
- await import_fs6.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
1615
+ await import_fs7.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
1616
+ await import_fs7.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
1583
1617
  try {
1584
1618
  let program3;
1585
1619
  const runFork = async () => {
@@ -1623,7 +1657,7 @@ var import_path2 = require("path");
1623
1657
  var import_prompts4 = __toESM(require("prompts"));
1624
1658
 
1625
1659
  // src/cli/init/walkthrough.ts
1626
- var import_fs7 = require("fs");
1660
+ var import_fs8 = require("fs");
1627
1661
  var import_prompts3 = __toESM(require("prompts"));
1628
1662
 
1629
1663
  // src/lib/errors.ts
@@ -1643,7 +1677,7 @@ function walkthrough() {
1643
1677
  validate: async (val) => {
1644
1678
  try {
1645
1679
  const name2 = sanitizeName(val);
1646
- await import_fs7.promises.access(name2, import_fs7.promises.constants.F_OK);
1680
+ await import_fs8.promises.access(name2, import_fs8.promises.constants.F_OK);
1647
1681
  return "A directory with this name already exists";
1648
1682
  } catch (e) {
1649
1683
  return val.length > 2 || "The name must be at least 3 characters long";
@@ -1778,7 +1812,7 @@ var RootCmd = class extends import_commander.Command {
1778
1812
 
1779
1813
  // src/cli/update.ts
1780
1814
  var import_child_process5 = require("child_process");
1781
- var import_fs8 = __toESM(require("fs"));
1815
+ var import_fs9 = __toESM(require("fs"));
1782
1816
  var import_path3 = require("path");
1783
1817
  var import_prompts5 = __toESM(require("prompts"));
1784
1818
  function update_default(program2) {
@@ -1818,12 +1852,12 @@ function update_default(program2) {
1818
1852
  await write((0, import_path3.resolve)(".vscode", snippet.path), snippet.data);
1819
1853
  await write((0, import_path3.resolve)(".vscode", codeSettings.path), codeSettings.data);
1820
1854
  const samplePath = (0, import_path3.resolve)("capabilities", samplesYaml.path);
1821
- if (import_fs8.default.existsSync(samplePath)) {
1822
- import_fs8.default.unlinkSync(samplePath);
1855
+ if (import_fs9.default.existsSync(samplePath)) {
1856
+ import_fs9.default.unlinkSync(samplePath);
1823
1857
  await write(samplePath, samplesYaml.data);
1824
1858
  }
1825
1859
  const tsPath = (0, import_path3.resolve)("capabilities", helloPepr.path);
1826
- if (import_fs8.default.existsSync(tsPath)) {
1860
+ if (import_fs9.default.existsSync(tsPath)) {
1827
1861
  await write(tsPath, helloPepr.data);
1828
1862
  }
1829
1863
  }
@@ -48,7 +48,7 @@ if (process.env.LOG_LEVEL) {
48
48
  var logger_default = Log;
49
49
 
50
50
  // src/templates/data.json
51
- 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" }, version: "0.14.1", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest journey/entrypoint.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "1.6.0", pino: "8.16.0", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "17.7.2", "@commitlint/config-conventional": "17.7.0", "@jest/globals": "29.7.0", "@types/eslint": "8.44.4", "@types/express": "4.17.19", "@types/node": "18.x.x", "@types/node-forge": "1.3.7", "@types/prompts": "2.4.6", "@types/ramda": "0.29.6", "@types/uuid": "9.0.5", jest: "29.7.0", nock: "13.3.4", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.7.3", "@typescript-eslint/parser": "6.7.3", commander: "11.0.0", esbuild: "0.19.4", eslint: "8.50.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.1" } };
51
+ 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" }, version: "0.14.2", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest journey/entrypoint.test.ts", "test:journey:run-wasm": "jest journey/entrypoint-wasm.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "1.7.0", pino: "8.16.0", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "17.8.0", "@commitlint/config-conventional": "17.8.0", "@jest/globals": "29.7.0", "@types/eslint": "8.44.6", "@types/express": "4.17.20", "@types/node": "18.x.x", "@types/node-forge": "1.3.8", "@types/prompts": "2.4.7", "@types/ramda": "0.29.7", "@types/uuid": "9.0.6", jest: "29.7.0", nock: "13.3.4", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.7.3", "@typescript-eslint/parser": "6.7.3", commander: "11.0.0", esbuild: "0.19.4", eslint: "8.50.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.1" } };
52
52
 
53
53
  // src/runtime/controller.ts
54
54
  var { version } = packageJSON;
@@ -0,0 +1,2 @@
1
+ export declare function createDockerfile(version: string, description: string, includedFiles: string[]): Promise<void>;
2
+ //# sourceMappingURL=included-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"included-files.d.ts","sourceRoot":"","sources":["../../src/lib/included-files.ts"],"names":[],"mappings":"AAKA,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,iBAanG"}
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "engines": {
10
10
  "node": ">=18.0.0"
11
11
  },
12
- "version": "0.14.1",
12
+ "version": "0.14.2",
13
13
  "main": "dist/lib.js",
14
14
  "types": "dist/lib.d.ts",
15
15
  "scripts": {
@@ -19,33 +19,35 @@
19
19
  "test": "npm run test:unit && npm run test:journey",
20
20
  "test:unit": "npm run gen-data-json && jest src --coverage",
21
21
  "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run",
22
+ "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm",
22
23
  "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'",
23
24
  "test:journey:build": "npm run build && npm pack",
24
25
  "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev",
25
26
  "test:journey:run": "jest journey/entrypoint.test.ts",
27
+ "test:journey:run-wasm": "jest journey/entrypoint-wasm.test.ts",
26
28
  "format:check": "eslint src && prettier src --check",
27
29
  "format:fix": "eslint src --fix && prettier src --write"
28
30
  },
29
31
  "dependencies": {
30
32
  "express": "4.18.2",
31
33
  "fast-json-patch": "3.1.1",
32
- "kubernetes-fluent-client": "1.6.0",
34
+ "kubernetes-fluent-client": "1.7.0",
33
35
  "pino": "8.16.0",
34
36
  "pino-pretty": "10.2.3",
35
37
  "prom-client": "15.0.0",
36
38
  "ramda": "0.29.1"
37
39
  },
38
40
  "devDependencies": {
39
- "@commitlint/cli": "17.7.2",
40
- "@commitlint/config-conventional": "17.7.0",
41
+ "@commitlint/cli": "17.8.0",
42
+ "@commitlint/config-conventional": "17.8.0",
41
43
  "@jest/globals": "29.7.0",
42
- "@types/eslint": "8.44.4",
43
- "@types/express": "4.17.19",
44
+ "@types/eslint": "8.44.6",
45
+ "@types/express": "4.17.20",
44
46
  "@types/node": "18.x.x",
45
- "@types/node-forge": "1.3.7",
46
- "@types/prompts": "2.4.6",
47
- "@types/ramda": "0.29.6",
48
- "@types/uuid": "9.0.5",
47
+ "@types/node-forge": "1.3.8",
48
+ "@types/prompts": "2.4.7",
49
+ "@types/ramda": "0.29.7",
50
+ "@types/uuid": "9.0.6",
49
51
  "jest": "29.7.0",
50
52
  "nock": "13.3.4",
51
53
  "ts-jest": "29.1.1"
@@ -0,0 +1,19 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
+
4
+ import { promises as fs } from "fs";
5
+
6
+ export async function createDockerfile(version: string, description: string, includedFiles: string[]) {
7
+ const file = `
8
+ # Use an official Node.js runtime as the base image
9
+ FROM ghcr.io/defenseunicorns/pepr/controller:v${version}
10
+
11
+ LABEL description="${description}"
12
+
13
+ # Add the included files to the image
14
+ ${includedFiles.map(f => `ADD ${f} ${f}`).join("\n")}
15
+
16
+ `;
17
+
18
+ await fs.writeFile("Dockerfile.controller", file, { encoding: "utf-8" });
19
+ }
@@ -10,6 +10,7 @@
10
10
  "alwaysIgnore": {
11
11
  "namespaces": [],
12
12
  "labels": []
13
- }
13
+ },
14
+ "includedFiles": []
14
15
  }
15
16
  }