Skip to content

Commit 5dca343

Browse files
authored
Push to the OCI registry and debug chart with console.error() (#31)
* Bump dependencies versions * Fix typos * Add ability to push to OCI registry and work with new version of helm-push plugin * Add the ability to debug deno charts using console.error() * Update actions versions in GitHub Workflows * Fix code formatting * Fix e2e test with helm secret plugin
1 parent a7223ae commit 5dca343

File tree

18 files changed

+629
-335
lines changed

18 files changed

+629
-335
lines changed

.github/workflows/codeql-analysis.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616

1717
steps:
1818
- name: Checkout repository
19-
uses: actions/checkout@v2
19+
uses: actions/checkout@v3
2020

2121
- name: Initialize CodeQL
22-
uses: github/codeql-action/init@v1
22+
uses: github/codeql-action/init@v2
2323
with:
2424
languages: javascript
2525

2626
- name: Perform CodeQL Analysis
27-
uses: github/codeql-action/analyze@v1
27+
uses: github/codeql-action/analyze@v2

.github/workflows/lint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v3
1111

1212
- name: Install dependencies
1313
run: make install-tools
@@ -16,4 +16,4 @@ jobs:
1616
run: make lint
1717

1818
- name: Run editorconfig linter
19-
uses: docker://mstruebing/editorconfig-checker:2.3.3
19+
uses: docker://mstruebing/editorconfig-checker:2.4.0

.github/workflows/test-all.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,34 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v3
1111

12-
- uses: denolib/setup-deno@v2
12+
- uses: denoland/setup-deno@v1
1313
with:
14-
deno-version: v1.8.x
14+
deno-version: v1.26.x
1515

1616
- name: Install Age Encryption Tool
1717
run: |
18-
wget https://github.com/FiloSottile/age/releases/download/v1.0.0-rc.1/age-v1.0.0-rc.1-linux-amd64.tar.gz -O age.tar.gz
18+
wget https://github.com/FiloSottile/age/releases/download/v1.0.0/age-v1.0.0-linux-amd64.tar.gz -O age.tar.gz
1919
tar xvf age.tar.gz age/age age/age-keygen
2020
echo "$PWD/age" >> $GITHUB_PATH
2121
2222
- name: Install sops
23-
uses: mdgreenwald/mozilla-sops-action@55d09a81cc2b0b5235af697e3b84b1f502f63025 # v1 at 14 April 2020
23+
uses: mdgreenwald/mozilla-sops-action@v1.2.0
2424
with:
25-
version: 3.7.1
25+
version: 3.7.3
2626

2727
- name: Install helm-diff
2828
run: |
29-
helm plugin install https://github.com/databus23/helm-diff --version v3.1.3
29+
helm plugin install https://github.com/databus23/helm-diff --version v3.6.0
3030
3131
- name: Install helm-secrets
3232
run: |
33-
helm plugin install https://github.com/jkroepke/helm-secrets --version v3.6.1
33+
helm plugin install https://github.com/jkroepke/helm-secrets --version v4.1.1
3434
3535
- name: Install helm-push
3636
run: |
37-
helm plugin install https://github.com/chartmuseum/helm-push --version v0.9.0
37+
helm plugin install https://github.com/chartmuseum/helm-push --version v0.10.3
3838
3939
- name: Install plugin
4040
run: make install-plugin

.github/workflows/test.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v3
1111

12-
- uses: denolib/setup-deno@v2
12+
- uses: denoland/setup-deno@v1
1313
with:
14-
deno-version: v1.8.x
14+
deno-version: v1.26.x
1515

1616
- name: Install plugin
1717
run: make install-plugin

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
deno 1.14.0
1+
deno 1.26.2

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ install-tools:
1111
@ yarn --frozen-lockfile
1212

1313
install-plugin:
14-
@ HELM_PLUGIN_DIR="$$PWD" ./scripts/install.sh "v$${DENO_VERSION:-1.14.0}"
14+
@ HELM_PLUGIN_DIR="$$PWD" ./scripts/install.sh "v$${DENO_VERSION:-1.26.2}"
1515

1616
lint:
1717
@ yarn prettier --check .
@@ -38,4 +38,5 @@ test-all:
3838
@ $(shell $(HELM) env) RUN_ALL_TESTS=true bin/deno test --unstable --allow-run --allow-read --allow-write --allow-env --allow-net src/ e2e-tests/
3939

4040
update-deps:
41-
deno run -A https://deno.land/x/udd@0.5.0/main.ts src/**/*.ts
41+
deno run -A https://deno.land/x/udd@0.8.1/main.ts src/*.ts
42+
deno run -A https://deno.land/x/udd@0.8.1/main.ts src/**/*.ts

e2e-tests/e2e.test.ts

Lines changed: 170 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Use fork until https://github.com/piyush-bhatt/deno-port/pull/1 is merged
22
import { getAvailablePort } from "https://raw.githubusercontent.com/Nitive/deno-port/fix-getting-random-port/mod.ts"
3-
4-
import { exists } from "https://deno.land/std@0.107.0/fs/exists.ts"
5-
import * as path from "https://deno.land/std@0.107.0/path/mod.ts"
6-
import * as yaml from "https://deno.land/std@0.107.0/encoding/yaml.ts"
3+
import { exists } from "https://deno.land/std@0.160.0/fs/exists.ts"
4+
import * as path from "https://deno.land/std@0.160.0/path/mod.ts"
5+
import * as yaml from "https://deno.land/std@0.160.0/encoding/yaml.ts"
76
import {
87
assertEquals,
98
assertStringIncludes,
10-
} from "https://deno.land/std@0.107.0/testing/asserts.ts"
9+
} from "https://deno.land/std@0.160.0/testing/asserts.ts"
1110
import { ignoreNotFoundError } from "../src/utils/ignore-not-found-error.ts"
1211
import { waitForProcess } from "../src/utils/process.ts"
1312

