Skip to content

Commit

Permalink
feat: Add helm action
Browse files Browse the repository at this point in the history
  • Loading branch information
colinjfw committed Aug 23, 2019
1 parent 9005d46 commit 1b24336
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine/helm:2.14.0
RUN apk add --no-cache jq curl bash nodejs && helm init --client-only
COPY . /usr/src/
ENTRYPOINT ["node", "/usr/src/index.js"]
15 changes: 15 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'Deliverybot Helm Action'
description: 'Deploys a helm chart'
author: 'deliverybot'
inputs:
release:
description: 'Helm release name'
namespace:
description: 'Kubernetes namespace name'
chart:
description: 'Helm chart name'
values:
description: 'Helm chart values, expected to be a YAML or JSON string'
runs:
using: 'docker'
image: 'Dockerfile'
42 changes: 42 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const core = require("@actions/core");
const github = require("@actions/github");
const exec = require("@actions/exec");
const fs = require("fs");
const util = require("util");

const writeFile = util.promisify(fs.writeFile);

const required = { required: true };

async function run() {
try {
const release = core.getInput("release", required);
const namespace = core.getInput("namespace", required);
const chart = core.getInput("chart", required);
const values = core.getInput("values");
const context = github.context;
const deployment = context.payload.deployment;
const opts = {
env: {
KUBECONFIG: "./kubeconfig.yml",
}
}

await writeFile("./kubeconfig.yml", process.env.KUBECONFIG);
await writeFile("./values.yml", values);

if (deployment.task === "remove") {
exec.exec("helm", ["delete", release, "--purge"], opts);
} else {
exec.exec("helm", [
"upgrade", release, chart, "--install", "--wait", "--atomic",
"--namespace", namespace, "--values"
], opts);
}
} catch (error) {
core.error(error);
core.setFailed(error.message);
}
}

run();

0 comments on commit 1b24336

Please sign in to comment.