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-04-14 23:06:51 +02:00
|
|
|
package: bash: "=~5.1"
|
|
|
|
package: jq: "=~1.6"
|
|
|
|
package: curl: "=~7.76"
|
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-05-26 12:23:44 +02:00
|
|
|
source: dagger.#Artifact @dagger(input)
|
2021-04-07 05:57:45 +02:00
|
|
|
|
|
|
|
// Kubernetes config to deploy inlined in a string
|
2021-05-26 12:23:44 +02:00
|
|
|
sourceInline?: string @dagger(input)
|
2021-03-22 17:52:29 +01:00
|
|
|
|
|
|
|
// Kubernetes Namespace to deploy to
|
2021-05-26 12:23:44 +02:00
|
|
|
namespace: string @dagger(input)
|
2021-03-22 17:52:29 +01:00
|
|
|
|
|
|
|
// Version of kubectl client
|
2021-05-26 12:23:44 +02:00
|
|
|
version: *"v1.19.9" | string @dagger(input)
|
2021-03-22 17:52:29 +01:00
|
|
|
|
|
|
|
// Kube config file
|
2021-05-26 12:23:44 +02:00
|
|
|
kubeconfig: dagger.#Secret @dagger(input)
|
2021-03-22 17:52:29 +01:00
|
|
|
|
|
|
|
#code: #"""
|
|
|
|
kubectl create namespace "$KUBE_NAMESPACE" || true
|
|
|
|
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-04-09 14:37:42 +02:00
|
|
|
content: sourceInline
|
2021-03-22 17:52:29 +01:00
|
|
|
}
|
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
|
|
|
]
|
|
|
|
}
|