stdlib: implemented kubernetes/helm

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-03-22 12:07:38 -07:00
parent f03018d230
commit cbb4f325bf
2 changed files with 156 additions and 0 deletions

View File

@ -0,0 +1,47 @@
package helm
#code: #"""
# Install Helm
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
# Add the repository
helm repo add repository "${HELM_REPO}"
helm repo update
# If the chart is a file, then it's the chart name
# If it's a directly, then it's the contents of the cart
if [ -f "/helm/chart" ]; then
HELM_CHART="repository/$(cat /helm/chart)"
else
HELM_CHART="/helm/chart"
fi
OPTS=""
OPTS="$OPTS --timeout "$HELM_TIMEOUT""
OPTS="$OPTS --namespace "$KUBE_NAMESPACE""
[ "$HELM_WAIT" = "true" ] && OPTS="$OPTS --wait"
[ "$HELM_ATOMIC" = "true" ] && OPTS="$OPTS --atomic"
[ -f "/helm/values.yaml" ] && OPTS="$OPTS -f /helm/values.yaml"
# Select the namespace
kubectl create namespace "$KUBE_NAMESPACE" || true
case "$HELM_ACTION" in
install)
helm install $OPTS "$HELM_NAME" "$HELM_CHART"
;;
upgrade)
helm upgrade $OPTS "$HELM_NAME" "$HELM_CHART"
;;
installOrUpgrade)
helm upgrade $OPTS --install "$HELM_NAME" "$HELM_CHART"
;;
*)
echo unsupported helm action "$HELM_ACTION"
exit 1
;;
esac
"""#

View File

@ -0,0 +1,109 @@
package helm
import (
"strconv"
"dagger.io/dagger"
"dagger.io/llb"
"dagger.io/kubernetes"
)
// Install a Helm chart
#Chart: {
// Helm deployment name
name: string
// Helm chart to install
chart: string | dagger.#Artifact
// 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
#compute: [
llb.#Load & {
from: kubernetes.#Kubectl & {
version: kubectlVersion
}
},
llb.#Mkdir & {
path: "/helm"
},
llb.#WriteFile & {
dest: "/entrypoint.sh"
content: #code
},
llb.#WriteFile & {
dest: "/kubeconfig"
content: kubeconfig
mode: 0o600
},
if (chart & string) != _|_ {
llb.#WriteFile & {
dest: "/helm/chart"
content: chart
}
},
llb.#Exec & {
always: true
args: [
"/bin/bash",
"--noprofile",
"--norc",
"-eo",
"pipefail",
"/entrypoint.sh",
]
env: {
KUBECONFIG: "/kubeconfig"
KUBE_NAMESPACE: namespace
HELM_VERSION: version
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) != _|_ {
"/helm/varlues.yaml": values
}
if (chart & dagger.#Artifact) != _|_ {
"/helm/chart": from: chart
}
}
},
]
}