@@ -61,7 +60,7 @@ async function assertYamlParsable(yamlFileContent: string) {
6160
try {
6261
await yaml.parseAll(yamlFileContent)
6362
} catch (err) {
64-
throw new Error(`Cloud parse yaml context ${err} ${yamlFileContent}`)
63+
throw new Error(`Could not parse yaml context ${err} ${yamlFileContent}`)
6564
}
6665
}
6766

@@ -163,9 +162,10 @@ Supported helm [command] is:
163162
- template
164163
- install
165164
- upgrade
165+
- push
166166
- diff (helm plugin)
167167
- secrets (helm plugin)
168-
- push (helm plugin)
168+
- cm-push (helm plugin)
169169
170170
You must use the options of the supported commands in strict order:
171171
$ helm <secrets> <diff> [upgrade/template/install] [RELEASE] [CHART] <flags>
@@ -256,7 +256,7 @@ Deno.test({
256256

257257
assertEquals(
258258
stderr,
259-
"[helm-secrets] Decrypt: tmp-secrets.test-values.yaml\n\n[helm-secrets] Removed: ./tmp-secrets.test-values.yaml.dec\n"
259+
"[helm-secrets] Decrypt: tmp-secrets.test-values.yaml\n\n[helm-secrets] Removed: tmp-secrets.test-values.yaml.dec\n"
260260
)
261261
assertEquals(yaml.parseAll(stdout), [
262262
{
@@ -395,7 +395,7 @@ async function startHelmRegistry() {
395395
// eslint-disable-next-line no-constant-condition
396396
while (true) {
397397
if (errorsCount > 10) {
398-
throw new Error("To many errors")
398+
throw new Error("Too many errors")
399399
}
400400
try {
401401
const response = await fetch(`http://localhost:${port}/health`)
@@ -424,8 +424,57 @@ async function startHelmRegistry() {
424424
}
425425
}
426426

427+
async function startOCIRegistry() {
428+
const port = await getAvailablePort()
429+
const { status, stdout, stderr } = await run([
430+
"docker",
431+
"run",
432+
"--rm",
433+
"--detach",
434+
`--publish=${port}:5000`,
435+
"registry:2.8.1@sha256:11bb1b1a54493dc3626f4bd3cdd74f83e4e5157239ea607a70cbe634f50bb89c",
436+
])
437+
438+
if (!status.success) {
439+
throw new Error(`Could not start oci registry ${stderr}`)
440+
}
441+
const containerID = stdout.trim()
442+
443+
let errorsCount = 0
444+
// eslint-disable-next-line no-constant-condition
445+
while (true) {
446+
if (errorsCount > 10) {
447+
throw new Error("Too many errors")
448+
}
449+
try {
450+
const response = await fetch(`http://localhost:${port}/v2/`)
451+
await response.text()
452+
if (response.ok) {
453+
break
454+
}
455+
} catch {
456+
errorsCount++
457+
}
458+
await sleep(200)
459+
}
460+
461+
return {
462+
url: `oci://localhost:${port}`,
463+
async stop() {
464+
const { status, stderr } = await run(["docker", "stop", containerID])
465+
466+
if (!status.success) {
467+
const dockerStopError = stderr
468+
throw new Error(
469+
`Could not stop oci registry docker container ${containerID} ${dockerStopError}`
470+
)
471+
}
472+
},
473+
}
474+
}
475+
427476
Deno.test({
428-
name: "should precompile chart during helm deno push",
477+
name: "should precompile chart during helm deno cm-push",
429478
ignore: !runAllTests,
430479
async fn() {
431480
const helmRegistry = await startHelmRegistry()
@@ -437,7 +486,7 @@ Deno.test({
437486
const chartPath = path.join(chartsBin, "one-service")
438487

439488
const { status, stderr } = await runHelmDeno([
440-
"push",
489+
"cm-push",
441490
chartPath,
442491
helmRegistry.url,
443492
])
@@ -487,7 +536,107 @@ Deno.test({
487536
})
488537

489538
Deno.test({
490-
name: "should clean deno-bundle.js if push wasn't successful",
539+
name: "should precompile chart during helm deno push",
540+
ignore: !runAllTests,
541+
async fn() {
542+
const ociRegistry = await startOCIRegistry()
543+
const fetchDirectory = await Deno.makeTempDir({
544+
prefix: "helm-deno-tests-",
545+
})
546+
547+
try {
548+
const chartPath = path.join(chartsBin, "one-service")
549+
550+
const { status, stderr } = await runHelmDeno([
551+
"push",
552+
chartPath,
553+
ociRegistry.url,
554+
])
555+
556+
if (!status.success) {
557+
console.log(stderr)
558+
}
559+
assertEquals(status.success, true, "should successfully push")
560+
561+
const isDenoBundleExists = await exists(
562+
path.join(chartPath, "deno-bundle.js")
563+
)
564+
assertEquals(
565+
isDenoBundleExists,
566+
false,
567+
"should not have left temporary file deno-bundle.js"
568+
)
569+
570+
const isHelmPackageExists = await exists(
571+
path.join(chartPath, "one-service-1.0.0.tgz")
572+
)
573+
assertEquals(
574+
isHelmPackageExists,
575+
false,
576+
"should not have left temporary file one-service-1.0.0.tgz"
577+
)
578+
579+
const fetchResult = await runHelmDeno([
580+
"fetch",
581+
`${ociRegistry.url}/one-service`,
582+
"--untar",
583+
"--untardir",
584+
fetchDirectory,
585+
])
586+
assertEquals(
587+
fetchResult.status.success,
588+
true,
589+
"should successfully fetch"
590+
)
591+
592+
const isDenoBundleInFetchedChartExists = await exists(
593+
path.join(fetchDirectory, "one-service/deno-bundle.js")
594+
)
595+
assertEquals(
596+
isDenoBundleInFetchedChartExists,
597+
true,
598+
"should have file deno-bundle.js in fetched chart"
599+
)
600+
} finally {
601+
await removeIfExists(fetchDirectory)
602+
await ociRegistry.stop()
603+
}
604+
},
605+
})
606+
607+
Deno.test({
608+
name: "should clean deno-bundle.js if cm-push wasn't successful",
609+
ignore: !runAllTests,
610+
async fn() {
611+
const chartPath = path.join(chartsBin, "one-service")
612+
const denoBundlePath = path.join(chartPath, "deno-bundle.js")
613+
614+
try {
615+
const { status } = await runHelmDeno([
616+
"cm-push",
617+
chartPath,
618+
"http://127.0.0.1:1",
619+
])
620+
621+
if (status.success) {
622+
assertEquals(status.success, false, "should not successfully push")
623+
}
624+
625+
const isDenoBundleExists = await exists(denoBundlePath)
626+
assertEquals(
627+
isDenoBundleExists,
628+
false,
629+
"should not have left temporary file deno-bundle.js"
630+
)
631+
} finally {
632+
await removeIfExists(denoBundlePath)
633+
}
634+
},
635+
})
636+
637+
Deno.test({
638+
name:
639+
"should clean deno-bundle.js and helm package if push wasn't successful",
491640
ignore: !runAllTests,
492641
async fn() {
493642
const chartPath = path.join(chartsBin, "one-service")
@@ -510,6 +659,15 @@ Deno.test({
510659
false,
511660
"should not have left temporary file deno-bundle.js"
512661
)
662+
663+
const isHelmPackageExists = await exists(
664+
path.join(chartPath, "one-service-1.0.0.tgz")
665+
)
666+
assertEquals(
667+
isHelmPackageExists,
668+
false,
669+
"should not have left temporary file one-service-1.0.0.tgz"
670+
)
513671
} finally {
514672
await removeIfExists(denoBundlePath)
515673
}

plugin.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: "deno"
2-
version: "0.2.0-alpha.1"
2+
version: "0.3.0-alpha"
33
usage: "Helm charts with Deno"
44
description: |-
55
This plugin allows to use Deno to prepare kubernetes manifests
66
hooks:
7-
install: "$HELM_PLUGIN_DIR/scripts/install.sh v1.14.0"
8-
update: "$HELM_PLUGIN_DIR/scripts/install.sh v1.14.0"
7+
install: "$HELM_PLUGIN_DIR/scripts/install.sh v1.26.2"
8+
update: "$HELM_PLUGIN_DIR/scripts/install.sh v1.26.2"
99
command: "$HELM_PLUGIN_DIR/scripts/run.sh"

0 commit comments

Comments
 (0)