Skip to content

Commit

Permalink
Push to the OCI registry and debug chart with console.error() (#31)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
verdel authored Oct 27, 2022
1 parent a7223ae commit 5dca343
Show file tree
Hide file tree
Showing 18 changed files with 629 additions and 335 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: javascript

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install dependencies
run: make install-tools
Expand All @@ -16,4 +16,4 @@ jobs:
run: make lint

- name: Run editorconfig linter
uses: docker://mstruebing/editorconfig-checker:2.3.3
uses: docker://mstruebing/editorconfig-checker:2.4.0
18 changes: 9 additions & 9 deletions .github/workflows/test-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: denolib/setup-deno@v2
- uses: denoland/setup-deno@v1
with:
deno-version: v1.8.x
deno-version: v1.26.x

- name: Install Age Encryption Tool
run: |
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
wget https://github.com/FiloSottile/age/releases/download/v1.0.0/age-v1.0.0-linux-amd64.tar.gz -O age.tar.gz
tar xvf age.tar.gz age/age age/age-keygen
echo "$PWD/age" >> $GITHUB_PATH
- name: Install sops
uses: mdgreenwald/mozilla-sops-action@55d09a81cc2b0b5235af697e3b84b1f502f63025 # v1 at 14 April 2020
uses: mdgreenwald/mozilla-sops-action@v1.2.0
with:
version: 3.7.1
version: 3.7.3

- name: Install helm-diff
run: |
helm plugin install https://github.com/databus23/helm-diff --version v3.1.3
helm plugin install https://github.com/databus23/helm-diff --version v3.6.0
- name: Install helm-secrets
run: |
helm plugin install https://github.com/jkroepke/helm-secrets --version v3.6.1
helm plugin install https://github.com/jkroepke/helm-secrets --version v4.1.1
- name: Install helm-push
run: |
helm plugin install https://github.com/chartmuseum/helm-push --version v0.9.0
helm plugin install https://github.com/chartmuseum/helm-push --version v0.10.3
- name: Install plugin
run: make install-plugin
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: denolib/setup-deno@v2
- uses: denoland/setup-deno@v1
with:
deno-version: v1.8.x
deno-version: v1.26.x

- name: Install plugin
run: make install-plugin
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
deno 1.14.0
deno 1.26.2
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ install-tools:
@ yarn --frozen-lockfile

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

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

update-deps:
deno run -A https://deno.land/x/udd@0.5.0/main.ts src/**/*.ts
deno run -A https://deno.land/x/udd@0.8.1/main.ts src/*.ts
deno run -A https://deno.land/x/udd@0.8.1/main.ts src/**/*.ts
182 changes: 170 additions & 12 deletions e2e-tests/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Use fork until https://github.com/piyush-bhatt/deno-port/pull/1 is merged
import { getAvailablePort } from "https://raw.githubusercontent.com/Nitive/deno-port/fix-getting-random-port/mod.ts"

import { exists } from "https://deno.land/std@0.107.0/fs/exists.ts"
import * as path from "https://deno.land/std@0.107.0/path/mod.ts"
import * as yaml from "https://deno.land/std@0.107.0/encoding/yaml.ts"
import { exists } from "https://deno.land/std@0.160.0/fs/exists.ts"
import * as path from "https://deno.land/std@0.160.0/path/mod.ts"
import * as yaml from "https://deno.land/std@0.160.0/encoding/yaml.ts"
import {
assertEquals,
assertStringIncludes,
} from "https://deno.land/std@0.107.0/testing/asserts.ts"
} from "https://deno.land/std@0.160.0/testing/asserts.ts"
import { ignoreNotFoundError } from "../src/utils/ignore-not-found-error.ts"
import { waitForProcess } from "../src/utils/process.ts"

Expand Down Expand Up @@ -61,7 +60,7 @@ async function assertYamlParsable(yamlFileContent: string) {
try {
await yaml.parseAll(yamlFileContent)
} catch (err) {
throw new Error(`Cloud parse yaml context ${err} ${yamlFileContent}`)
throw new Error(`Could not parse yaml context ${err} ${yamlFileContent}`)
}
}

