2021-03-22 17:52:29 +01:00
|
|
|
package kubernetes
|
|
|
|
|
|
|
|
import (
|
2021-04-06 02:27:51 +02:00
|
|
|
"dagger.io/dagger/op"
|
2021-03-22 17:52:29 +01:00
|
|
|
"dagger.io/dagger"
|
|
|
|
"dagger.io/alpine"
|
|
|
|
)
|
|
|
|
|
|
|
|
#Kubectl: {
|
|
|
|
|
|
|
|
version: *"v1.19.9" | string
|
|
|
|
|
|
|
|
#code: #"""
|
|
|
|
[ -e /usr/local/bin/kubectl ] || {
|
|
|
|
curl -sfL https://dl.k8s.io/${KUBECTL_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl \
|
|
|
|
&& chmod +x /usr/local/bin/kubectl
|
|
|
|
}
|
|
|
|
"""#
|
|
|
|
|
2021-04-03 00:00:30 +02:00
|
|
|
#up: [
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#Load & {
|
2021-03-22 17:52:29 +01:00
|
|
|
from: alpine.#Image & {
|
2021-03-22 20:08:42 +01:00
|
|
|
package: bash: "=5.1.0-r0"
|
|
|
|
package: jq: "=1.6-r1"
|
|
|
|
package: curl: "=7.74.0-r1"
|
2021-03-22 17:52:29 +01:00
|
|
|
}
|
|
|
|
},
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#WriteFile & {
|
2021-03-22 17:52:29 +01:00
|
|
|
dest: "/entrypoint.sh"
|
|
|
|
content: #code
|
|
|
|
},
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#Exec & {
|
2021-03-22 17:52:29 +01:00
|
|
|
args: [
|
|
|
|
"/bin/bash",
|
|
|
|
"--noprofile",
|
|
|
|
"--norc",
|
|
|
|
"-eo",
|
|
|
|
"pipefail",
|
|
|
|
"/entrypoint.sh",
|
|
|
|
]
|
2021-03-22 20:08:42 +01:00
|
|
|
env: KUBECTL_VERSION: version
|
|
|
|
},
|
2021-03-22 17:52:29 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply a Kubernetes configuration
|
|
|
|
#Apply: {
|
2021-04-07 05:57:45 +02:00
|
|
|
|
2021-03-22 17:52:29 +01:00
|
|
|
// Kubernetes config to deploy
|
2021-04-07 05:57:45 +02:00
|
|
|
source: dagger.#Artifact
|
|
|
|
|
|
|
|
// Kubernetes config to deploy inlined in a string
|
|
|
|
sourceInline?: string
|
2021-03-22 17:52:29 +01:00
|
|
|
|
|
|
|
// Kubernetes Namespace to deploy to
|
|
|
|
namespace: string
|
|
|
|
|
|
|
|
// Version of kubectl client
|
|
|
|
version: *"v1.19.9" | string
|
|
|
|
|
|
|
|
// Kube config file
|
|
|
|
kubeconfig: dagger.#Secret
|
|
|
|
|
|
|
|
#code: #"""
|
|
|
|
kubectl create namespace "$KUBE_NAMESPACE" || true
|
2021-04-07 05:57:45 +02:00
|
|
|
ls -la /source
|
|
|
|
cat /source
|
2021-03-22 17:52:29 +01:00
|
|
|
kubectl --namespace "$KUBE_NAMESPACE" apply -R -f /source
|
|
|
|
"""#
|
|
|
|
|
2021-04-03 00:00:30 +02:00
|
|
|
#up: [
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#Load & {
|
2021-03-22 20:08:42 +01:00
|
|
|
from: #Kubectl & {"version": version}
|
2021-03-22 17:52:29 +01:00
|
|
|
},
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#WriteFile & {
|
2021-03-22 17:52:29 +01:00
|
|
|
dest: "/entrypoint.sh"
|
|
|
|
content: #code
|
|
|
|
},
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#WriteFile & {
|
2021-03-22 17:52:29 +01:00
|
|
|
dest: "/kubeconfig"
|
|
|
|
content: kubeconfig
|
|
|
|
mode: 0o600
|
|
|
|
},
|
2021-04-07 05:57:45 +02:00
|
|
|
if sourceInline != _|_ {
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#WriteFile & {
|
2021-03-22 20:08:42 +01:00
|
|
|
dest: "/source"
|
2021-03-22 17:52:29 +01:00
|
|
|
content: source
|
|
|
|
}
|
2021-03-22 20:08:42 +01:00
|
|
|
},
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#Exec & {
|
2021-03-22 17:52:29 +01:00
|
|
|
always: true
|
|
|
|
args: [
|
|
|
|
"/bin/bash",
|
|
|
|
"--noprofile",
|
|
|
|
"--norc",
|
|
|
|
"-eo",
|
|
|
|
"pipefail",
|
|
|
|
"/entrypoint.sh",
|
|
|
|
]
|
|
|
|
env: {
|
2021-03-22 20:08:42 +01:00
|
|
|
KUBECONFIG: "/kubeconfig"
|
2021-03-22 17:52:29 +01:00
|
|
|
KUBE_NAMESPACE: namespace
|
|
|
|
}
|
2021-04-07 05:57:45 +02:00
|
|
|
if sourceInline == _|_ {
|
2021-03-22 20:08:42 +01:00
|
|
|
mount: "/source": from: source
|
2021-03-22 17:52:29 +01:00
|
|
|
}
|
2021-03-22 20:08:42 +01:00
|
|
|
},
|
2021-03-22 17:52:29 +01:00
|
|
|
]
|
|
|
|
}
|