pepr 0.52.3 → 0.53.0
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/banner.d.ts +1 -1
- package/dist/cli/banner.d.ts.map +1 -1
- package/dist/cli/build/build.helpers.d.ts +1 -1
- package/dist/cli/build/build.helpers.d.ts.map +1 -1
- package/dist/cli/build/buildModule.d.ts +1 -2
- package/dist/cli/build/buildModule.d.ts.map +1 -1
- package/dist/cli/build/index.d.ts.map +1 -1
- package/dist/cli/deploy/buildAndDeploy.d.ts +5 -0
- package/dist/cli/deploy/buildAndDeploy.d.ts.map +1 -0
- package/dist/cli/deploy/imagePullSecret.d.ts +16 -0
- package/dist/cli/deploy/imagePullSecret.d.ts.map +1 -0
- package/dist/cli/deploy/index.d.ts +3 -0
- package/dist/cli/deploy/index.d.ts.map +1 -0
- package/dist/cli/deploy/userConfirmation.d.ts +4 -0
- package/dist/cli/deploy/userConfirmation.d.ts.map +1 -0
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/init/createProjectFiles.d.ts +3 -0
- package/dist/cli/init/createProjectFiles.d.ts.map +1 -0
- package/dist/cli/init/doPostInitActions.d.ts +2 -0
- package/dist/cli/init/doPostInitActions.d.ts.map +1 -0
- package/dist/cli/init/index.d.ts +1 -1
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/setupProjectStructure.d.ts +2 -0
- package/dist/cli/init/setupProjectStructure.d.ts.map +1 -0
- package/dist/cli/init/templates.d.ts +9 -9
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/init/walkthrough.d.ts.map +1 -1
- package/dist/cli.js +260 -229
- package/dist/controller.js +1 -1
- package/dist/lib/assets/assets.d.ts.map +1 -1
- package/dist/lib/assets/loader.d.ts.map +1 -1
- package/dist/lib/assets/webhooks.d.ts +5 -1
- package/dist/lib/assets/webhooks.d.ts.map +1 -1
- package/dist/lib/assets/yaml/overridesFile.d.ts +1 -0
- package/dist/lib/assets/yaml/overridesFile.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/types.d.ts +7 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib.js +1 -0
- package/dist/lib.js.map +2 -2
- package/package.json +15 -15
- package/src/cli/banner.ts +25 -59
- package/src/cli/build/build.helpers.ts +3 -9
- package/src/cli/build/buildModule.ts +1 -1
- package/src/cli/build/index.ts +9 -5
- package/src/cli/deploy/buildAndDeploy.ts +48 -0
- package/src/cli/deploy/imagePullSecret.ts +68 -0
- package/src/cli/deploy/index.ts +40 -0
- package/src/cli/deploy/userConfirmation.ts +16 -0
- package/src/cli/dev.ts +6 -5
- package/src/cli/init/createProjectFiles.ts +48 -0
- package/src/cli/init/doPostInitActions.ts +26 -0
- package/src/cli/init/index.ts +18 -84
- package/src/cli/init/setupProjectStructure.ts +8 -0
- package/src/cli/init/templates.ts +2 -4
- package/src/cli/init/walkthrough.ts +3 -0
- package/src/cli/kfc.ts +2 -2
- package/src/cli/monitor.ts +6 -6
- package/src/cli.ts +5 -5
- package/src/lib/assets/assets.ts +5 -1
- package/src/lib/assets/k8sObjects.ts +6 -6
- package/src/lib/assets/loader.ts +0 -6
- package/src/lib/assets/webhooks.ts +58 -9
- package/src/lib/assets/yaml/overridesFile.ts +29 -7
- package/src/lib/controller/index.ts +1 -0
- package/src/lib/types.ts +7 -0
- package/dist/cli/deploy.d.ts +0 -21
- package/dist/cli/deploy.d.ts.map +0 -1
- package/src/cli/deploy.ts +0 -170
|
@@ -113,15 +113,9 @@ export function checkIronBankImage(registry: string, image: string, peprVersion:
|
|
|
113
113
|
* @param imagePullSecret
|
|
114
114
|
* @returns boolean
|
|
115
115
|
*/
|
|
116
|
-
export function validImagePullSecret(imagePullSecretName: string):
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (sanitizeResourceName(imagePullSecretName) !== imagePullSecretName) {
|
|
120
|
-
// https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
|
|
121
|
-
console.error(error);
|
|
122
|
-
process.exit(1);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
116
|
+
export function validImagePullSecret(imagePullSecretName: string): boolean {
|
|
117
|
+
// https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
|
|
118
|
+
return sanitizeResourceName(imagePullSecretName) === imagePullSecretName;
|
|
125
119
|
}
|
|
126
120
|
|
|
127
121
|
/**
|
|
@@ -11,7 +11,7 @@ import { PeprConfig, Reloader } from "../types";
|
|
|
11
11
|
import { BuildContext } from "esbuild";
|
|
12
12
|
import { loadModule } from "./loadModule";
|
|
13
13
|
|
|
14
|
-
type BuildModuleReturn = {
|
|
14
|
+
export type BuildModuleReturn = {
|
|
15
15
|
ctx: BuildContext<BuildOptions>;
|
|
16
16
|
path: string;
|
|
17
17
|
cfg: PeprConfig;
|
package/src/cli/build/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
generateYamlAndWriteToDisk,
|
|
16
16
|
} from "./build.helpers";
|
|
17
17
|
import { buildModule } from "./buildModule";
|
|
18
|
+
import Log from "../../lib/telemetry/logger";
|
|
18
19
|
|
|
19
20
|
export default function (program: Command): void {
|
|
20
21
|
program
|
|
@@ -53,7 +54,7 @@ export default function (program: Command): void {
|
|
|
53
54
|
.option("-o, --output <directory>", "Set output directory.", "dist")
|
|
54
55
|
.addOption(
|
|
55
56
|
new Option(
|
|
56
|
-
"-r, --registry <
|
|
57
|
+
"-r, --registry <registry>",
|
|
57
58
|
"Container registry: Choose container registry for deployment manifests. Conflicts with --custom-image and --registry-info.",
|
|
58
59
|
)
|
|
59
60
|
.conflicts(["customImage", "registryInfo"])
|
|
@@ -99,8 +100,7 @@ export default function (program: Command): void {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
if (opts.registryInfo !== undefined) {
|
|
102
|
-
|
|
103
|
-
// for journey test to make sure the image is built
|
|
103
|
+
Log.info(`Including ${cfg.pepr.includedFiles.length} files in controller image.`);
|
|
104
104
|
|
|
105
105
|
// only actually build/push if there are files to include
|
|
106
106
|
await handleCustomImageBuild(
|
|
@@ -113,7 +113,7 @@ export default function (program: Command): void {
|
|
|
113
113
|
|
|
114
114
|
// If building without embedding, exit after building
|
|
115
115
|
if (!opts.embed) {
|
|
116
|
-
|
|
116
|
+
Log.info(`Module built successfully at ${path}`);
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -136,7 +136,11 @@ export default function (program: Command): void {
|
|
|
136
136
|
if (image !== "") assets.image = image;
|
|
137
137
|
|
|
138
138
|
// Ensure imagePullSecret is valid
|
|
139
|
-
validImagePullSecret(opts.withPullSecret)
|
|
139
|
+
if (!validImagePullSecret(opts.withPullSecret)) {
|
|
140
|
+
throw new Error(
|
|
141
|
+
"Invalid imagePullSecret. Please provide a valid name as defined in RFC 1123.",
|
|
142
|
+
);
|
|
143
|
+
}
|
|
140
144
|
|
|
141
145
|
handleValidCapabilityNames(assets.capabilities);
|
|
142
146
|
await generateYamlAndWriteToDisk({
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Assets } from "../../lib/assets/assets";
|
|
2
|
+
import { deployWebhook } from "../../lib/assets/deploy";
|
|
3
|
+
import { loadCapabilities } from "../../lib/assets/loader";
|
|
4
|
+
import { namespaceDeploymentsReady } from "../../lib/deploymentChecks";
|
|
5
|
+
import { namespaceComplianceValidator, validateCapabilityNames } from "../../lib/helpers";
|
|
6
|
+
import { CapabilityExport } from "../../lib/types";
|
|
7
|
+
import { buildModule } from "../build/buildModule";
|
|
8
|
+
|
|
9
|
+
export async function buildAndDeployModule(image: string, force: boolean): Promise<void> {
|
|
10
|
+
const builtModule = await buildModule("dist");
|
|
11
|
+
if (!builtModule) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Generate a secret for the module
|
|
16
|
+
const webhook = new Assets(
|
|
17
|
+
{ ...builtModule.cfg.pepr, description: builtModule.cfg.description },
|
|
18
|
+
builtModule.path,
|
|
19
|
+
[],
|
|
20
|
+
);
|
|
21
|
+
webhook.image = image ?? webhook.image;
|
|
22
|
+
const capabilities = await loadCapabilities(webhook.path);
|
|
23
|
+
for (const capability of capabilities) {
|
|
24
|
+
validateNamespaces(capability, webhook);
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
await webhook.deploy(deployWebhook, force, builtModule.cfg.pepr.webhookTimeout ?? 10);
|
|
28
|
+
|
|
29
|
+
// wait for capabilities to be loaded and test names
|
|
30
|
+
validateCapabilityNames(webhook.capabilities);
|
|
31
|
+
|
|
32
|
+
// Wait for the pepr-system resources to be fully up
|
|
33
|
+
await namespaceDeploymentsReady();
|
|
34
|
+
console.info(`Module deployed successfully`);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.error(`Error deploying module:`, e);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function validateNamespaces(capability: CapabilityExport, webhook: Assets): void {
|
|
41
|
+
namespaceComplianceValidator(capability, webhook.alwaysIgnore?.namespaces);
|
|
42
|
+
namespaceComplianceValidator(
|
|
43
|
+
capability,
|
|
44
|
+
webhook.config.admission?.alwaysIgnore?.namespaces,
|
|
45
|
+
false,
|
|
46
|
+
);
|
|
47
|
+
namespaceComplianceValidator(capability, webhook.config.watch?.alwaysIgnore?.namespaces, true);
|
|
48
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ImagePullSecret } from "../../lib/types";
|
|
2
|
+
import { sanitizeName } from "../init/utils";
|
|
3
|
+
|
|
4
|
+
export interface ImagePullSecretDetails {
|
|
5
|
+
pullSecret?: string;
|
|
6
|
+
dockerServer?: string;
|
|
7
|
+
dockerUsername?: string;
|
|
8
|
+
dockerEmail?: string;
|
|
9
|
+
dockerPassword?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function validateImagePullSecretDetails(details: ImagePullSecretDetails): {
|
|
13
|
+
valid: boolean;
|
|
14
|
+
error?: string;
|
|
15
|
+
} {
|
|
16
|
+
if (!details.pullSecret) {
|
|
17
|
+
return { valid: true };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
|
|
21
|
+
if (details.pullSecret !== sanitizeName(details.pullSecret)) {
|
|
22
|
+
return {
|
|
23
|
+
valid: false,
|
|
24
|
+
error: `Invalid --pullSecret. Must be valid name as defined in RFC 1123.`,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const missing: string[] = [];
|
|
29
|
+
if (!details.dockerEmail) {
|
|
30
|
+
missing.push("--docker-email");
|
|
31
|
+
}
|
|
32
|
+
if (!details.dockerServer) {
|
|
33
|
+
missing.push("--docker-server");
|
|
34
|
+
}
|
|
35
|
+
if (!details.dockerUsername) {
|
|
36
|
+
missing.push("--docker-username");
|
|
37
|
+
}
|
|
38
|
+
if (!details.dockerPassword) {
|
|
39
|
+
missing.push("--docker-password");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (missing.length > 0) {
|
|
43
|
+
return {
|
|
44
|
+
valid: false,
|
|
45
|
+
error: `Error: Must provide ${missing.join(", ")} when providing --pull-secret`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { valid: true };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type ValidatedImagePullSecretDetails = Required<ImagePullSecretDetails>;
|
|
53
|
+
|
|
54
|
+
export function generateImagePullSecret(details: ValidatedImagePullSecretDetails): ImagePullSecret {
|
|
55
|
+
const auth = Buffer.from(`${details.dockerUsername}:${details.dockerPassword}`).toString(
|
|
56
|
+
"base64",
|
|
57
|
+
);
|
|
58
|
+
return {
|
|
59
|
+
auths: {
|
|
60
|
+
[details.dockerServer]: {
|
|
61
|
+
username: details.dockerUsername,
|
|
62
|
+
password: details.dockerPassword,
|
|
63
|
+
email: details.dockerEmail,
|
|
64
|
+
auth,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
|
+
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { deployImagePullSecret } from "../../lib/assets/deploy";
|
|
6
|
+
import { validateImagePullSecretDetails, generateImagePullSecret } from "./imagePullSecret";
|
|
7
|
+
import { getUserConfirmation } from "./userConfirmation";
|
|
8
|
+
import { buildAndDeployModule } from "./buildAndDeploy";
|
|
9
|
+
|
|
10
|
+
export default function (program: Command): void {
|
|
11
|
+
program
|
|
12
|
+
.command("deploy")
|
|
13
|
+
.description("Deploy a Pepr Module")
|
|
14
|
+
.option("-E, --docker-email <email>", "Email for Docker registry.")
|
|
15
|
+
.option("-P, --docker-password <password>", "Password for Docker registry.")
|
|
16
|
+
.option("-S, --docker-server <server>", "Docker server address.")
|
|
17
|
+
.option("-U, --docker-username <username>", "Docker registry username.")
|
|
18
|
+
.option("-f, --force", "Force deploy the module, override manager field.")
|
|
19
|
+
.option("-i, --image <image>", "Override the image tag.")
|
|
20
|
+
.option("-p, --pull-secret <name>", "Deploy imagePullSecret for Controller private registry.")
|
|
21
|
+
.option("-y, --yes", "Skip confirmation prompts.")
|
|
22
|
+
.action(async opts => {
|
|
23
|
+
const valResp = validateImagePullSecretDetails(opts);
|
|
24
|
+
if (!valResp.valid) {
|
|
25
|
+
console.error(valResp.error);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (opts.pullSecret) {
|
|
30
|
+
await deployImagePullSecret(generateImagePullSecret(opts), opts.pullSecret);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!(await getUserConfirmation(opts))) {
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await buildAndDeployModule(opts.image, opts.force);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import prompt from "prompts";
|
|
2
|
+
|
|
3
|
+
export async function getUserConfirmation(opts: { yes: boolean }): Promise<boolean> {
|
|
4
|
+
if (opts.yes) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Prompt the user to confirm
|
|
9
|
+
const confirmation = await prompt({
|
|
10
|
+
type: "confirm",
|
|
11
|
+
name: "yes",
|
|
12
|
+
message: "This will remove and redeploy the module. Continue?",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return confirmation.yes ? true : false;
|
|
16
|
+
}
|
package/src/cli/dev.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { loadModule } from "./build/loadModule";
|
|
|
12
12
|
import { deployWebhook } from "../lib/assets/deploy";
|
|
13
13
|
import { promises as fs } from "fs";
|
|
14
14
|
import { validateCapabilityNames } from "../lib/helpers";
|
|
15
|
+
import Log from "../lib/telemetry/logger";
|
|
15
16
|
|
|
16
17
|
export default function (program: Command): void {
|
|
17
18
|
program
|
|
@@ -61,7 +62,7 @@ export default function (program: Command): void {
|
|
|
61
62
|
|
|
62
63
|
// Run the processed javascript file
|
|
63
64
|
const runFork = async (): Promise<void> => {
|
|
64
|
-
|
|
65
|
+
Log.info(`Running module ${path}`);
|
|
65
66
|
|
|
66
67
|
// Deploy the webhook with a 30 second timeout for debugging, don't force
|
|
67
68
|
await webhook.deploy(deployWebhook, false, 30);
|
|
@@ -70,7 +71,7 @@ export default function (program: Command): void {
|
|
|
70
71
|
// wait for capabilities to be loaded and test names
|
|
71
72
|
validateCapabilityNames(webhook.capabilities);
|
|
72
73
|
} catch (error) {
|
|
73
|
-
|
|
74
|
+
Log.error(
|
|
74
75
|
`CapabilityValidation Error - Unable to valide capability name(s) in: '${webhook.capabilities.map(item => item.name)}'\n${error}`,
|
|
75
76
|
);
|
|
76
77
|
process.exit(1);
|
|
@@ -100,13 +101,13 @@ export default function (program: Command): void {
|
|
|
100
101
|
|
|
101
102
|
// listen for CTRL+C and remove webhooks
|
|
102
103
|
process.on("SIGINT", () => {
|
|
103
|
-
|
|
104
|
+
Log.debug(`Received SIGINT, removing webhooks`);
|
|
104
105
|
});
|
|
105
106
|
};
|
|
106
107
|
|
|
107
108
|
await buildModule("dist", async r => {
|
|
108
109
|
if (r.errors.length > 0) {
|
|
109
|
-
|
|
110
|
+
Log.error(`Error compiling module: ${r.errors}`);
|
|
110
111
|
return;
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -118,7 +119,7 @@ export default function (program: Command): void {
|
|
|
118
119
|
}
|
|
119
120
|
});
|
|
120
121
|
} catch (e) {
|
|
121
|
-
|
|
122
|
+
Log.error(`Error deploying module:`, e);
|
|
122
123
|
process.exit(1);
|
|
123
124
|
}
|
|
124
125
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
|
+
|
|
4
|
+
import { resolve } from "path/posix";
|
|
5
|
+
import {
|
|
6
|
+
peprPackageJSON,
|
|
7
|
+
gitignore,
|
|
8
|
+
eslint,
|
|
9
|
+
prettier,
|
|
10
|
+
readme,
|
|
11
|
+
tsConfig,
|
|
12
|
+
peprTSTemplate,
|
|
13
|
+
snippet,
|
|
14
|
+
codeSettings,
|
|
15
|
+
samplesYaml,
|
|
16
|
+
helloPepr,
|
|
17
|
+
} from "./templates";
|
|
18
|
+
import { write } from "./utils";
|
|
19
|
+
|
|
20
|
+
export async function createProjectFiles(
|
|
21
|
+
dirName: string,
|
|
22
|
+
packageJSON: peprPackageJSON,
|
|
23
|
+
): Promise<void> {
|
|
24
|
+
const files = [
|
|
25
|
+
{ path: gitignore.path, data: gitignore.data },
|
|
26
|
+
{ path: eslint.path, data: eslint.data },
|
|
27
|
+
{ path: prettier.path, data: prettier.data },
|
|
28
|
+
{ path: packageJSON.path, data: packageJSON.data },
|
|
29
|
+
{ path: readme.path, data: readme.data },
|
|
30
|
+
{ path: tsConfig.path, data: tsConfig.data },
|
|
31
|
+
{ path: peprTSTemplate.path, data: peprTSTemplate.data },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const nestedFiles = [
|
|
35
|
+
{ dir: ".vscode", path: snippet.path, data: snippet.data },
|
|
36
|
+
{ dir: ".vscode", path: codeSettings.path, data: codeSettings.data },
|
|
37
|
+
{ dir: "capabilities", path: samplesYaml.path, data: samplesYaml.data },
|
|
38
|
+
{ dir: "capabilities", path: helloPepr.path, data: helloPepr.data },
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
for (const file of files) {
|
|
42
|
+
await write(resolve(dirName, file.path), file.data);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (const file of nestedFiles) {
|
|
46
|
+
await write(resolve(dirName, file.dir, file.path), file.data);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
|
+
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
|
+
import Log from "../../lib/telemetry/logger";
|
|
6
|
+
export const doPostInitActions = (dirName: string): void => {
|
|
7
|
+
// run npm install from the new directory
|
|
8
|
+
process.chdir(dirName);
|
|
9
|
+
execSync("npm install", {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// setup git
|
|
14
|
+
execSync("git init --initial-branch=main", {
|
|
15
|
+
stdio: "inherit",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// try to open vscode
|
|
19
|
+
try {
|
|
20
|
+
execSync("code .", {
|
|
21
|
+
stdio: "inherit",
|
|
22
|
+
});
|
|
23
|
+
} catch {
|
|
24
|
+
Log.warn("VSCode was not found, IDE will not automatically open.");
|
|
25
|
+
}
|
|
26
|
+
};
|
package/src/cli/init/index.ts
CHANGED
|
@@ -1,35 +1,23 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
3
|
|
|
4
|
-
import { execSync } from "child_process";
|
|
5
|
-
import { resolve } from "path";
|
|
6
|
-
|
|
7
4
|
import { Command } from "commander";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
eslint,
|
|
11
|
-
peprTSTemplate,
|
|
12
|
-
genPkgJSON,
|
|
13
|
-
gitignore,
|
|
14
|
-
helloPepr,
|
|
15
|
-
peprPackageJSON,
|
|
16
|
-
prettier,
|
|
17
|
-
readme,
|
|
18
|
-
samplesYaml,
|
|
19
|
-
snippet,
|
|
20
|
-
tsConfig,
|
|
21
|
-
} from "./templates";
|
|
22
|
-
import { createDir, sanitizeName, write } from "./utils";
|
|
5
|
+
import { peprTSTemplate, genPkgJSON } from "./templates";
|
|
6
|
+
import { sanitizeName } from "./utils";
|
|
23
7
|
import { confirm, PromptOptions, walkthrough } from "./walkthrough";
|
|
24
8
|
import { ErrorList } from "../../lib/errors";
|
|
25
9
|
import { UUID_LENGTH_LIMIT } from "./enums";
|
|
26
10
|
import { Option } from "commander";
|
|
11
|
+
import { setupProjectStructure } from "./setupProjectStructure";
|
|
12
|
+
import { doPostInitActions } from "./doPostInitActions";
|
|
13
|
+
import { createProjectFiles } from "./createProjectFiles";
|
|
14
|
+
import { v4 as uuidv4 } from "uuid";
|
|
15
|
+
import Log from "../../lib/telemetry/logger";
|
|
27
16
|
|
|
28
|
-
export default function (
|
|
17
|
+
export default function (): Command {
|
|
29
18
|
let response = {} as PromptOptions;
|
|
30
19
|
|
|
31
|
-
|
|
32
|
-
.command("init")
|
|
20
|
+
return new Command("init")
|
|
33
21
|
.description("Initialize a new Pepr Module")
|
|
34
22
|
.option("-d, --description <string>", "Explain the purpose of the new module.")
|
|
35
23
|
.addOption(
|
|
@@ -41,6 +29,10 @@ export default function (program: Command): void {
|
|
|
41
29
|
"-u, --uuid <string>",
|
|
42
30
|
"Unique identifier for your module with a max length of 36 characters.",
|
|
43
31
|
(uuid: string): string => {
|
|
32
|
+
if (typeof uuid === "undefined" || uuid === "") {
|
|
33
|
+
uuid = uuidv4();
|
|
34
|
+
Log.warn(`The UUID was empty. Generated new UUID: '${uuid}'`);
|
|
35
|
+
}
|
|
44
36
|
if (uuid.length > UUID_LENGTH_LIMIT) {
|
|
45
37
|
throw new Error("The UUID must be 36 characters or fewer.");
|
|
46
38
|
}
|
|
@@ -59,7 +51,7 @@ export default function (program: Command): void {
|
|
|
59
51
|
const confirmed = await confirm(dirName, packageJSON, peprTSTemplate.path, opts.yes);
|
|
60
52
|
|
|
61
53
|
if (confirmed) {
|
|
62
|
-
|
|
54
|
+
Log.info("Creating new Pepr module...");
|
|
63
55
|
|
|
64
56
|
try {
|
|
65
57
|
await setupProjectStructure(dirName);
|
|
@@ -69,69 +61,11 @@ export default function (program: Command): void {
|
|
|
69
61
|
doPostInitActions(dirName);
|
|
70
62
|
}
|
|
71
63
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
} catch (
|
|
75
|
-
|
|
76
|
-
console.error(`Error creating Pepr module:`, e);
|
|
77
|
-
}
|
|
78
|
-
process.exit(1);
|
|
64
|
+
Log.info(`New Pepr module created at ${dirName}`);
|
|
65
|
+
Log.info(`Open VSCode or your editor of choice in ${dirName} to get started!`);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw new Error(`Error creating Pepr module:`, { cause: error });
|
|
79
68
|
}
|
|
80
69
|
}
|
|
81
70
|
});
|
|
82
71
|
}
|
|
83
|
-
|
|
84
|
-
async function setupProjectStructure(dirName: string): Promise<void> {
|
|
85
|
-
await createDir(dirName);
|
|
86
|
-
await createDir(resolve(dirName, ".vscode"));
|
|
87
|
-
await createDir(resolve(dirName, "capabilities"));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async function createProjectFiles(dirName: string, packageJSON: peprPackageJSON): Promise<void> {
|
|
91
|
-
const files = [
|
|
92
|
-
{ path: gitignore.path, data: gitignore.data },
|
|
93
|
-
{ path: eslint.path, data: eslint.data },
|
|
94
|
-
{ path: prettier.path, data: prettier.data },
|
|
95
|
-
{ path: packageJSON.path, data: packageJSON.data },
|
|
96
|
-
{ path: readme.path, data: readme.data },
|
|
97
|
-
{ path: tsConfig.path, data: tsConfig.data },
|
|
98
|
-
{ path: peprTSTemplate.path, data: peprTSTemplate.data },
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
const nestedFiles = [
|
|
102
|
-
{ dir: ".vscode", path: snippet.path, data: snippet.data },
|
|
103
|
-
{ dir: ".vscode", path: codeSettings.path, data: codeSettings.data },
|
|
104
|
-
{ dir: "capabilities", path: samplesYaml.path, data: samplesYaml.data },
|
|
105
|
-
{ dir: "capabilities", path: helloPepr.path, data: helloPepr.data },
|
|
106
|
-
];
|
|
107
|
-
|
|
108
|
-
for (const file of files) {
|
|
109
|
-
await write(resolve(dirName, file.path), file.data);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
for (const file of nestedFiles) {
|
|
113
|
-
await write(resolve(dirName, file.dir, file.path), file.data);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const doPostInitActions = (dirName: string): void => {
|
|
118
|
-
// run npm install from the new directory
|
|
119
|
-
process.chdir(dirName);
|
|
120
|
-
execSync("npm install", {
|
|
121
|
-
stdio: "inherit",
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// setup git
|
|
125
|
-
execSync("git init --initial-branch=main", {
|
|
126
|
-
stdio: "inherit",
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// try to open vscode
|
|
130
|
-
try {
|
|
131
|
-
execSync("code .", {
|
|
132
|
-
stdio: "inherit",
|
|
133
|
-
});
|
|
134
|
-
} catch {
|
|
135
|
-
console.warn("VSCode was not found, IDE will not automatically open.");
|
|
136
|
-
}
|
|
137
|
-
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createDir } from "./utils";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
|
|
4
|
+
export async function setupProjectStructure(dirName: string): Promise<void> {
|
|
5
|
+
await createDir(dirName);
|
|
6
|
+
await createDir(resolve(dirName, ".vscode"));
|
|
7
|
+
await createDir(resolve(dirName, "capabilities"));
|
|
8
|
+
}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import { dumpYaml } from "@kubernetes/client-node";
|
|
5
5
|
import { inspect } from "util";
|
|
6
|
-
import { v4 as uuidv4 } from "uuid";
|
|
7
6
|
import { readFileSync } from "fs";
|
|
8
7
|
import path from "path";
|
|
9
8
|
|
|
@@ -50,8 +49,7 @@ export type peprPackageJSON = {
|
|
|
50
49
|
};
|
|
51
50
|
|
|
52
51
|
export function genPkgJSON(opts: InitOptions): peprPackageJSON {
|
|
53
|
-
|
|
54
|
-
const uuid = !opts.uuid ? uuidv4() : opts.uuid;
|
|
52
|
+
const uuid = opts.uuid;
|
|
55
53
|
// Generate a name for the module based on the module name
|
|
56
54
|
const name = sanitizeName(opts.name);
|
|
57
55
|
// Make typescript a dev dependency
|
|
@@ -91,7 +89,7 @@ export function genPkgJSON(opts: InitOptions): peprPackageJSON {
|
|
|
91
89
|
env: {},
|
|
92
90
|
},
|
|
93
91
|
scripts: {
|
|
94
|
-
"k3d-setup": scripts["
|
|
92
|
+
"k3d-setup": scripts["cluster:k3d"],
|
|
95
93
|
},
|
|
96
94
|
dependencies: {
|
|
97
95
|
pepr: version,
|
|
@@ -33,6 +33,9 @@ async function setUUID(uuid?: string): Promise<Answers<string>> {
|
|
|
33
33
|
name: "uuid",
|
|
34
34
|
message: "Enter a unique identifier for the new Pepr module.\n",
|
|
35
35
|
validate: (val: string) => {
|
|
36
|
+
if (typeof val === "undefined" || val === "") {
|
|
37
|
+
return "The UUID must be at least 1 character long";
|
|
38
|
+
}
|
|
36
39
|
return (
|
|
37
40
|
val.length <= UUID_LENGTH_LIMIT ||
|
|
38
41
|
`The UUID must be ${UUID_LENGTH_LIMIT} characters or fewer.`
|
package/src/cli/kfc.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { execSync } from "child_process";
|
|
5
5
|
import prompt from "prompts";
|
|
6
|
-
|
|
6
|
+
import Log from "../lib/telemetry/logger";
|
|
7
7
|
import { Command } from "commander";
|
|
8
8
|
|
|
9
9
|
export default function (program: Command): void {
|
|
@@ -42,7 +42,7 @@ export default function (program: Command): void {
|
|
|
42
42
|
stdio: "inherit",
|
|
43
43
|
});
|
|
44
44
|
} catch (e) {
|
|
45
|
-
|
|
45
|
+
Log.error(`Error creating CRD generated class:`, e);
|
|
46
46
|
process.exit(1);
|
|
47
47
|
}
|
|
48
48
|
});
|
package/src/cli/monitor.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { K8s, kind } from "kubernetes-fluent-client";
|
|
|
6
6
|
import stream from "stream";
|
|
7
7
|
import { ResponseItem } from "../lib/types";
|
|
8
8
|
import { Command } from "commander";
|
|
9
|
-
|
|
9
|
+
import Log from "../lib/telemetry/logger";
|
|
10
10
|
interface LogPayload {
|
|
11
11
|
namespace: string;
|
|
12
12
|
name: string;
|
|
@@ -39,7 +39,7 @@ export default function (program: Command): void {
|
|
|
39
39
|
const podNames: string[] = pods.items.flatMap(pod => pod.metadata!.name || "");
|
|
40
40
|
|
|
41
41
|
if (podNames.length < 1) {
|
|
42
|
-
|
|
42
|
+
Log.error(errorMessage);
|
|
43
43
|
process.exit(1);
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -122,9 +122,9 @@ export function processMutateLog(payload: LogPayload, name: string, uid: string)
|
|
|
122
122
|
const patchType = payload.res.patchType || payload.res.warnings || "";
|
|
123
123
|
const allowOrDeny = payload.res.allowed ? "🔀" : "🚫";
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
Log.info(`\n${allowOrDeny} MUTATE ${name} (${uid})`);
|
|
126
126
|
if (patchType.length > 0) {
|
|
127
|
-
|
|
127
|
+
Log.info(`\n\u001b[1;34m${patch}\u001b[0m`);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -135,8 +135,8 @@ export function processValidateLog(payload: LogPayload, name: string, uid: strin
|
|
|
135
135
|
.filter((r: ResponseItem) => !r.allowed)
|
|
136
136
|
.map((r: ResponseItem) => r.status?.message || "");
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
Log.info(`\n${filteredFailures.length > 0 ? "❌" : "✅"} VALIDATE ${name} (${uid})`);
|
|
139
139
|
if (filteredFailures.length > 0) {
|
|
140
|
-
|
|
140
|
+
Log.info(`\u001b[1;31m${filteredFailures}\u001b[0m`);
|
|
141
141
|
}
|
|
142
142
|
}
|
package/src/cli.ts
CHANGED
|
@@ -16,9 +16,9 @@ import { Command } from "commander";
|
|
|
16
16
|
import update from "./cli/update";
|
|
17
17
|
import kfc from "./cli/kfc";
|
|
18
18
|
import crd from "./cli/crd";
|
|
19
|
-
|
|
19
|
+
import Log from "./lib/telemetry/logger";
|
|
20
20
|
if (process.env.npm_lifecycle_event !== "npx") {
|
|
21
|
-
|
|
21
|
+
Log.info("Pepr should be run via `npx pepr <command>` instead of `pepr <command>`.");
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const program = new Command();
|
|
@@ -30,18 +30,18 @@ program
|
|
|
30
30
|
.version(version)
|
|
31
31
|
.description(`Pepr (v${version}) - Type safe K8s middleware for humans`)
|
|
32
32
|
.addCommand(crd())
|
|
33
|
+
.addCommand(init())
|
|
33
34
|
.action(() => {
|
|
34
35
|
if (program.args.length < 1) {
|
|
35
|
-
|
|
36
|
+
Log.info(banner);
|
|
36
37
|
program.help();
|
|
37
38
|
} else {
|
|
38
|
-
|
|
39
|
+
Log.error(`Invalid command '${program.args.join(" ")}'\n`);
|
|
39
40
|
program.outputHelp();
|
|
40
41
|
process.exitCode = 1;
|
|
41
42
|
}
|
|
42
43
|
});
|
|
43
44
|
|
|
44
|
-
init(program);
|
|
45
45
|
build(program);
|
|
46
46
|
deploy(program);
|
|
47
47
|
dev(program);
|