Add test for kube-gcp deployment step
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
committed by
Guillaume de Rouville
parent
2a15682386
commit
1830b34e13
25
docs/learn/tests/kube-gcp/deployment/config.cue
Normal file
25
docs/learn/tests/kube-gcp/deployment/config.cue
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/gcp"
|
||||
"alpha.dagger.io/gcp/gcr"
|
||||
"alpha.dagger.io/gcp/gke"
|
||||
)
|
||||
|
||||
// Value created for generic reference of `kubeconfig` in `todoapp.cue`
|
||||
kubeconfig: gkeConfig.kubeconfig
|
||||
|
||||
// gcpConfig used for Google connection
|
||||
gcpConfig: gcp.#Config
|
||||
|
||||
// gkeConfig used for deployment
|
||||
gkeConfig: gke.#KubeConfig & {
|
||||
// config field references `gkeConfig` value to set in once
|
||||
config: gcpConfig
|
||||
}
|
||||
|
||||
// gcrCreds used for remote image push
|
||||
gcrCreds: gcr.#Credentials & {
|
||||
// config field references `gcpConfig` value to set in once
|
||||
config: gcpConfig
|
||||
}
|
19
docs/learn/tests/kube-gcp/deployment/input.cue
Normal file
19
docs/learn/tests/kube-gcp/deployment/input.cue
Normal file
@@ -0,0 +1,19 @@
|
||||
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"
|
||||
}
|
||||
|
||||
registry: "gcr.io/dagger-ci/test"
|
66
docs/learn/tests/kube-gcp/deployment/test/test.cue
Normal file
66
docs/learn/tests/kube-gcp/deployment/test/test.cue
Normal file
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger/op"
|
||||
"alpha.dagger.io/kubernetes"
|
||||
)
|
||||
|
||||
TestEks: {
|
||||
#_GetDeployment: """
|
||||
kubectl describe deployment todoapp | grep 'True'
|
||||
"""
|
||||
|
||||
#_DeleteDeployment: """
|
||||
kubectl delete deployment todoapp
|
||||
kubectl delete service todoapp-service
|
||||
"""
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: kubernetes.#Kubectl
|
||||
},
|
||||
|
||||
op.#WriteFile & {
|
||||
dest: "/kubeconfig"
|
||||
content: todoApp.kubeSrc.kubeconfig
|
||||
},
|
||||
|
||||
op.#WriteFile & {
|
||||
dest: "/getPods.sh"
|
||||
content: #_GetDeployment
|
||||
},
|
||||
|
||||
op.#WriteFile & {
|
||||
dest: "/deletePods.sh"
|
||||
content: #_DeleteDeployment
|
||||
},
|
||||
|
||||
// Get pods
|
||||
op.#Exec & {
|
||||
always: true
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"/getPods.sh",
|
||||
]
|
||||
env: KUBECONFIG: "/kubeconfig"
|
||||
},
|
||||
|
||||
// Delete pods
|
||||
op.#Exec & {
|
||||
always: true
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"/deletePods.sh",
|
||||
]
|
||||
env: KUBECONFIG: "/kubeconfig"
|
||||
},
|
||||
]
|
||||
}
|
61
docs/learn/tests/kube-gcp/deployment/todoapp.cue
Normal file
61
docs/learn/tests/kube-gcp/deployment/todoapp.cue
Normal file
@@ -0,0 +1,61 @@
|
||||
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
|
||||
|
||||
// GCR registry to push images to
|
||||
registry: string & dagger.#Input
|
||||
tag: "test-gcr"
|
||||
|
||||
// source of Kube config file.
|
||||
// set with `dagger input dir manifest ./k8s -e kube`
|
||||
manifest: dagger.#Artifact & dagger.#Input
|
||||
|
||||
// Declarative name
|
||||
todoApp: {
|
||||
// Build an image from the project repository
|
||||
image: docker.#Build & {
|
||||
source: repository
|
||||
}
|
||||
|
||||
// Push the image to a remote registry
|
||||
remoteImage: docker.#Push & {
|
||||
target: "\(registry):\(tag)"
|
||||
source: image
|
||||
auth: {
|
||||
username: gcrCreds.username
|
||||
secret: gcrCreds.secret
|
||||
}
|
||||
}
|
||||
|
||||
// Update the image of the deployment to the deployed image
|
||||
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
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
// Value created for generic reference of `kubeconfig` in `todoapp.cue`
|
||||
kubeSrc: kubernetes.#Resources & {
|
||||
"kubeconfig": kubeconfig
|
||||
source: kustomization
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user