pepr 0.52.3-nightly.0 → 0.52.3-nightly.10
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/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 +3 -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 +187 -206
- package/dist/controller.js +1 -1
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib.js +1 -0
- package/dist/lib.js.map +2 -2
- package/package.json +8 -14
- 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/init/createProjectFiles.ts +45 -0
- package/src/cli/init/doPostInitActions.ts +23 -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.ts +1 -1
- package/src/lib/assets/k8sObjects.ts +6 -6
- package/src/lib/assets/yaml/overridesFile.ts +6 -6
- package/src/lib/controller/index.ts +1 -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
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { resolve } from "path/posix";
|
|
2
|
+
import {
|
|
3
|
+
peprPackageJSON,
|
|
4
|
+
gitignore,
|
|
5
|
+
eslint,
|
|
6
|
+
prettier,
|
|
7
|
+
readme,
|
|
8
|
+
tsConfig,
|
|
9
|
+
peprTSTemplate,
|
|
10
|
+
snippet,
|
|
11
|
+
codeSettings,
|
|
12
|
+
samplesYaml,
|
|
13
|
+
helloPepr,
|
|
14
|
+
} from "./templates";
|
|
15
|
+
import { write } from "./utils";
|
|
16
|
+
|
|
17
|
+
export async function createProjectFiles(
|
|
18
|
+
dirName: string,
|
|
19
|
+
packageJSON: peprPackageJSON,
|
|
20
|
+
): Promise<void> {
|
|
21
|
+
const files = [
|
|
22
|
+
{ path: gitignore.path, data: gitignore.data },
|
|
23
|
+
{ path: eslint.path, data: eslint.data },
|
|
24
|
+
{ path: prettier.path, data: prettier.data },
|
|
25
|
+
{ path: packageJSON.path, data: packageJSON.data },
|
|
26
|
+
{ path: readme.path, data: readme.data },
|
|
27
|
+
{ path: tsConfig.path, data: tsConfig.data },
|
|
28
|
+
{ path: peprTSTemplate.path, data: peprTSTemplate.data },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const nestedFiles = [
|
|
32
|
+
{ dir: ".vscode", path: snippet.path, data: snippet.data },
|
|
33
|
+
{ dir: ".vscode", path: codeSettings.path, data: codeSettings.data },
|
|
34
|
+
{ dir: "capabilities", path: samplesYaml.path, data: samplesYaml.data },
|
|
35
|
+
{ dir: "capabilities", path: helloPepr.path, data: helloPepr.data },
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
await write(resolve(dirName, file.path), file.data);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (const file of nestedFiles) {
|
|
43
|
+
await write(resolve(dirName, file.dir, file.path), file.data);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
|
|
3
|
+
export const doPostInitActions = (dirName: string): void => {
|
|
4
|
+
// run npm install from the new directory
|
|
5
|
+
process.chdir(dirName);
|
|
6
|
+
execSync("npm install", {
|
|
7
|
+
stdio: "inherit",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// setup git
|
|
11
|
+
execSync("git init --initial-branch=main", {
|
|
12
|
+
stdio: "inherit",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// try to open vscode
|
|
16
|
+
try {
|
|
17
|
+
execSync("code .", {
|
|
18
|
+
stdio: "inherit",
|
|
19
|
+
});
|
|
20
|
+
} catch {
|
|
21
|
+
console.warn("VSCode was not found, IDE will not automatically open.");
|
|
22
|
+
}
|
|
23
|
+
};
|
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.ts
CHANGED
|
@@ -30,6 +30,7 @@ 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
|
console.log(banner);
|
|
@@ -41,7 +42,6 @@ program
|
|
|
41
42
|
}
|
|
42
43
|
});
|
|
43
44
|
|
|
44
|
-
init(program);
|
|
45
45
|
build(program);
|
|
46
46
|
deploy(program);
|
|
47
47
|
dev(program);
|
|
@@ -85,9 +85,9 @@ export function getWatcher(
|
|
|
85
85
|
serviceAccountName: name,
|
|
86
86
|
securityContext: {
|
|
87
87
|
runAsUser: image.includes("private") ? 1000 : 65532,
|
|
88
|
-
runAsGroup: 65532,
|
|
88
|
+
runAsGroup: image.includes("private") ? 1000 : 65532,
|
|
89
89
|
runAsNonRoot: true,
|
|
90
|
-
fsGroup: 65532,
|
|
90
|
+
fsGroup: image.includes("private") ? 1000 : 65532,
|
|
91
91
|
},
|
|
92
92
|
containers: [
|
|
93
93
|
{
|
|
@@ -128,7 +128,7 @@ export function getWatcher(
|
|
|
128
128
|
},
|
|
129
129
|
securityContext: {
|
|
130
130
|
runAsUser: image.includes("private") ? 1000 : 65532,
|
|
131
|
-
runAsGroup: 65532,
|
|
131
|
+
runAsGroup: image.includes("private") ? 1000 : 65532,
|
|
132
132
|
runAsNonRoot: true,
|
|
133
133
|
allowPrivilegeEscalation: false,
|
|
134
134
|
capabilities: {
|
|
@@ -228,9 +228,9 @@ export function getDeployment(
|
|
|
228
228
|
serviceAccountName: name,
|
|
229
229
|
securityContext: {
|
|
230
230
|
runAsUser: image.includes("private") ? 1000 : 65532,
|
|
231
|
-
runAsGroup: 65532,
|
|
231
|
+
runAsGroup: image.includes("private") ? 1000 : 65532,
|
|
232
232
|
runAsNonRoot: true,
|
|
233
|
-
fsGroup: 65532,
|
|
233
|
+
fsGroup: image.includes("private") ? 1000 : 65532,
|
|
234
234
|
},
|
|
235
235
|
containers: [
|
|
236
236
|
{
|
|
@@ -272,7 +272,7 @@ export function getDeployment(
|
|
|
272
272
|
env: genEnv(config),
|
|
273
273
|
securityContext: {
|
|
274
274
|
runAsUser: image.includes("private") ? 1000 : 65532,
|
|
275
|
-
runAsGroup: 65532,
|
|
275
|
+
runAsGroup: image.includes("private") ? 1000 : 65532,
|
|
276
276
|
runAsNonRoot: true,
|
|
277
277
|
allowPrivilegeEscalation: false,
|
|
278
278
|
capabilities: {
|
|
@@ -60,9 +60,9 @@ export async function overridesFile(
|
|
|
60
60
|
},
|
|
61
61
|
securityContext: {
|
|
62
62
|
runAsUser: image.includes("private") ? 1000 : 65532,
|
|
63
|
-
runAsGroup: 65532,
|
|
63
|
+
runAsGroup: image.includes("private") ? 1000 : 65532,
|
|
64
64
|
runAsNonRoot: true,
|
|
65
|
-
fsGroup: 65532,
|
|
65
|
+
fsGroup: image.includes("private") ? 1000 : 65532,
|
|
66
66
|
},
|
|
67
67
|
readinessProbe: {
|
|
68
68
|
httpGet: {
|
|
@@ -92,7 +92,7 @@ export async function overridesFile(
|
|
|
92
92
|
},
|
|
93
93
|
containerSecurityContext: {
|
|
94
94
|
runAsUser: image.includes("private") ? 1000 : 65532,
|
|
95
|
-
runAsGroup: 65532,
|
|
95
|
+
runAsGroup: image.includes("private") ? 1000 : 65532,
|
|
96
96
|
runAsNonRoot: true,
|
|
97
97
|
allowPrivilegeEscalation: false,
|
|
98
98
|
capabilities: {
|
|
@@ -128,9 +128,9 @@ export async function overridesFile(
|
|
|
128
128
|
},
|
|
129
129
|
securityContext: {
|
|
130
130
|
runAsUser: image.includes("private") ? 1000 : 65532,
|
|
131
|
-
runAsGroup: 65532,
|
|
131
|
+
runAsGroup: image.includes("private") ? 1000 : 65532,
|
|
132
132
|
runAsNonRoot: true,
|
|
133
|
-
fsGroup: 65532,
|
|
133
|
+
fsGroup: image.includes("private") ? 1000 : 65532,
|
|
134
134
|
},
|
|
135
135
|
readinessProbe: {
|
|
136
136
|
httpGet: {
|
|
@@ -160,7 +160,7 @@ export async function overridesFile(
|
|
|
160
160
|
},
|
|
161
161
|
containerSecurityContext: {
|
|
162
162
|
runAsUser: image.includes("private") ? 1000 : 65532,
|
|
163
|
-
runAsGroup: 65532,
|
|
163
|
+
runAsGroup: image.includes("private") ? 1000 : 65532,
|
|
164
164
|
runAsNonRoot: true,
|
|
165
165
|
allowPrivilegeEscalation: false,
|
|
166
166
|
capabilities: {
|
|
@@ -50,6 +50,7 @@ export class Controller {
|
|
|
50
50
|
const { beforeHook, afterHook, onReady } = hooks;
|
|
51
51
|
this.#config = config;
|
|
52
52
|
this.#capabilities = capabilities;
|
|
53
|
+
Log.info({ config }, "Controller configuration");
|
|
53
54
|
|
|
54
55
|
// Initialize the Pepr store for each capability
|
|
55
56
|
new StoreController(capabilities, `pepr-${config.uuid}-store`, () => {
|
package/dist/cli/deploy.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { CapabilityExport } from "../lib/types";
|
|
2
|
-
import { Assets } from "../lib/assets/assets";
|
|
3
|
-
import { Command } from "commander";
|
|
4
|
-
interface ImagePullSecretDetails {
|
|
5
|
-
pullSecret?: string;
|
|
6
|
-
dockerServer?: string;
|
|
7
|
-
dockerUsername?: string;
|
|
8
|
-
dockerEmail?: string;
|
|
9
|
-
dockerPassword?: string;
|
|
10
|
-
}
|
|
11
|
-
export declare function validateImagePullSecretDetails(details: ImagePullSecretDetails): {
|
|
12
|
-
valid: boolean;
|
|
13
|
-
error?: string;
|
|
14
|
-
};
|
|
15
|
-
export declare function getUserConfirmation(opts: {
|
|
16
|
-
yes: boolean;
|
|
17
|
-
}): Promise<boolean>;
|
|
18
|
-
export default function (program: Command): void;
|
|
19
|
-
export declare function validateNamespaces(capability: CapabilityExport, webhook: Assets): void;
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=deploy.d.ts.map
|
package/dist/cli/deploy.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/cli/deploy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,UAAU,sBAAsB;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,GAAG;IAC/E,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAmCA;AAoBD,wBAAsB,mBAAmB,CAAC,IAAI,EAAE;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAalF;AAkCD,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,OAAO,GAAG,IAAI,CA8B/C;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAQtF"}
|