Add kubernetes test for kind deployment
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
parent
b145d03192
commit
bdcb917943
@ -434,64 +434,7 @@ Let's see how to deploy an image locally and push it to the local cluster
|
|||||||
- `remoteImage`, push an image to the registry
|
- `remoteImage`, push an image to the registry
|
||||||
- `kustomization`, apply kustomization to image
|
- `kustomization`, apply kustomization to image
|
||||||
|
|
||||||
```cue title="todoapp/kube/todoapp.cue"
|
```cue file=tests/kube-kind/deployment/todoapp.cue title="todoapp/kube/todoapp.cue"
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/yaml"
|
|
||||||
|
|
||||||
"alpha.dagger.io/dagger"
|
|
||||||
"alpha.dagger.io/docker"
|
|
||||||
"alpha.dagger.io/kubernetes"
|
|
||||||
"alpha.dagger.io/kubernetes/kustomize"
|
|
||||||
)
|
|
||||||
|
|
||||||
// input: source code repository, must contain a Dockerfile
|
|
||||||
// set with `dagger input dir repository . -e kube`
|
|
||||||
repository: dagger.#Artifact & dagger.#Input
|
|
||||||
|
|
||||||
// Registry to push images to
|
|
||||||
registry: string & dagger.#Input
|
|
||||||
tag: "test-kind"
|
|
||||||
|
|
||||||
// input: kubernetes objects directory to deploy to
|
|
||||||
// set with `dagger input dir manifest ./k8s -e kube`
|
|
||||||
manifest: dagger.#Artifact & dagger.#Input
|
|
||||||
|
|
||||||
// Todoapp deployment pipeline
|
|
||||||
todoApp: {
|
|
||||||
// Build the image from repositoru artifact
|
|
||||||
image: docker.#Build & {
|
|
||||||
source: repository
|
|
||||||
}
|
|
||||||
|
|
||||||
// Push image to registry
|
|
||||||
remoteImage: docker.#Push & {
|
|
||||||
target: "\(registry):\(tag)"
|
|
||||||
source: image
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the image from manifest to use the deployed one
|
|
||||||
kustomization: kustomize.#Kustomize & {
|
|
||||||
source: manifest
|
|
||||||
|
|
||||||
// Convert CUE to YAML.
|
|
||||||
kustomization: yaml.Marshal({
|
|
||||||
resources: ["deployment.yaml", "service.yaml"]
|
|
||||||
|
|
||||||
images: [{
|
|
||||||
name: "public.ecr.aws/j7f8d3t2/todoapp"
|
|
||||||
newName: remoteImage.ref
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deploy the customized manifest to a kubernetes cluster
|
|
||||||
kubeSrc: kubernetes.#Resources & {
|
|
||||||
"kubeconfig": kubeconfig
|
|
||||||
source: kustomization
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
2
docs/learn/tests/.dagger/env/kube-kind-deployment/.gitignore
vendored
Normal file
2
docs/learn/tests/.dagger/env/kube-kind-deployment/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# dagger state
|
||||||
|
state/**
|
26
docs/learn/tests/.dagger/env/kube-kind-deployment/values.yaml
vendored
Normal file
26
docs/learn/tests/.dagger/env/kube-kind-deployment/values.yaml
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
plan:
|
||||||
|
package: ./kube-kind/deployment
|
||||||
|
name: kube-kind-deployment
|
||||||
|
inputs:
|
||||||
|
registry:
|
||||||
|
text: localhost:5000/kind
|
||||||
|
sops:
|
||||||
|
kms: []
|
||||||
|
gcp_kms: []
|
||||||
|
azure_kv: []
|
||||||
|
hc_vault: []
|
||||||
|
age:
|
||||||
|
- recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk
|
||||||
|
enc: |
|
||||||
|
-----BEGIN AGE ENCRYPTED FILE-----
|
||||||
|
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBxRlpLcVVoTnVLUkVOMlpN
|
||||||
|
eXRzdkgvNjNGYWNzaVBBNUJEZFdnbXhMTzI0CjlsNGVDcHlHTDk3VU1ycEVvVmti
|
||||||
|
SmlGVDFZUTlKWm9OVWdwK1Q4ZmZXZDgKLS0tIDRNRW4razlkbnFMdDV1UU52aHdT
|
||||||
|
d1pSR1VtUU12VmlDTEdyazgwdkdwQkkK6NZclDyaf5YwBWAbL6VmJWzCNT+cFXsU
|
||||||
|
gM9y8Bo/VXHx2uR5ceLVtAGvTl4XuIGTqBEqpIelTJAD3TUj2C2upg==
|
||||||
|
-----END AGE ENCRYPTED FILE-----
|
||||||
|
lastmodified: "2021-08-13T16:37:05Z"
|
||||||
|
mac: ENC[AES256_GCM,data:qO6rbMUVpVs5dwmZm7nHSsGPysJXcIkvpRMeEhihUXGcZ6IeVX2dmuwOXMTQWtJ6HwhM+wdYyj5IIlujYARC+FYj3ldrYlCs/kPzfcDkJm1K9PXcKKTm5wV7v0hcTvmwe9ju5VSNWtLvXNsE8+u8hz9Wnnz4e0QQCvNQmUHJrNo=,iv:+JuEpyBRXZ4xb4KQ15p8OK7QPqB4iYtgSyPDxK9949w=,tag:9m27tAGWjxr87DzEzP5vmQ==,type:str]
|
||||||
|
pgp: []
|
||||||
|
encrypted_suffix: secret
|
||||||
|
version: 3.7.1
|
@ -90,7 +90,22 @@ setup() {
|
|||||||
dagger -w "$DAGGER_SANDBOX" -e kube-kind-basic up
|
dagger -w "$DAGGER_SANDBOX" -e kube-kind-basic up
|
||||||
|
|
||||||
# Check deployment
|
# Check deployment
|
||||||
kubectl get deployment
|
kubectl describe deployment todoapp | grep 'True'
|
||||||
|
|
||||||
|
# Clean
|
||||||
|
kubectl delete deployments --all
|
||||||
|
|
||||||
|
#################### DEPLOYMENT ####################
|
||||||
|
copy_to_sandbox kube-kind-deployment kube-kind
|
||||||
|
|
||||||
|
# Add kubeconfig
|
||||||
|
dagger -w "$DAGGER_SANDBOX" -e kube-kind-deployment input text kubeconfig -f "$HOME"/.kube/config
|
||||||
|
|
||||||
|
# Up deployment
|
||||||
|
dagger -w "$DAGGER_SANDBOX" -e kube-kind-deployment up
|
||||||
|
|
||||||
|
# Check deployment
|
||||||
|
kubectl describe deployment todoapp | grep 'True'
|
||||||
|
|
||||||
# Clean
|
# Clean
|
||||||
kubectl delete deployments --all
|
kubectl delete deployments --all
|
||||||
|
17
docs/learn/tests/kube-kind/deployment/manifest.cue
Normal file
17
docs/learn/tests/kube-kind/deployment/manifest.cue
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"alpha.dagger.io/git"
|
||||||
|
)
|
||||||
|
|
||||||
|
manifest: git.#Repository & {
|
||||||
|
remote: "https://github.com/dagger/examples.git"
|
||||||
|
ref: "main"
|
||||||
|
subdir: "todoapp/k8s"
|
||||||
|
}
|
||||||
|
|
||||||
|
repository: git.#Repository & {
|
||||||
|
remote: "https://github.com/dagger/examples.git"
|
||||||
|
ref: "main"
|
||||||
|
subdir: "todoapp"
|
||||||
|
}
|
57
docs/learn/tests/kube-kind/deployment/todoapp.cue
Normal file
57
docs/learn/tests/kube-kind/deployment/todoapp.cue
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/yaml"
|
||||||
|
|
||||||
|
"alpha.dagger.io/dagger"
|
||||||
|
"alpha.dagger.io/docker"
|
||||||
|
"alpha.dagger.io/kubernetes"
|
||||||
|
"alpha.dagger.io/kubernetes/kustomize"
|
||||||
|
)
|
||||||
|
|
||||||
|
// input: source code repository, must contain a Dockerfile
|
||||||
|
// set with `dagger input dir repository . -e kube`
|
||||||
|
repository: dagger.#Artifact & dagger.#Input
|
||||||
|
|
||||||
|
// Registry to push images to
|
||||||
|
registry: string & dagger.#Input
|
||||||
|
tag: "test-kind"
|
||||||
|
|
||||||
|
// input: kubernetes objects directory to deploy to
|
||||||
|
// set with `dagger input dir manifest ./k8s -e kube`
|
||||||
|
manifest: dagger.#Artifact & dagger.#Input
|
||||||
|
|
||||||
|
// Todoapp deployment pipeline
|
||||||
|
todoApp: {
|
||||||
|
// Build the image from repositoru artifact
|
||||||
|
image: docker.#Build & {
|
||||||
|
source: repository
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push image to registry
|
||||||
|
remoteImage: docker.#Push & {
|
||||||
|
target: "\(registry):\(tag)"
|
||||||
|
source: image
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the image from manifest to use the deployed one
|
||||||
|
kustomization: kustomize.#Kustomize & {
|
||||||
|
source: manifest
|
||||||
|
|
||||||
|
// Convert CUE to YAML.
|
||||||
|
kustomization: yaml.Marshal({
|
||||||
|
resources: ["deployment.yaml", "service.yaml"]
|
||||||
|
|
||||||
|
images: [{
|
||||||
|
name: "public.ecr.aws/j7f8d3t2/todoapp"
|
||||||
|
newName: remoteImage.ref
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deploy the customized manifest to a kubernetes cluster
|
||||||
|
kubeSrc: kubernetes.#Resources & {
|
||||||
|
"kubeconfig": kubeconfig
|
||||||
|
source: kustomization
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user