Expand Down Expand Up @@ -163,9 +162,10 @@ Supported helm [command] is:
- template
- install
- upgrade
- push
- diff (helm plugin)
- secrets (helm plugin)
- push (helm plugin)
- cm-push (helm plugin)
You must use the options of the supported commands in strict order:
$ helm <secrets> <diff> [upgrade/template/install] [RELEASE] [CHART] <flags>
Expand Down Expand Up @@ -256,7 +256,7 @@ Deno.test({

assertEquals(
stderr,
"[helm-secrets] Decrypt: tmp-secrets.test-values.yaml\n\n[helm-secrets] Removed: ./tmp-secrets.test-values.yaml.dec\n"
"[helm-secrets] Decrypt: tmp-secrets.test-values.yaml\n\n[helm-secrets] Removed: tmp-secrets.test-values.yaml.dec\n"
)
assertEquals(yaml.parseAll(stdout), [
{
Expand Down Expand Up @@ -395,7 +395,7 @@ async function startHelmRegistry() {
// eslint-disable-next-line no-constant-condition
while (true) {
if (errorsCount > 10) {
throw new Error("To many errors")
throw new Error("Too many errors")
}
try {
const response = await fetch(`http://localhost:${port}/health`)
Expand Down Expand Up @@ -424,8 +424,57 @@ async function startHelmRegistry() {
}
}

async function startOCIRegistry() {
const port = await getAvailablePort()
const { status, stdout, stderr } = await run([
"docker",
"run",
"--rm",
"--detach",
`--publish=${port}:5000`,
"registry:2.8.1@sha256:11bb1b1a54493dc3626f4bd3cdd74f83e4e5157239ea607a70cbe634f50bb89c",
])

if (!status.success) {
throw new Error(`Could not start oci registry ${stderr}`)
}
const containerID = stdout.trim()

let errorsCount = 0
// eslint-disable-next-line no-constant-condition
while (true) {
if (errorsCount > 10) {
throw new Error("Too many errors")
}
try {
const response = await fetch(`http://localhost:${port}/v2/`)
await response.text()
if (response.ok) {
break
}
} catch {
errorsCount++
}
await sleep(200)
}

return {
url: `oci://localhost:${port}`,
async stop() {
const { status, stderr } = await run(["docker", "stop", containerID])

if (!status.success) {
const dockerStopError = stderr
throw new Error(
`Could not stop oci registry docker container ${containerID} ${dockerStopError}`
)
}
},
}
}

Deno.test({
name: "should precompile chart during helm deno push",
name: "should precompile chart during helm deno cm-push",
ignore: !runAllTests,
async fn() {
const helmRegistry = await startHelmRegistry()
Expand All @@ -437,7 +486,7 @@ Deno.test({
const chartPath = path.join(chartsBin, "one-service")

const { status, stderr } = await runHelmDeno([
"push",
"cm-push",
chartPath,
helmRegistry.url,
])
Expand Down Expand Up @@ -487,7 +536,107 @@ Deno.test({
})

Deno.test({
name: "should clean deno-bundle.js if push wasn't successful",
name: "should precompile chart during helm deno push",
ignore: !runAllTests,
async fn() {
const ociRegistry = await startOCIRegistry()
const fetchDirectory = await Deno.makeTempDir({
prefix: "helm-deno-tests-",
})

try {
const chartPath = path.join(chartsBin, "one-service")

const { status, stderr } = await runHelmDeno([
"push",
chartPath,
ociRegistry.url,
])

if (!status.success) {
console.log(stderr)
}
assertEquals(status.success, true, "should successfully push")

const isDenoBundleExists = await exists(
path.join(chartPath, "deno-bundle.js")
)
assertEquals(
isDenoBundleExists,
false,
"should not have left temporary file deno-bundle.js"
)

const isHelmPackageExists = await exists(
path.join(chartPath, "one-service-1.0.0.tgz")
)
assertEquals(
isHelmPackageExists,
false,
"should not have left temporary file one-service-1.0.0.tgz"
)

const fetchResult = await runHelmDeno([
"fetch",
`${ociRegistry.url}/one-service`,
"--untar",
"--untardir",
fetchDirectory,
])
assertEquals(
fetchResult.status.success,
true,
"should successfully fetch"
)

const isDenoBundleInFetchedChartExists = await exists(
path.join(fetchDirectory, "one-service/deno-bundle.js")
)
assertEquals(
isDenoBundleInFetchedChartExists,
true,
"should have file deno-bundle.js in fetched chart"
)
} finally {
await removeIfExists(fetchDirectory)
await ociRegistry.stop()
}
},
})

Deno.test({
name: "should clean deno-bundle.js if cm-push wasn't successful",
ignore: !runAllTests,
async fn() {
const chartPath = path.join(chartsBin, "one-service")
const denoBundlePath = path.join(chartPath, "deno-bundle.js")

try {
const { status } = await runHelmDeno([
"cm-push",
chartPath,
"http://127.0.0.1:1",
])

if (status.success) {
assertEquals(status.success, false, "should not successfully push")
}

const isDenoBundleExists = await exists(denoBundlePath)
assertEquals(
isDenoBundleExists,
false,
"should not have left temporary file deno-bundle.js"
)
} finally {
await removeIfExists(denoBundlePath)
}
},
})

Deno.test({
name:
"should clean deno-bundle.js and helm package if push wasn't successful",
ignore: !runAllTests,
async fn() {
const chartPath = path.join(chartsBin, "one-service")
Expand All @@ -510,6 +659,15 @@ Deno.test({
false,
"should not have left temporary file deno-bundle.js"
)

const isHelmPackageExists = await exists(
path.join(chartPath, "one-service-1.0.0.tgz")
)
assertEquals(
isHelmPackageExists,
false,
"should not have left temporary file one-service-1.0.0.tgz"
)
} finally {
await removeIfExists(denoBundlePath)
}
Expand Down
6 changes: 3 additions & 3 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: "deno"
version: "0.2.0-alpha.1"
version: "0.3.0-alpha"
usage: "Helm charts with Deno"
description: |-
This plugin allows to use Deno to prepare kubernetes manifests
hooks:
install: "$HELM_PLUGIN_DIR/scripts/install.sh v1.14.0"
update: "$HELM_PLUGIN_DIR/scripts/install.sh v1.14.0"
install: "$HELM_PLUGIN_DIR/scripts/install.sh v1.26.2"
update: "$HELM_PLUGIN_DIR/scripts/install.sh v1.26.2"
command: "$HELM_PLUGIN_DIR/scripts/run.sh"
Loading

0 comments on commit 5dca343

Please sign in to comment.