Add kubernetes test for kind cue-manifest

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau
2021-08-13 19:11:50 +02:00
committed by Guillaume de Rouville
parent bdcb917943
commit a91181bb5f
11 changed files with 213 additions and 158 deletions

View File

@@ -0,0 +1,43 @@
package main
// Deployment template containing all the common boilerplate shared by
// deployments of this application.
#Deployment: {
// Name of the deployment. This will be used to label resources automatically
// and generate selectors.
name: string
// Container image.
image: string
// 80 is the default port.
port: *80 | int
// 1 is the default, but we allow any number.
replicas: *1 | int
// Deployment manifest. Uses the name, image, port and replicas above to
// generate the resource manifest.
manifest: {
apiVersion: "apps/v1"
kind: "Deployment"
metadata: {
"name": name
labels: app: name
}
spec: {
"replicas": replicas
selector: matchLabels: app: name
template: {
metadata: labels: app: name
spec: containers: [{
"name": name
"image": image
ports: [{
containerPort: port
}]
}]
}
}
}
}

View File

@@ -0,0 +1,11 @@
package main
import (
"alpha.dagger.io/git"
)
repository: git.#Repository & {
remote: "https://github.com/dagger/examples.git"
ref: "main"
subdir: "todoapp"
}

View File

@@ -0,0 +1,29 @@
package main
import (
"encoding/yaml"
)
// Define and generate kubernetes deployment to deploy to kubernetes cluster
#AppManifest: {
// Name of the application
name: string
// Image to deploy to
image: string
// Define a kubernetes deployment object
deployment: #Deployment & {
"name": name
"image": image
}
// Define a kubernetes service object
service: #Service & {
"name": name
ports: http: deployment.port
}
// Merge definitions and convert them back from CUE to YAML
manifest: yaml.MarshalStream([deployment.manifest, service.manifest])
}

View File

@@ -0,0 +1,36 @@
package main
// Service template containing all the common boilerplate shared by
// services of this application.
#Service: {
// Name of the service. This will be used to label resources automatically
// and generate selector.
name: string
// NodePort is the default service type.
type: *"NodePort" | "LoadBalancer" | "ClusterIP" | "ExternalName"
// Ports where the service should listen
ports: [string]: number
// Service manifest. Uses the name, type and ports above to
// generate the resource manifest.
manifest: {
apiVersion: "v1"
kind: "Service"
metadata: {
"name": "\(name)-service"
labels: app: name
}
spec: {
"type": type
"ports": [
for k, v in ports {
name: k
port: v
},
]
selector: app: name
}
}
}

View File

@@ -0,0 +1,41 @@
package main
import (
"alpha.dagger.io/dagger"
"alpha.dagger.io/docker"
"alpha.dagger.io/kubernetes"
)
// 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"
// 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
}
// Generate deployment manifest
deployment: #AppManifest & {
name: "todoapp"
image: remoteImage.ref
}
// Deploy the customized manifest to a kubernetes cluster
kubeSrc: kubernetes.#Resources & {
"kubeconfig": kubeconfig
manifest: deployment.manifest
}
}