2021-03-22 20:07:38 +01:00
|
|
|
package helm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"dagger.io/dagger"
|
2021-04-06 02:27:51 +02:00
|
|
|
"dagger.io/dagger/op"
|
2021-03-22 20:07:38 +01:00
|
|
|
"dagger.io/kubernetes"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Install a Helm chart
|
|
|
|
#Chart: {
|
|
|
|
// Helm deployment name
|
|
|
|
name: string
|
|
|
|
|
|
|
|
// Helm chart to install
|
2021-04-07 05:57:45 +02:00
|
|
|
chart: dagger.#Artifact
|
|
|
|
|
|
|
|
// Helm chart to install inlined
|
|
|
|
chartInline?: string
|
2021-03-22 20:07:38 +01:00
|
|
|
|
|
|
|
// Helm chart repository (defaults to stable)
|
|
|
|
repository: *"https://charts.helm.sh/stable" | string
|
|
|
|
|
|
|
|
// Helm values (either a YAML string or a Cue structure)
|
|
|
|
values?: string
|
|
|
|
|
|
|
|
// Kubernetes Namespace to deploy to
|
|
|
|
namespace: string
|
|
|
|
|
|
|
|
// Helm action to apply
|
|
|
|
action: *"installOrUpgrade" | "install" | "upgrade"
|
|
|
|
|
|
|
|
// time to wait for any individual Kubernetes operation (like Jobs for hooks)
|
|
|
|
timeout: string | *"5m"
|
|
|
|
|
|
|
|
// if set, will wait until all Pods, PVCs, Services, and minimum number of
|
|
|
|
// Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready state
|
|
|
|
// before marking the release as successful.
|
|
|
|
// It will wait for as long as timeout
|
|
|
|
wait: *true | bool
|
|
|
|
|
|
|
|
// if set, installation process purges chart on fail.
|
|
|
|
// The wait option will be set automatically if atomic is used
|
|
|
|
atomic: *true | bool
|
|
|
|
|
|
|
|
// Kube config file
|
|
|
|
kubeconfig: dagger.#Secret
|
|
|
|
|
|
|
|
// Helm version
|
|
|
|
version: *"3.5.2" | string
|
|
|
|
|
|
|
|
// Kubectl version
|
|
|
|
kubectlVersion: *"v1.19.9" | string
|
|
|
|
|
2021-04-03 00:00:30 +02:00
|
|
|
#up: [
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#Load & {
|
2021-03-22 20:07:38 +01:00
|
|
|
from: kubernetes.#Kubectl & {
|
|
|
|
version: kubectlVersion
|
|
|
|
}
|
|
|
|
},
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#Exec & {
|
2021-03-24 17:30:57 +01:00
|
|
|
env: HELM_VERSION: version
|
|
|
|
args: [
|
|
|
|
"/bin/bash",
|
|
|
|
"--noprofile",
|
|
|
|
"--norc",
|
|
|
|
"-eo",
|
|
|
|
"pipefail",
|
|
|
|
"-c",
|
|
|
|
#"""
|
|
|
|
# Install Yarn
|
|
|
|
curl -sfL -S https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz | \
|
|
|
|
tar -zx -C /tmp && \
|
|
|
|
mv /tmp/linux-amd64/helm /usr/local/bin && \
|
|
|
|
chmod +x /usr/local/bin/helm
|
|
|
|
"""#,
|
|
|
|
]
|
|
|
|
},
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#Mkdir & {
|
2021-03-22 20:07:38 +01:00
|
|
|
path: "/helm"
|
|
|
|
},
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#WriteFile & {
|
2021-03-22 20:07:38 +01:00
|
|
|
dest: "/entrypoint.sh"
|
|
|
|
content: #code
|
|
|
|
},
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#WriteFile & {
|
2021-03-22 20:07:38 +01:00
|
|
|
dest: "/kubeconfig"
|
|
|
|
content: kubeconfig
|
|
|
|
mode: 0o600
|
|
|
|
},
|
2021-04-07 05:57:45 +02:00
|
|
|
if chartInline != _|_ {
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#WriteFile & {
|
2021-03-22 20:07:38 +01:00
|
|
|
dest: "/helm/chart"
|
|
|
|
content: chart
|
|
|
|
}
|
|
|
|
},
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#Exec & {
|
2021-03-22 20:07:38 +01:00
|
|
|
always: true
|
|
|
|
args: [
|
|
|
|
"/bin/bash",
|
|
|
|
"--noprofile",
|
|
|
|
"--norc",
|
|
|
|
"-eo",
|
|
|
|
"pipefail",
|
|
|
|
"/entrypoint.sh",
|
|
|
|
]
|
|
|
|
env: {
|
|
|
|
KUBECONFIG: "/kubeconfig"
|
|
|
|
KUBE_NAMESPACE: namespace
|
|
|
|
|
|
|
|
HELM_REPO: repository
|
|
|
|
HELM_NAME: name
|
|
|
|
HELM_ACTION: action
|
|
|
|
HELM_TIMEOUT: timeout
|
|
|
|
HELM_WAIT: strconv.FormatBool(wait)
|
|
|
|
HELM_ATOMIC: strconv.FormatBool(atomic)
|
|
|
|
}
|
|
|
|
mount: {
|
|
|
|
if (values & string) != _|_ {
|
2021-03-24 17:30:57 +01:00
|
|
|
"/helm/values.yaml": values
|
2021-03-22 20:07:38 +01:00
|
|
|
}
|
2021-04-07 05:57:45 +02:00
|
|
|
if chartInline == _|_ {
|
2021-03-22 20:07:38 +01:00
|
|
|
"/helm/chart": from: chart
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|