pepr 0.26.2 → 0.27.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.js +517 -80
- package/dist/controller.js +1 -1
- package/dist/lib/assets/helm.d.ts +5 -0
- package/dist/lib/assets/helm.d.ts.map +1 -0
- package/dist/lib/assets/index.d.ts +4 -0
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/assets/pods.d.ts +9 -2
- package/dist/lib/assets/pods.d.ts.map +1 -1
- package/dist/lib/assets/yaml.d.ts +1 -0
- package/dist/lib/assets/yaml.d.ts.map +1 -1
- package/dist/lib/filter.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts +2 -0
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib.js +1 -1
- package/dist/lib.js.map +2 -2
- package/package.json +6 -6
- package/src/lib/assets/deploy.ts +2 -2
- package/src/lib/assets/helm.ts +199 -0
- package/src/lib/assets/index.ts +121 -4
- package/src/lib/assets/pods.ts +22 -12
- package/src/lib/assets/yaml.ts +116 -4
- package/src/lib/filter.ts +4 -1
- package/src/lib/helpers.ts +25 -0
- package/src/templates/package.json +3 -1
package/dist/cli.js
CHANGED
|
@@ -106,8 +106,8 @@ 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
|
|
110
|
-
var
|
|
109
|
+
var import_fs8 = require("fs");
|
|
110
|
+
var import_path2 = require("path");
|
|
111
111
|
|
|
112
112
|
// src/lib/included-files.ts
|
|
113
113
|
var import_fs = require("fs");
|
|
@@ -127,6 +127,7 @@ async function createDockerfile(version3, description, includedFiles) {
|
|
|
127
127
|
|
|
128
128
|
// src/lib/assets/index.ts
|
|
129
129
|
var import_crypto3 = __toESM(require("crypto"));
|
|
130
|
+
var import_client_node2 = require("@kubernetes/client-node");
|
|
130
131
|
|
|
131
132
|
// src/lib/tls.ts
|
|
132
133
|
var import_node_forge = __toESM(require("node-forge"));
|
|
@@ -404,7 +405,7 @@ async function namespaceDeploymentsReady(namespace2 = "pepr-system") {
|
|
|
404
405
|
if (ready) {
|
|
405
406
|
return ready;
|
|
406
407
|
}
|
|
407
|
-
await new Promise((
|
|
408
|
+
await new Promise((resolve5) => setTimeout(resolve5, 1e3));
|
|
408
409
|
}
|
|
409
410
|
logger_default.info(`All ${namespace2} deployments are ready`);
|
|
410
411
|
}
|
|
@@ -427,19 +428,48 @@ var parseTimeout = (value, previous) => {
|
|
|
427
428
|
}
|
|
428
429
|
return parsedValue;
|
|
429
430
|
};
|
|
431
|
+
function dedent(file) {
|
|
432
|
+
const lines = file.split("\n");
|
|
433
|
+
if (lines[0].trim() === "") {
|
|
434
|
+
lines.shift();
|
|
435
|
+
file = lines.join("\n");
|
|
436
|
+
}
|
|
437
|
+
const match = file.match(/^[ \t]*(?=\S)/gm);
|
|
438
|
+
const indent = match && Math.min(...match.map((el) => el.length));
|
|
439
|
+
if (indent && indent > 0) {
|
|
440
|
+
const re = new RegExp(`^[ \\t]{${indent}}`, "gm");
|
|
441
|
+
return file.replace(re, "");
|
|
442
|
+
}
|
|
443
|
+
return file;
|
|
444
|
+
}
|
|
445
|
+
function replaceString(str, stringA, stringB) {
|
|
446
|
+
const escapedStringA = stringA.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
447
|
+
const regExp = new RegExp(escapedStringA, "g");
|
|
448
|
+
return str.replace(regExp, stringB);
|
|
449
|
+
}
|
|
430
450
|
|
|
431
451
|
// src/lib/assets/pods.ts
|
|
432
452
|
function namespace(namespaceLabels) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
453
|
+
if (namespaceLabels) {
|
|
454
|
+
return {
|
|
455
|
+
apiVersion: "v1",
|
|
456
|
+
kind: "Namespace",
|
|
457
|
+
metadata: {
|
|
458
|
+
name: "pepr-system",
|
|
459
|
+
labels: namespaceLabels ?? {}
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
} else {
|
|
463
|
+
return {
|
|
464
|
+
apiVersion: "v1",
|
|
465
|
+
kind: "Namespace",
|
|
466
|
+
metadata: {
|
|
467
|
+
name: "pepr-system"
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
441
471
|
}
|
|
442
|
-
function watcher(assets, hash) {
|
|
472
|
+
function watcher(assets, hash, buildTimestamp) {
|
|
443
473
|
const { name: name2, image, capabilities, config } = assets;
|
|
444
474
|
let hasSchedule = false;
|
|
445
475
|
const app = `${name2}-watcher`;
|
|
@@ -483,7 +513,7 @@ function watcher(assets, hash) {
|
|
|
483
513
|
template: {
|
|
484
514
|
metadata: {
|
|
485
515
|
annotations: {
|
|
486
|
-
buildTimestamp: `${
|
|
516
|
+
buildTimestamp: `${buildTimestamp}`
|
|
487
517
|
},
|
|
488
518
|
labels: {
|
|
489
519
|
app,
|
|
@@ -576,7 +606,7 @@ function watcher(assets, hash) {
|
|
|
576
606
|
}
|
|
577
607
|
};
|
|
578
608
|
}
|
|
579
|
-
function deployment(assets, hash) {
|
|
609
|
+
function deployment(assets, hash, buildTimestamp) {
|
|
580
610
|
const { name: name2, image, config } = assets;
|
|
581
611
|
const app = name2;
|
|
582
612
|
return {
|
|
@@ -605,7 +635,7 @@ function deployment(assets, hash) {
|
|
|
605
635
|
template: {
|
|
606
636
|
metadata: {
|
|
607
637
|
annotations: {
|
|
608
|
-
buildTimestamp: `${
|
|
638
|
+
buildTimestamp: `${buildTimestamp}`
|
|
609
639
|
},
|
|
610
640
|
labels: {
|
|
611
641
|
app,
|
|
@@ -1058,11 +1088,11 @@ async function setupController(assets, code, hash, force) {
|
|
|
1058
1088
|
const apiToken = apiTokenSecret(name2, assets.apiToken);
|
|
1059
1089
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(apiToken, { force });
|
|
1060
1090
|
logger_default.info("Applying deployment");
|
|
1061
|
-
const dep = deployment(assets, hash);
|
|
1091
|
+
const dep = deployment(assets, hash, assets.buildTimestamp);
|
|
1062
1092
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(dep, { force });
|
|
1063
1093
|
}
|
|
1064
1094
|
async function setupWatcher(assets, hash, force) {
|
|
1065
|
-
const watchDeployment = watcher(assets, hash);
|
|
1095
|
+
const watchDeployment = watcher(assets, hash, assets.buildTimestamp);
|
|
1066
1096
|
if (watchDeployment) {
|
|
1067
1097
|
logger_default.info("Applying watcher deployment");
|
|
1068
1098
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(watchDeployment, { force });
|
|
@@ -1075,7 +1105,7 @@ async function setupWatcher(assets, hash, force) {
|
|
|
1075
1105
|
// src/lib/assets/loader.ts
|
|
1076
1106
|
var import_child_process = require("child_process");
|
|
1077
1107
|
function loadCapabilities(path) {
|
|
1078
|
-
return new Promise((
|
|
1108
|
+
return new Promise((resolve5, reject) => {
|
|
1079
1109
|
const program2 = (0, import_child_process.fork)(path, {
|
|
1080
1110
|
env: {
|
|
1081
1111
|
...process.env,
|
|
@@ -1088,7 +1118,7 @@ function loadCapabilities(path) {
|
|
|
1088
1118
|
for (const capability of capabilities) {
|
|
1089
1119
|
console.info(`Registered Pepr Capability "${capability.name}"`);
|
|
1090
1120
|
}
|
|
1091
|
-
|
|
1121
|
+
resolve5(capabilities);
|
|
1092
1122
|
});
|
|
1093
1123
|
program2.on("error", (error) => {
|
|
1094
1124
|
reject(error);
|
|
@@ -1100,6 +1130,116 @@ function loadCapabilities(path) {
|
|
|
1100
1130
|
var import_client_node = require("@kubernetes/client-node");
|
|
1101
1131
|
var import_crypto2 = __toESM(require("crypto"));
|
|
1102
1132
|
var import_fs4 = require("fs");
|
|
1133
|
+
async function overridesFile({ hash, name: name2, image, config, apiToken }, path) {
|
|
1134
|
+
const overrides = {
|
|
1135
|
+
secrets: {
|
|
1136
|
+
apiToken: Buffer.from(apiToken).toString("base64")
|
|
1137
|
+
},
|
|
1138
|
+
hash,
|
|
1139
|
+
namespace: {
|
|
1140
|
+
annotations: {},
|
|
1141
|
+
labels: {
|
|
1142
|
+
"pepr.dev": ""
|
|
1143
|
+
}
|
|
1144
|
+
},
|
|
1145
|
+
uuid: name2,
|
|
1146
|
+
admission: {
|
|
1147
|
+
failurePolicy: config.onError === "reject" ? "Fail" : "Ignore",
|
|
1148
|
+
webhookTimeout: config.webhookTimeout,
|
|
1149
|
+
env: [
|
|
1150
|
+
{ name: "PEPR_WATCH_MODE", value: "false" },
|
|
1151
|
+
{ name: "PEPR_PRETTY_LOG", value: "false" },
|
|
1152
|
+
{ name: "LOG_LEVEL", value: "debug" },
|
|
1153
|
+
process.env.PEPR_MODE === "dev" && { name: "MY_CUSTOM_VAR", value: "example-value" },
|
|
1154
|
+
process.env.PEPR_MODE === "dev" && { name: "ZARF_VAR", value: "###ZARF_VAR_THING###" }
|
|
1155
|
+
],
|
|
1156
|
+
image,
|
|
1157
|
+
annotations: {
|
|
1158
|
+
"pepr.dev/description": `${config.description}` || ""
|
|
1159
|
+
},
|
|
1160
|
+
labels: {
|
|
1161
|
+
app: name2,
|
|
1162
|
+
"pepr.dev/controller": "admission",
|
|
1163
|
+
"pepr.dev/uuid": config.uuid
|
|
1164
|
+
},
|
|
1165
|
+
securityContext: {
|
|
1166
|
+
runAsUser: 65532,
|
|
1167
|
+
runAsGroup: 65532,
|
|
1168
|
+
runAsNonRoot: true,
|
|
1169
|
+
fsGroup: 65532
|
|
1170
|
+
},
|
|
1171
|
+
resources: {
|
|
1172
|
+
requests: {
|
|
1173
|
+
memory: "64Mi",
|
|
1174
|
+
cpu: "100m"
|
|
1175
|
+
},
|
|
1176
|
+
limits: {
|
|
1177
|
+
memory: "256Mi",
|
|
1178
|
+
cpu: "500m"
|
|
1179
|
+
}
|
|
1180
|
+
},
|
|
1181
|
+
containerSecurityContext: {
|
|
1182
|
+
runAsUser: 65532,
|
|
1183
|
+
runAsGroup: 65532,
|
|
1184
|
+
runAsNonRoot: true,
|
|
1185
|
+
allowPrivilegeEscalation: false,
|
|
1186
|
+
capabilities: {
|
|
1187
|
+
drop: ["ALL"]
|
|
1188
|
+
}
|
|
1189
|
+
},
|
|
1190
|
+
nodeSelector: {},
|
|
1191
|
+
tolerations: [],
|
|
1192
|
+
affinity: {}
|
|
1193
|
+
},
|
|
1194
|
+
watcher: {
|
|
1195
|
+
env: [
|
|
1196
|
+
{ name: "PEPR_WATCH_MODE", value: "true" },
|
|
1197
|
+
{ name: "PEPR_PRETTY_LOG", value: "false" },
|
|
1198
|
+
{ name: "LOG_LEVEL", value: "debug" },
|
|
1199
|
+
process.env.PEPR_MODE === "dev" && { name: "MY_CUSTOM_VAR", value: "example-value" },
|
|
1200
|
+
process.env.PEPR_MODE === "dev" && { name: "ZARF_VAR", value: "###ZARF_VAR_THING###" }
|
|
1201
|
+
],
|
|
1202
|
+
image,
|
|
1203
|
+
annotations: {
|
|
1204
|
+
"pepr.dev/description": `${config.description}` || ""
|
|
1205
|
+
},
|
|
1206
|
+
labels: {
|
|
1207
|
+
app: `${name2}-watcher`,
|
|
1208
|
+
"pepr.dev/controller": "watcher",
|
|
1209
|
+
"pepr.dev/uuid": config.uuid
|
|
1210
|
+
},
|
|
1211
|
+
securityContext: {
|
|
1212
|
+
runAsUser: 65532,
|
|
1213
|
+
runAsGroup: 65532,
|
|
1214
|
+
runAsNonRoot: true,
|
|
1215
|
+
fsGroup: 65532
|
|
1216
|
+
},
|
|
1217
|
+
resources: {
|
|
1218
|
+
requests: {
|
|
1219
|
+
memory: "64Mi",
|
|
1220
|
+
cpu: "100m"
|
|
1221
|
+
},
|
|
1222
|
+
limits: {
|
|
1223
|
+
memory: "256Mi",
|
|
1224
|
+
cpu: "500m"
|
|
1225
|
+
}
|
|
1226
|
+
},
|
|
1227
|
+
containerSecurityContext: {
|
|
1228
|
+
runAsUser: 65532,
|
|
1229
|
+
runAsGroup: 65532,
|
|
1230
|
+
runAsNonRoot: true,
|
|
1231
|
+
allowPrivilegeEscalation: false,
|
|
1232
|
+
capabilities: {
|
|
1233
|
+
drop: ["ALL"]
|
|
1234
|
+
}
|
|
1235
|
+
},
|
|
1236
|
+
nodeSelector: {},
|
|
1237
|
+
tolerations: [],
|
|
1238
|
+
affinity: {}
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
await import_fs4.promises.writeFile(path, (0, import_client_node.dumpYaml)(overrides, { noRefs: true, forceQuotes: true }));
|
|
1242
|
+
}
|
|
1103
1243
|
function zarfYaml({ name: name2, image, config }, path) {
|
|
1104
1244
|
const zarfCfg = {
|
|
1105
1245
|
kind: "ZarfPackageConfig",
|
|
@@ -1129,10 +1269,10 @@ function zarfYaml({ name: name2, image, config }, path) {
|
|
|
1129
1269
|
async function allYaml(assets, rbacMode) {
|
|
1130
1270
|
const { name: name2, tls, apiToken, path } = assets;
|
|
1131
1271
|
const code = await import_fs4.promises.readFile(path);
|
|
1132
|
-
|
|
1272
|
+
assets.hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
|
|
1133
1273
|
const mutateWebhook = await webhookConfig(assets, "mutate", assets.config.webhookTimeout);
|
|
1134
1274
|
const validateWebhook = await webhookConfig(assets, "validate", assets.config.webhookTimeout);
|
|
1135
|
-
const watchDeployment = watcher(assets, hash);
|
|
1275
|
+
const watchDeployment = watcher(assets, assets.hash, assets.buildTimestamp);
|
|
1136
1276
|
const resources = [
|
|
1137
1277
|
namespace(assets.config.customLabels?.namespace),
|
|
1138
1278
|
clusterRole(name2, assets.capabilities, rbacMode),
|
|
@@ -1140,10 +1280,10 @@ async function allYaml(assets, rbacMode) {
|
|
|
1140
1280
|
serviceAccount(name2),
|
|
1141
1281
|
apiTokenSecret(name2, apiToken),
|
|
1142
1282
|
tlsSecret(name2, tls),
|
|
1143
|
-
deployment(assets, hash),
|
|
1283
|
+
deployment(assets, assets.hash, assets.buildTimestamp),
|
|
1144
1284
|
service(name2),
|
|
1145
1285
|
watcherService(name2),
|
|
1146
|
-
moduleSecret(name2, code, hash),
|
|
1286
|
+
moduleSecret(name2, code, assets.hash),
|
|
1147
1287
|
storeRole(name2),
|
|
1148
1288
|
storeRoleBinding(name2)
|
|
1149
1289
|
];
|
|
@@ -1160,14 +1300,215 @@ async function allYaml(assets, rbacMode) {
|
|
|
1160
1300
|
}
|
|
1161
1301
|
|
|
1162
1302
|
// src/lib/assets/index.ts
|
|
1303
|
+
var import_path = require("path");
|
|
1304
|
+
|
|
1305
|
+
// src/lib/assets/helm.ts
|
|
1306
|
+
function nsTemplate() {
|
|
1307
|
+
return `
|
|
1308
|
+
apiVersion: v1
|
|
1309
|
+
kind: Namespace
|
|
1310
|
+
metadata:
|
|
1311
|
+
name: pepr-system
|
|
1312
|
+
{{- if .Values.namespace.annotations }}
|
|
1313
|
+
annotations:
|
|
1314
|
+
{{- toYaml .Values.namespace.annotations | nindent 6 }}
|
|
1315
|
+
{{- end }}
|
|
1316
|
+
{{- if .Values.namespace.labels }}
|
|
1317
|
+
labels:
|
|
1318
|
+
{{- toYaml .Values.namespace.labels | nindent 6 }}
|
|
1319
|
+
{{- end }}
|
|
1320
|
+
`;
|
|
1321
|
+
}
|
|
1322
|
+
function chartYaml(name2, description) {
|
|
1323
|
+
return `
|
|
1324
|
+
apiVersion: v2
|
|
1325
|
+
name: ${name2}
|
|
1326
|
+
description: ${description || ""}
|
|
1327
|
+
|
|
1328
|
+
# A chart can be either an 'application' or a 'library' chart.
|
|
1329
|
+
#
|
|
1330
|
+
# Application charts are a collection of templates that can be packaged into versioned archives
|
|
1331
|
+
# to be deployed.
|
|
1332
|
+
#
|
|
1333
|
+
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
|
1334
|
+
# a dependency of application charts to inject those utilities and functions into the rendering
|
|
1335
|
+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
|
1336
|
+
type: application
|
|
1337
|
+
|
|
1338
|
+
# This is the chart version. This version number should be incremented each time you make changes
|
|
1339
|
+
# to the chart and its templates, including the app version.
|
|
1340
|
+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
|
1341
|
+
version: 0.1.0
|
|
1342
|
+
|
|
1343
|
+
# This is the version number of the application being deployed. This version number should be
|
|
1344
|
+
# incremented each time you make changes to the application. Versions are not expected to
|
|
1345
|
+
# follow Semantic Versioning. They should reflect the version the application is using.
|
|
1346
|
+
# It is recommended to use it with quotes.
|
|
1347
|
+
appVersion: "1.16.0"
|
|
1348
|
+
`;
|
|
1349
|
+
}
|
|
1350
|
+
function watcherDeployTemplate(buildTimestamp) {
|
|
1351
|
+
return `
|
|
1352
|
+
apiVersion: apps/v1
|
|
1353
|
+
kind: Deployment
|
|
1354
|
+
metadata:
|
|
1355
|
+
name: {{ .Values.uuid }}-watcher
|
|
1356
|
+
namespace: pepr-system
|
|
1357
|
+
annotations:
|
|
1358
|
+
{{- toYaml .Values.watcher.annotations | nindent 4 }}
|
|
1359
|
+
labels:
|
|
1360
|
+
{{- toYaml .Values.watcher.labels | nindent 4 }}
|
|
1361
|
+
spec:
|
|
1362
|
+
replicas: 1
|
|
1363
|
+
strategy:
|
|
1364
|
+
type: Recreate
|
|
1365
|
+
selector:
|
|
1366
|
+
matchLabels:
|
|
1367
|
+
app: {{ .Values.uuid }}-watcher
|
|
1368
|
+
pepr.dev/controller: watcher
|
|
1369
|
+
template:
|
|
1370
|
+
metadata:
|
|
1371
|
+
annotations:
|
|
1372
|
+
buildTimestamp: "${buildTimestamp}"
|
|
1373
|
+
labels:
|
|
1374
|
+
app: {{ .Values.uuid }}-watcher
|
|
1375
|
+
pepr.dev/controller: watcher
|
|
1376
|
+
spec:
|
|
1377
|
+
serviceAccountName: {{ .Values.uuid }}
|
|
1378
|
+
securityContext:
|
|
1379
|
+
{{- toYaml .Values.admission.securityContext | nindent 8 }}
|
|
1380
|
+
containers:
|
|
1381
|
+
- name: watcher
|
|
1382
|
+
image: {{ .Values.watcher.image }}
|
|
1383
|
+
imagePullPolicy: IfNotPresent
|
|
1384
|
+
command:
|
|
1385
|
+
- node
|
|
1386
|
+
- /app/node_modules/pepr/dist/controller.js
|
|
1387
|
+
- {{ .Values.hash }}
|
|
1388
|
+
readinessProbe:
|
|
1389
|
+
httpGet:
|
|
1390
|
+
path: /healthz
|
|
1391
|
+
port: 3000
|
|
1392
|
+
scheme: HTTPS
|
|
1393
|
+
livenessProbe:
|
|
1394
|
+
httpGet:
|
|
1395
|
+
path: /healthz
|
|
1396
|
+
port: 3000
|
|
1397
|
+
scheme: HTTPS
|
|
1398
|
+
ports:
|
|
1399
|
+
- containerPort: 3000
|
|
1400
|
+
resources:
|
|
1401
|
+
{{- toYaml .Values.watcher.resources | nindent 12 }}
|
|
1402
|
+
env:
|
|
1403
|
+
{{- toYaml .Values.watcher.env | nindent 12 }}
|
|
1404
|
+
securityContext:
|
|
1405
|
+
{{- toYaml .Values.watcher.containerSecurityContext | nindent 12 }}
|
|
1406
|
+
volumeMounts:
|
|
1407
|
+
- name: tls-certs
|
|
1408
|
+
mountPath: /etc/certs
|
|
1409
|
+
readOnly: true
|
|
1410
|
+
- name: module
|
|
1411
|
+
mountPath: /app/load
|
|
1412
|
+
readOnly: true
|
|
1413
|
+
volumes:
|
|
1414
|
+
- name: tls-certs
|
|
1415
|
+
secret:
|
|
1416
|
+
secretName: {{ .Values.uuid }}-tls
|
|
1417
|
+
- name: module
|
|
1418
|
+
secret:
|
|
1419
|
+
secretName: {{ .Values.uuid }}-module
|
|
1420
|
+
`;
|
|
1421
|
+
}
|
|
1422
|
+
function admissionDeployTemplate(buildTimestamp) {
|
|
1423
|
+
return `
|
|
1424
|
+
apiVersion: apps/v1
|
|
1425
|
+
kind: Deployment
|
|
1426
|
+
metadata:
|
|
1427
|
+
name: {{ .Values.uuid }}
|
|
1428
|
+
namespace: pepr-system
|
|
1429
|
+
annotations:
|
|
1430
|
+
{{- toYaml .Values.admission.annotations | nindent 4 }}
|
|
1431
|
+
labels:
|
|
1432
|
+
{{- toYaml .Values.admission.labels | nindent 4 }}
|
|
1433
|
+
spec:
|
|
1434
|
+
replicas: 2
|
|
1435
|
+
selector:
|
|
1436
|
+
matchLabels:
|
|
1437
|
+
app: {{ .Values.uuid }}
|
|
1438
|
+
pepr.dev/controller: admission
|
|
1439
|
+
template:
|
|
1440
|
+
metadata:
|
|
1441
|
+
annotations:
|
|
1442
|
+
buildTimestamp: "${buildTimestamp}"
|
|
1443
|
+
labels:
|
|
1444
|
+
app: {{ .Values.uuid }}
|
|
1445
|
+
pepr.dev/controller: admission
|
|
1446
|
+
spec:
|
|
1447
|
+
priorityClassName: system-node-critical
|
|
1448
|
+
serviceAccountName: {{ .Values.uuid }}
|
|
1449
|
+
securityContext:
|
|
1450
|
+
{{- toYaml .Values.admission.securityContext | nindent 8 }}
|
|
1451
|
+
containers:
|
|
1452
|
+
- name: server
|
|
1453
|
+
image: {{ .Values.admission.image }}
|
|
1454
|
+
imagePullPolicy: IfNotPresent
|
|
1455
|
+
command:
|
|
1456
|
+
- node
|
|
1457
|
+
- /app/node_modules/pepr/dist/controller.js
|
|
1458
|
+
- {{ .Values.hash }}
|
|
1459
|
+
readinessProbe:
|
|
1460
|
+
httpGet:
|
|
1461
|
+
path: /healthz
|
|
1462
|
+
port: 3000
|
|
1463
|
+
scheme: HTTPS
|
|
1464
|
+
livenessProbe:
|
|
1465
|
+
httpGet:
|
|
1466
|
+
path: /healthz
|
|
1467
|
+
port: 3000
|
|
1468
|
+
scheme: HTTPS
|
|
1469
|
+
ports:
|
|
1470
|
+
- containerPort: 3000
|
|
1471
|
+
resources:
|
|
1472
|
+
{{- toYaml .Values.admission.resources | nindent 12 }}
|
|
1473
|
+
env:
|
|
1474
|
+
{{- toYaml .Values.admission.env | nindent 12 }}
|
|
1475
|
+
securityContext:
|
|
1476
|
+
{{- toYaml .Values.admission.containerSecurityContext | nindent 12 }}
|
|
1477
|
+
volumeMounts:
|
|
1478
|
+
- name: tls-certs
|
|
1479
|
+
mountPath: /etc/certs
|
|
1480
|
+
readOnly: true
|
|
1481
|
+
- name: api-token
|
|
1482
|
+
mountPath: /app/api-token
|
|
1483
|
+
readOnly: true
|
|
1484
|
+
- name: module
|
|
1485
|
+
mountPath: /app/load
|
|
1486
|
+
readOnly: true
|
|
1487
|
+
volumes:
|
|
1488
|
+
- name: tls-certs
|
|
1489
|
+
secret:
|
|
1490
|
+
secretName: {{ .Values.uuid }}-tls
|
|
1491
|
+
- name: api-token
|
|
1492
|
+
secret:
|
|
1493
|
+
secretName: {{ .Values.uuid }}-api-token
|
|
1494
|
+
- name: module
|
|
1495
|
+
secret:
|
|
1496
|
+
secretName: {{ .Values.uuid }}-module
|
|
1497
|
+
`;
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
// src/lib/assets/index.ts
|
|
1501
|
+
var import_fs5 = require("fs");
|
|
1163
1502
|
var Assets = class {
|
|
1164
1503
|
constructor(config, path, host) {
|
|
1165
1504
|
this.config = config;
|
|
1166
1505
|
this.path = path;
|
|
1167
1506
|
this.host = host;
|
|
1168
1507
|
this.name = `pepr-${config.uuid}`;
|
|
1508
|
+
this.buildTimestamp = `${Date.now()}`;
|
|
1169
1509
|
this.alwaysIgnore = config.alwaysIgnore;
|
|
1170
1510
|
this.image = `ghcr.io/defenseunicorns/pepr/controller:v${config.peprVersion}`;
|
|
1511
|
+
this.hash = "";
|
|
1171
1512
|
this.tls = genTLS(this.host || `${this.name}.pepr-system.svc`);
|
|
1172
1513
|
this.apiToken = import_crypto3.default.randomBytes(32).toString("hex");
|
|
1173
1514
|
}
|
|
@@ -1177,6 +1518,11 @@ var Assets = class {
|
|
|
1177
1518
|
alwaysIgnore;
|
|
1178
1519
|
capabilities;
|
|
1179
1520
|
image;
|
|
1521
|
+
buildTimestamp;
|
|
1522
|
+
hash;
|
|
1523
|
+
setHash = (hash) => {
|
|
1524
|
+
this.hash = hash;
|
|
1525
|
+
};
|
|
1180
1526
|
deploy = async (force, webhookTimeout) => {
|
|
1181
1527
|
this.capabilities = await loadCapabilities(this.path);
|
|
1182
1528
|
await deploy(this, force, webhookTimeout);
|
|
@@ -1189,10 +1535,91 @@ var Assets = class {
|
|
|
1189
1535
|
}
|
|
1190
1536
|
return allYaml(this, rbacMode);
|
|
1191
1537
|
};
|
|
1538
|
+
generateHelmChart = async (basePath) => {
|
|
1539
|
+
const CHART_DIR = `${basePath}/${this.config.uuid}-chart`;
|
|
1540
|
+
const CHAR_TEMPLATES_DIR = `${CHART_DIR}/templates`;
|
|
1541
|
+
const valuesPath = (0, import_path.resolve)(CHART_DIR, `values.yaml`);
|
|
1542
|
+
const chartPath = (0, import_path.resolve)(CHART_DIR, `Chart.yaml`);
|
|
1543
|
+
const nsPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `namespace.yaml`);
|
|
1544
|
+
const watcherSVCPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `watcher-service.yaml`);
|
|
1545
|
+
const admissionSVCPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `admission-service.yaml`);
|
|
1546
|
+
const mutationWebhookPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `mutation-webhook.yaml`);
|
|
1547
|
+
const validationWebhookPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `validation-webhook.yaml`);
|
|
1548
|
+
const admissionDeployPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `admission-deployment.yaml`);
|
|
1549
|
+
const watcherDeployPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `watcher-deployment.yaml`);
|
|
1550
|
+
const tlsSecretPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `tls-secret.yaml`);
|
|
1551
|
+
const apiTokenSecretPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `api-token-secret.yaml`);
|
|
1552
|
+
const moduleSecretPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `module-secret.yaml`);
|
|
1553
|
+
const storeRolePath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `store-role.yaml`);
|
|
1554
|
+
const storeRoleBindingPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `store-role-binding.yaml`);
|
|
1555
|
+
const clusterRolePath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `cluster-role.yaml`);
|
|
1556
|
+
const clusterRoleBindingPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `cluster-role-binding.yaml`);
|
|
1557
|
+
const serviceAccountPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `service-account.yaml`);
|
|
1558
|
+
try {
|
|
1559
|
+
await createDirectoryIfNotExists(CHART_DIR);
|
|
1560
|
+
await createDirectoryIfNotExists(`${CHART_DIR}/charts`);
|
|
1561
|
+
await createDirectoryIfNotExists(`${CHAR_TEMPLATES_DIR}`);
|
|
1562
|
+
await overridesFile(this, valuesPath);
|
|
1563
|
+
await import_fs5.promises.writeFile(chartPath, dedent(chartYaml(this.config.uuid, this.config.description || "")));
|
|
1564
|
+
await import_fs5.promises.writeFile(nsPath, dedent(nsTemplate()));
|
|
1565
|
+
const code = await import_fs5.promises.readFile(this.path);
|
|
1566
|
+
await import_fs5.promises.writeFile(watcherSVCPath, (0, import_client_node2.dumpYaml)(watcherService(this.name), { noRefs: true }));
|
|
1567
|
+
await import_fs5.promises.writeFile(admissionSVCPath, (0, import_client_node2.dumpYaml)(service(this.name), { noRefs: true }));
|
|
1568
|
+
await import_fs5.promises.writeFile(tlsSecretPath, (0, import_client_node2.dumpYaml)(tlsSecret(this.name, this.tls), { noRefs: true }));
|
|
1569
|
+
await import_fs5.promises.writeFile(apiTokenSecretPath, (0, import_client_node2.dumpYaml)(apiTokenSecret(this.name, this.apiToken), { noRefs: true }));
|
|
1570
|
+
await import_fs5.promises.writeFile(moduleSecretPath, (0, import_client_node2.dumpYaml)(moduleSecret(this.name, code, this.hash), { noRefs: true }));
|
|
1571
|
+
await import_fs5.promises.writeFile(storeRolePath, (0, import_client_node2.dumpYaml)(storeRole(this.name), { noRefs: true }));
|
|
1572
|
+
await import_fs5.promises.writeFile(storeRoleBindingPath, (0, import_client_node2.dumpYaml)(storeRoleBinding(this.name), { noRefs: true }));
|
|
1573
|
+
await import_fs5.promises.writeFile(
|
|
1574
|
+
clusterRolePath,
|
|
1575
|
+
(0, import_client_node2.dumpYaml)(clusterRole(this.name, this.capabilities, "rbac"), { noRefs: true })
|
|
1576
|
+
);
|
|
1577
|
+
await import_fs5.promises.writeFile(clusterRoleBindingPath, (0, import_client_node2.dumpYaml)(clusterRoleBinding(this.name), { noRefs: true }));
|
|
1578
|
+
await import_fs5.promises.writeFile(serviceAccountPath, (0, import_client_node2.dumpYaml)(serviceAccount(this.name), { noRefs: true }));
|
|
1579
|
+
const mutateWebhook = await webhookConfig(this, "mutate", this.config.webhookTimeout);
|
|
1580
|
+
const validateWebhook = await webhookConfig(this, "validate", this.config.webhookTimeout);
|
|
1581
|
+
const watchDeployment = watcher(this, this.hash, this.buildTimestamp);
|
|
1582
|
+
if (validateWebhook || mutateWebhook) {
|
|
1583
|
+
await import_fs5.promises.writeFile(admissionDeployPath, dedent(admissionDeployTemplate(this.buildTimestamp)));
|
|
1584
|
+
}
|
|
1585
|
+
if (mutateWebhook) {
|
|
1586
|
+
const yamlMutateWebhook = (0, import_client_node2.dumpYaml)(mutateWebhook, { noRefs: true });
|
|
1587
|
+
const mutateWebhookTemplate = replaceString(
|
|
1588
|
+
replaceString(
|
|
1589
|
+
replaceString(yamlMutateWebhook, this.name, "{{ .Values.uuid }}"),
|
|
1590
|
+
this.config.onError === "reject" ? "Fail" : "Ignore",
|
|
1591
|
+
"{{ .Values.admission.failurePolicy }}"
|
|
1592
|
+
),
|
|
1593
|
+
`${this.config.webhookTimeout}` || "10",
|
|
1594
|
+
"{{ .Values.admission.webhookTimeout }}"
|
|
1595
|
+
);
|
|
1596
|
+
await import_fs5.promises.writeFile(mutationWebhookPath, mutateWebhookTemplate);
|
|
1597
|
+
}
|
|
1598
|
+
if (validateWebhook) {
|
|
1599
|
+
const yamlValidateWebhook = (0, import_client_node2.dumpYaml)(validateWebhook, { noRefs: true });
|
|
1600
|
+
const validateWebhookTemplate = replaceString(
|
|
1601
|
+
replaceString(
|
|
1602
|
+
replaceString(yamlValidateWebhook, this.name, "{{ .Values.uuid }}"),
|
|
1603
|
+
this.config.onError === "reject" ? "Fail" : "Ignore",
|
|
1604
|
+
"{{ .Values.admission.failurePolicy }}"
|
|
1605
|
+
),
|
|
1606
|
+
`${this.config.webhookTimeout}` || "10",
|
|
1607
|
+
"{{ .Values.admission.webhookTimeout }}"
|
|
1608
|
+
);
|
|
1609
|
+
await import_fs5.promises.writeFile(validationWebhookPath, validateWebhookTemplate);
|
|
1610
|
+
}
|
|
1611
|
+
if (watchDeployment) {
|
|
1612
|
+
await import_fs5.promises.writeFile(watcherDeployPath, dedent(watcherDeployTemplate(this.buildTimestamp)));
|
|
1613
|
+
}
|
|
1614
|
+
} catch (err) {
|
|
1615
|
+
console.error(`Error generating helm chart: ${err.message}`);
|
|
1616
|
+
process.exit(1);
|
|
1617
|
+
}
|
|
1618
|
+
};
|
|
1192
1619
|
};
|
|
1193
1620
|
|
|
1194
1621
|
// src/cli/init/templates.ts
|
|
1195
|
-
var
|
|
1622
|
+
var import_client_node3 = require("@kubernetes/client-node");
|
|
1196
1623
|
var import_util = require("util");
|
|
1197
1624
|
var import_uuid = require("uuid");
|
|
1198
1625
|
|
|
@@ -1398,7 +1825,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
1398
1825
|
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';
|
|
1399
1826
|
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';
|
|
1400
1827
|
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 try {\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 } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\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\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';
|
|
1401
|
-
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.
|
|
1828
|
+
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.27.0", 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 --detectOpenHandles --coverageDirectory=./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:prep": "git clone https://github.com/defenseunicorns/pepr-upgrade-test.git", "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' --wait && kubectl rollout status deployment -n kube-system", "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 --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.29.10", express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.2.1", pino: "8.19.0", "pino-pretty": "10.3.1", "prom-client": "15.1.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "19.0.1", "@commitlint/config-conventional": "19.0.0", "@jest/globals": "29.7.0", "@types/eslint": "8.56.4", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.11", "@types/prompts": "2.4.9", "@types/uuid": "9.0.8", jest: "29.7.0", nock: "13.5.4", "ts-jest": "29.1.2" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.15.0", "@typescript-eslint/parser": "6.15.0", commander: "11.1.0", esbuild: "0.19.10", eslint: "8.56.0", "node-forge": "1.3.1", prettier: "3.1.1", prompts: "2.4.2", typescript: "5.3.3", uuid: "9.0.1" } };
|
|
1402
1829
|
|
|
1403
1830
|
// src/templates/pepr.code-snippets.json
|
|
1404
1831
|
var pepr_code_snippets_default = {
|
|
@@ -1457,7 +1884,7 @@ var tsconfig_module_default = {
|
|
|
1457
1884
|
};
|
|
1458
1885
|
|
|
1459
1886
|
// src/cli/init/utils.ts
|
|
1460
|
-
var
|
|
1887
|
+
var import_fs6 = require("fs");
|
|
1461
1888
|
function sanitizeName(name2) {
|
|
1462
1889
|
let sanitized = name2.toLowerCase().replace(/[^a-z0-9-]+/gi, "-");
|
|
1463
1890
|
sanitized = sanitized.replace(/^-+|-+$/g, "");
|
|
@@ -1466,7 +1893,7 @@ function sanitizeName(name2) {
|
|
|
1466
1893
|
}
|
|
1467
1894
|
async function createDir(dir) {
|
|
1468
1895
|
try {
|
|
1469
|
-
await
|
|
1896
|
+
await import_fs6.promises.mkdir(dir);
|
|
1470
1897
|
} catch (err) {
|
|
1471
1898
|
if (err && err.code === "EEXIST") {
|
|
1472
1899
|
throw new Error(`Directory ${dir} already exists`);
|
|
@@ -1479,7 +1906,7 @@ function write(path, data) {
|
|
|
1479
1906
|
if (typeof data !== "string") {
|
|
1480
1907
|
data = JSON.stringify(data, null, 2);
|
|
1481
1908
|
}
|
|
1482
|
-
return
|
|
1909
|
+
return import_fs6.promises.writeFile(path, data);
|
|
1483
1910
|
}
|
|
1484
1911
|
|
|
1485
1912
|
// src/cli/init/templates.ts
|
|
@@ -1506,7 +1933,9 @@ function genPkgJSON(opts, pgkVerOverride) {
|
|
|
1506
1933
|
onError: opts.errorBehavior,
|
|
1507
1934
|
webhookTimeout: 10,
|
|
1508
1935
|
customLabels: {
|
|
1509
|
-
namespace: {
|
|
1936
|
+
namespace: {
|
|
1937
|
+
"pepr.dev": ""
|
|
1938
|
+
}
|
|
1510
1939
|
},
|
|
1511
1940
|
alwaysIgnore: {
|
|
1512
1941
|
namespaces: [],
|
|
@@ -1551,7 +1980,7 @@ var gitignore = {
|
|
|
1551
1980
|
};
|
|
1552
1981
|
var samplesYaml = {
|
|
1553
1982
|
path: "hello-pepr.samples.yaml",
|
|
1554
|
-
data: hello_pepr_samples_default.map((r) => (0,
|
|
1983
|
+
data: hello_pepr_samples_default.map((r) => (0, import_client_node3.dumpYaml)(r, { noRefs: true })).join("---\n")
|
|
1555
1984
|
};
|
|
1556
1985
|
var snippet = {
|
|
1557
1986
|
path: "pepr.code-snippets",
|
|
@@ -1576,7 +2005,7 @@ var eslint = {
|
|
|
1576
2005
|
|
|
1577
2006
|
// src/cli/format.ts
|
|
1578
2007
|
var import_eslint = require("eslint");
|
|
1579
|
-
var
|
|
2008
|
+
var import_fs7 = require("fs");
|
|
1580
2009
|
var import_prettier = require("prettier");
|
|
1581
2010
|
function format_default(program2) {
|
|
1582
2011
|
program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
|
|
@@ -1609,7 +2038,7 @@ async function peprFormat(validateOnly) {
|
|
|
1609
2038
|
await import_eslint.ESLint.outputFixes(results);
|
|
1610
2039
|
}
|
|
1611
2040
|
for (const { filePath } of results) {
|
|
1612
|
-
const content = await
|
|
2041
|
+
const content = await import_fs7.promises.readFile(filePath, "utf8");
|
|
1613
2042
|
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
1614
2043
|
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
1615
2044
|
if (validateOnly) {
|
|
@@ -1618,7 +2047,7 @@ async function peprFormat(validateOnly) {
|
|
|
1618
2047
|
console.error(`File ${filePath} is not formatted correctly`);
|
|
1619
2048
|
}
|
|
1620
2049
|
} else {
|
|
1621
|
-
await
|
|
2050
|
+
await import_fs7.promises.writeFile(filePath, formatted);
|
|
1622
2051
|
}
|
|
1623
2052
|
}
|
|
1624
2053
|
return !hasFailure;
|
|
@@ -1708,12 +2137,13 @@ function build_default(program2) {
|
|
|
1708
2137
|
assets.image = image;
|
|
1709
2138
|
}
|
|
1710
2139
|
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
1711
|
-
const yamlPath = (0,
|
|
2140
|
+
const yamlPath = (0, import_path2.resolve)(outputDir, yamlFile);
|
|
1712
2141
|
const yaml = await assets.allYaml(opts.rbacMode);
|
|
1713
|
-
const zarfPath = (0,
|
|
2142
|
+
const zarfPath = (0, import_path2.resolve)(outputDir, "zarf.yaml");
|
|
1714
2143
|
const zarf = assets.zarfYaml(yamlFile);
|
|
1715
|
-
await
|
|
1716
|
-
await
|
|
2144
|
+
await import_fs8.promises.writeFile(yamlPath, yaml);
|
|
2145
|
+
await import_fs8.promises.writeFile(zarfPath, zarf);
|
|
2146
|
+
await assets.generateHelmChart(outputDir);
|
|
1717
2147
|
console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
|
|
1718
2148
|
});
|
|
1719
2149
|
}
|
|
@@ -1721,19 +2151,19 @@ var externalLibs = Object.keys(dependencies);
|
|
|
1721
2151
|
externalLibs.push("pepr");
|
|
1722
2152
|
externalLibs.push("@kubernetes/client-node");
|
|
1723
2153
|
async function loadModule(entryPoint = peprTS2) {
|
|
1724
|
-
const entryPointPath = (0,
|
|
1725
|
-
const modulePath = (0,
|
|
1726
|
-
const cfgPath = (0,
|
|
2154
|
+
const entryPointPath = (0, import_path2.resolve)(".", entryPoint);
|
|
2155
|
+
const modulePath = (0, import_path2.dirname)(entryPointPath);
|
|
2156
|
+
const cfgPath = (0, import_path2.resolve)(modulePath, "package.json");
|
|
1727
2157
|
try {
|
|
1728
|
-
await
|
|
1729
|
-
await
|
|
2158
|
+
await import_fs8.promises.access(cfgPath);
|
|
2159
|
+
await import_fs8.promises.access(entryPointPath);
|
|
1730
2160
|
} catch (e) {
|
|
1731
2161
|
console.error(
|
|
1732
2162
|
`Could not find ${cfgPath} or ${entryPointPath} in the current directory. Please run this command from the root of your module's directory.`
|
|
1733
2163
|
);
|
|
1734
2164
|
process.exit(1);
|
|
1735
2165
|
}
|
|
1736
|
-
const moduleText = await
|
|
2166
|
+
const moduleText = await import_fs8.promises.readFile(cfgPath, { encoding: "utf-8" });
|
|
1737
2167
|
const cfg = JSON.parse(moduleText);
|
|
1738
2168
|
const { uuid } = cfg.pepr;
|
|
1739
2169
|
const name2 = `pepr-${uuid}.js`;
|
|
@@ -1746,7 +2176,7 @@ async function loadModule(entryPoint = peprTS2) {
|
|
|
1746
2176
|
entryPointPath,
|
|
1747
2177
|
modulePath,
|
|
1748
2178
|
name: name2,
|
|
1749
|
-
path: (0,
|
|
2179
|
+
path: (0, import_path2.resolve)(outputDir, name2),
|
|
1750
2180
|
uuid
|
|
1751
2181
|
};
|
|
1752
2182
|
}
|
|
@@ -1797,7 +2227,7 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
|
1797
2227
|
}
|
|
1798
2228
|
if (!embed) {
|
|
1799
2229
|
ctxCfg.minify = false;
|
|
1800
|
-
ctxCfg.outfile = (0,
|
|
2230
|
+
ctxCfg.outfile = (0, import_path2.resolve)(outputDir, (0, import_path2.basename)(entryPoint, (0, import_path2.extname)(entryPoint))) + ".js";
|
|
1801
2231
|
ctxCfg.packages = "external";
|
|
1802
2232
|
ctxCfg.treeShaking = false;
|
|
1803
2233
|
}
|
|
@@ -1880,7 +2310,7 @@ function deploy_default(program2) {
|
|
|
1880
2310
|
|
|
1881
2311
|
// src/cli/dev.ts
|
|
1882
2312
|
var import_child_process3 = require("child_process");
|
|
1883
|
-
var
|
|
2313
|
+
var import_fs9 = require("fs");
|
|
1884
2314
|
var import_prompts2 = __toESM(require("prompts"));
|
|
1885
2315
|
function dev_default(program2) {
|
|
1886
2316
|
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) => {
|
|
@@ -1903,8 +2333,8 @@ function dev_default(program2) {
|
|
|
1903
2333
|
path,
|
|
1904
2334
|
opts.host
|
|
1905
2335
|
);
|
|
1906
|
-
await
|
|
1907
|
-
await
|
|
2336
|
+
await import_fs9.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
|
|
2337
|
+
await import_fs9.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
|
|
1908
2338
|
try {
|
|
1909
2339
|
let program3;
|
|
1910
2340
|
const runFork = async () => {
|
|
@@ -1943,7 +2373,7 @@ function dev_default(program2) {
|
|
|
1943
2373
|
}
|
|
1944
2374
|
|
|
1945
2375
|
// src/cli/monitor.ts
|
|
1946
|
-
var
|
|
2376
|
+
var import_client_node4 = require("@kubernetes/client-node");
|
|
1947
2377
|
var import_kubernetes_fluent_client4 = require("kubernetes-fluent-client");
|
|
1948
2378
|
var import_stream = __toESM(require("stream"));
|
|
1949
2379
|
function monitor_default(program2) {
|
|
@@ -1963,9 +2393,9 @@ function monitor_default(program2) {
|
|
|
1963
2393
|
console.error(errorMessage);
|
|
1964
2394
|
process.exit(1);
|
|
1965
2395
|
}
|
|
1966
|
-
const kc = new
|
|
2396
|
+
const kc = new import_client_node4.KubeConfig();
|
|
1967
2397
|
kc.loadFromDefault();
|
|
1968
|
-
const log = new
|
|
2398
|
+
const log = new import_client_node4.Log(kc);
|
|
1969
2399
|
const logStream = new import_stream.default.PassThrough();
|
|
1970
2400
|
logStream.on("data", (chunk) => {
|
|
1971
2401
|
const respMsg = `"msg":"Check response"`;
|
|
@@ -1978,16 +2408,23 @@ function monitor_default(program2) {
|
|
|
1978
2408
|
const name2 = `${payload.namespace}${payload.name}`;
|
|
1979
2409
|
const uid = payload.uid;
|
|
1980
2410
|
if (isMutate) {
|
|
1981
|
-
const
|
|
2411
|
+
const plainPatch = atob(payload.res.patch) || "";
|
|
2412
|
+
const patch = JSON.stringify(JSON.parse(plainPatch), null, 2);
|
|
2413
|
+
const patchType = payload.res.patchType || payload.res.warnings || "";
|
|
2414
|
+
const allowOrDeny = payload.res.allowed ? "\u{1F500}" : "\u{1F6AB}";
|
|
1982
2415
|
console.log(`
|
|
1983
2416
|
${allowOrDeny} MUTATE ${name2} (${uid})`);
|
|
2417
|
+
if (patchType.length > 0) {
|
|
2418
|
+
console.log(`
|
|
2419
|
+
\x1B[1;34m${patch}\x1B[0m`);
|
|
2420
|
+
}
|
|
1984
2421
|
} else {
|
|
1985
2422
|
const failures = Array.isArray(payload.res) ? payload.res : [payload.res];
|
|
1986
2423
|
const filteredFailures = failures.filter((r) => !r.allowed).map((r) => r.status.message);
|
|
1987
2424
|
if (filteredFailures.length > 0) {
|
|
1988
2425
|
console.log(`
|
|
1989
2426
|
\u274C VALIDATE ${name2} (${uid})`);
|
|
1990
|
-
console.debug(filteredFailures);
|
|
2427
|
+
console.debug(`\x1B[1;31m${filteredFailures}\x1B[0m`);
|
|
1991
2428
|
} else {
|
|
1992
2429
|
console.log(`
|
|
1993
2430
|
\u2705 VALIDATE ${name2} (${uid})`);
|
|
@@ -2012,11 +2449,11 @@ IGNORED - Unable to parse line: ${line}.`);
|
|
|
2012
2449
|
|
|
2013
2450
|
// src/cli/init/index.ts
|
|
2014
2451
|
var import_child_process4 = require("child_process");
|
|
2015
|
-
var
|
|
2452
|
+
var import_path3 = require("path");
|
|
2016
2453
|
var import_prompts4 = __toESM(require("prompts"));
|
|
2017
2454
|
|
|
2018
2455
|
// src/cli/init/walkthrough.ts
|
|
2019
|
-
var
|
|
2456
|
+
var import_fs10 = require("fs");
|
|
2020
2457
|
var import_prompts3 = __toESM(require("prompts"));
|
|
2021
2458
|
|
|
2022
2459
|
// src/lib/errors.ts
|
|
@@ -2036,7 +2473,7 @@ function walkthrough() {
|
|
|
2036
2473
|
validate: async (val) => {
|
|
2037
2474
|
try {
|
|
2038
2475
|
const name2 = sanitizeName(val);
|
|
2039
|
-
await
|
|
2476
|
+
await import_fs10.promises.access(name2, import_fs10.promises.constants.F_OK);
|
|
2040
2477
|
return "A directory with this name already exists";
|
|
2041
2478
|
} catch (e) {
|
|
2042
2479
|
return val.length > 2 || "The name must be at least 3 characters long";
|
|
@@ -2115,19 +2552,19 @@ function init_default(program2) {
|
|
|
2115
2552
|
console.log("Creating new Pepr module...");
|
|
2116
2553
|
try {
|
|
2117
2554
|
await createDir(dirName);
|
|
2118
|
-
await createDir((0,
|
|
2119
|
-
await createDir((0,
|
|
2120
|
-
await write((0,
|
|
2121
|
-
await write((0,
|
|
2122
|
-
await write((0,
|
|
2123
|
-
await write((0,
|
|
2124
|
-
await write((0,
|
|
2125
|
-
await write((0,
|
|
2126
|
-
await write((0,
|
|
2127
|
-
await write((0,
|
|
2128
|
-
await write((0,
|
|
2129
|
-
await write((0,
|
|
2130
|
-
await write((0,
|
|
2555
|
+
await createDir((0, import_path3.resolve)(dirName, ".vscode"));
|
|
2556
|
+
await createDir((0, import_path3.resolve)(dirName, "capabilities"));
|
|
2557
|
+
await write((0, import_path3.resolve)(dirName, gitignore.path), gitignore.data);
|
|
2558
|
+
await write((0, import_path3.resolve)(dirName, eslint.path), eslint.data);
|
|
2559
|
+
await write((0, import_path3.resolve)(dirName, prettier.path), prettier.data);
|
|
2560
|
+
await write((0, import_path3.resolve)(dirName, packageJSON2.path), packageJSON2.data);
|
|
2561
|
+
await write((0, import_path3.resolve)(dirName, readme.path), readme.data);
|
|
2562
|
+
await write((0, import_path3.resolve)(dirName, tsConfig.path), tsConfig.data);
|
|
2563
|
+
await write((0, import_path3.resolve)(dirName, peprTS3.path), peprTS3.data);
|
|
2564
|
+
await write((0, import_path3.resolve)(dirName, ".vscode", snippet.path), snippet.data);
|
|
2565
|
+
await write((0, import_path3.resolve)(dirName, ".vscode", codeSettings.path), codeSettings.data);
|
|
2566
|
+
await write((0, import_path3.resolve)(dirName, "capabilities", samplesYaml.path), samplesYaml.data);
|
|
2567
|
+
await write((0, import_path3.resolve)(dirName, "capabilities", helloPepr.path), helloPepr.data);
|
|
2131
2568
|
if (!opts.skipPostInit) {
|
|
2132
2569
|
process.chdir(dirName);
|
|
2133
2570
|
(0, import_child_process4.execSync)("npm install", {
|
|
@@ -2197,8 +2634,8 @@ var RootCmd = class extends import_commander3.Command {
|
|
|
2197
2634
|
|
|
2198
2635
|
// src/cli/update.ts
|
|
2199
2636
|
var import_child_process5 = require("child_process");
|
|
2200
|
-
var
|
|
2201
|
-
var
|
|
2637
|
+
var import_fs11 = __toESM(require("fs"));
|
|
2638
|
+
var import_path4 = require("path");
|
|
2202
2639
|
var import_prompts5 = __toESM(require("prompts"));
|
|
2203
2640
|
function update_default(program2) {
|
|
2204
2641
|
program2.command("update").description("Update this Pepr module").option("--skip-template-update", "Skip updating the template files").action(async (opts) => {
|
|
@@ -2232,17 +2669,17 @@ function update_default(program2) {
|
|
|
2232
2669
|
console.log("Updating Pepr config and template tiles...");
|
|
2233
2670
|
try {
|
|
2234
2671
|
if (!opts.skipTemplateUpdate) {
|
|
2235
|
-
await write((0,
|
|
2236
|
-
await write((0,
|
|
2237
|
-
await write((0,
|
|
2238
|
-
await write((0,
|
|
2239
|
-
const samplePath = (0,
|
|
2240
|
-
if (
|
|
2241
|
-
|
|
2672
|
+
await write((0, import_path4.resolve)(prettier.path), prettier.data);
|
|
2673
|
+
await write((0, import_path4.resolve)(tsConfig.path), tsConfig.data);
|
|
2674
|
+
await write((0, import_path4.resolve)(".vscode", snippet.path), snippet.data);
|
|
2675
|
+
await write((0, import_path4.resolve)(".vscode", codeSettings.path), codeSettings.data);
|
|
2676
|
+
const samplePath = (0, import_path4.resolve)("capabilities", samplesYaml.path);
|
|
2677
|
+
if (import_fs11.default.existsSync(samplePath)) {
|
|
2678
|
+
import_fs11.default.unlinkSync(samplePath);
|
|
2242
2679
|
await write(samplePath, samplesYaml.data);
|
|
2243
2680
|
}
|
|
2244
|
-
const tsPath = (0,
|
|
2245
|
-
if (
|
|
2681
|
+
const tsPath = (0, import_path4.resolve)("capabilities", helloPepr.path);
|
|
2682
|
+
if (import_fs11.default.existsSync(tsPath)) {
|
|
2246
2683
|
await write(tsPath, helloPepr.data);
|
|
2247
2684
|
}
|
|
2248
2685
|
}
|