@rophy123/helmtest 1.0.0 → 1.1.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/.dockerignore +2 -0
- package/Dockerfile +28 -0
- package/lib/helmtest.js +34 -1
- package/package.json +2 -1
package/.dockerignore
ADDED
package/Dockerfile
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
FROM node:16.19.1-bullseye-slim
|
|
2
|
+
|
|
3
|
+
RUN apt-get update && apt-get install -y curl git
|
|
4
|
+
|
|
5
|
+
RUN curl -sLo ./helm.tar.gz https://get.helm.sh/helm-v3.11.2-linux-amd64.tar.gz \
|
|
6
|
+
&& tar -zxvf helm.tar.gz linux-amd64/helm \
|
|
7
|
+
--strip-components 1 && mv ./helm /usr/local/bin/ \
|
|
8
|
+
&& rm ./helm.tar.gz
|
|
9
|
+
|
|
10
|
+
RUN curl -sLo ./helm.tar.gz https://get.helm.sh/helm-v3.11.2-linux-amd64.tar.gz \
|
|
11
|
+
&& tar -zxvf helm.tar.gz linux-amd64/helm \
|
|
12
|
+
--strip-components 1 && mv ./helm /usr/local/bin/ \
|
|
13
|
+
&& rm ./helm.tar.gz
|
|
14
|
+
|
|
15
|
+
RUN curl -sLo kubeconform.tar.gz https://github.com/yannh/kubeconform/releases/download/v0.6.1/kubeconform-linux-amd64.tar.gz \
|
|
16
|
+
&& tar -zxvf kubeconform.tar.gz kubeconform \
|
|
17
|
+
&& mv ./kubeconform /usr/local/bin/ \
|
|
18
|
+
&& rm kubeconform.tar.gz
|
|
19
|
+
|
|
20
|
+
ENV KUBERNETES_VERSION=1.22.9
|
|
21
|
+
RUN cd / && git clone --depth 1 --filter=blob:none --sparse https://github.com/yannh/kubernetes-json-schema \
|
|
22
|
+
&& cd kubernetes-json-schema \
|
|
23
|
+
&& git sparse-checkout set v${KUBERNETES_VERSION}-standalone-strict \
|
|
24
|
+
&& rm -rf ./.git
|
|
25
|
+
|
|
26
|
+
ENV KUBECONFORM_ENABLED=true KUBECONFORM_ARGS="-kubernetes-version ${KUBERNETES_VERSION} -schema-location /kubernetes-json-schema -strict"
|
|
27
|
+
ENV HELM_REGISTRY_CONFIG=/tmp/registry.json DOCKER_CONFIG=/tmp/config.json
|
|
28
|
+
RUN npm install -g @rophy123/helmtest
|
package/lib/helmtest.js
CHANGED
|
@@ -3,6 +3,8 @@ const path = require('path');
|
|
|
3
3
|
const util = require('util');
|
|
4
4
|
const exec = util.promisify(require('node:child_process').exec);
|
|
5
5
|
const yaml = require('js-yaml');
|
|
6
|
+
const debug = require('debug')('helmtest');
|
|
7
|
+
const Readable = require('stream').Readable;
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Run `helm template` to generate javascript object of the result YAML.
|
|
@@ -20,6 +22,14 @@ async function renderTemplate(options = {}) {
|
|
|
20
22
|
options.extraHelmArgs = options.extraHelmArgs || [];
|
|
21
23
|
options.helmBinary = options.helmBinary || process.env.HELM_BINARY || 'helm';
|
|
22
24
|
options.loadYaml = options.loadYaml || true;
|
|
25
|
+
options.kubeconformEnabled = options.kubeconformEnabled ||
|
|
26
|
+
process.env.KUBECONFORM_ENABLED || false;
|
|
27
|
+
options.kubeconformBinary = options.kubeconformBinary ||
|
|
28
|
+
process.env.KUBECONFORM_BINARY || 'kubeconform';
|
|
29
|
+
options.kubeconformExtraArgs = options.kubeconformExtraArgs ||
|
|
30
|
+
process.env.KUBECONFORM_ARGS || false;
|
|
31
|
+
|
|
32
|
+
debug(`options: ${JSON.stringify(options)}`);
|
|
23
33
|
|
|
24
34
|
// Make sure chartDir exists.
|
|
25
35
|
fs.statSync(options.chartDir);
|
|
@@ -68,7 +78,30 @@ async function renderTemplate(options = {}) {
|
|
|
68
78
|
helmCmd.push(options.releaseName);
|
|
69
79
|
helmCmd.push(options.chartDir);
|
|
70
80
|
|
|
71
|
-
const
|
|
81
|
+
const command = helmCmd.join(' ');
|
|
82
|
+
debug(`command: ${command}`);
|
|
83
|
+
const helmOutput = await exec(command);
|
|
84
|
+
|
|
85
|
+
if (options.kubeconformEnabled) {
|
|
86
|
+
let kcCommand = options.kubeconformBinary;
|
|
87
|
+
if (options.kubeconformExtraArgs) {
|
|
88
|
+
kcCommand += ' ' + options.kubeconformExtraArgs;
|
|
89
|
+
}
|
|
90
|
+
debug(`kcCommand: ${kcCommand}`);
|
|
91
|
+
const kcProc = exec(kcCommand);
|
|
92
|
+
const piper = new Readable();
|
|
93
|
+
piper.pipe(kcProc.child.stdin);
|
|
94
|
+
piper.push(helmOutput.stdout);
|
|
95
|
+
piper.push(null);
|
|
96
|
+
try {
|
|
97
|
+
await kcProc;
|
|
98
|
+
} catch (err) {
|
|
99
|
+
if (err.stdout) console.error(err.stdout);
|
|
100
|
+
if (err.stderr) console.error(err.stderr);
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
72
105
|
if (options.loadYaml) {
|
|
73
106
|
return yaml.loadAll(helmOutput.stdout);
|
|
74
107
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rophy123/helmtest",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Write unit tests against your helm charts using JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/rophy/helmtest#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"debug": "^4.3.4",
|
|
23
24
|
"jest": "^29.5.0",
|
|
24
25
|
"js-yaml": "^4.1.0"
|
|
25
26
|
},
|