k8s
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Cadey Ratio 2020-01-23 23:33:52 +00:00
parent b23fbb2957
commit 0326661b9a
13 changed files with 289 additions and 1 deletions

View File

@ -1,7 +1,10 @@
FROM xena/dhall-yaml AS dyaml
FROM xena/alpine AS drone
FROM xena/alpine
COPY --from=dyaml /bin/dhall-to-yaml-ng /usr/local/bin/dhall-to-yaml
WORKDIR /drone
COPY ./drone .
RUN dhall-to-yaml --file pipeline.dhall
WORKDIR /k8s
COPY ./k8s .
RUN cd apps && dhall-to-yaml --file hlang.dhall

1
k8s/Prelude.dhall Normal file
View File

@ -0,0 +1 @@
https://prelude.dhall-lang.org/package.dhall sha256:4aa8581954f7734d09b7b21fddbf5d8df901a44b54b4ef26ea71db92de0b1a12

19
k8s/app/config.dhall Normal file
View File

@ -0,0 +1,19 @@
let kubernetes = ../kubernetes.dhall
in { Type =
{ name : Text
, appPort : Natural
, image : Text
, domain : Text
, leIssuer : Text
, envVars : List kubernetes.EnvVar.Type
}
, default =
{ name = ""
, appPort = 5000
, image = ""
, domain = ""
, leIssuer = "staging"
, envVars = [] : List kubernetes.EnvVar.Type
}
}

6
k8s/app/list.dhall Normal file
View File

@ -0,0 +1,6 @@
let typesUnion = ../typesUnion.dhall
in { Type = { apiVersion : Text, kind : Text, items : List typesUnion }
, default =
{ apiVersion = "v1", kind = "List", items = [] : List typesUnion }
}

33
k8s/app/make.dhall Normal file
View File

@ -0,0 +1,33 @@
let Prelude = ../Prelude.dhall
let kubernetes = ../kubernetes.dhall
let typesUnion = ../typesUnion.dhall
let deployment = ../http/deployment.dhall
let ingress = ../http/ingress.dhall
let service = ../http/service.dhall
let Config = ../app/config.dhall
let K8sList = ../app/list.dhall
let buildService =
λ(config : Config.Type)
→ let myService = service config
let myDeployment = deployment config
let myIngress = ingress config
in K8sList::{
, items =
[ typesUnion.Service myService
, typesUnion.Deployment myDeployment
, typesUnion.Ingress myIngress
]
}
in buildService

14
k8s/apps/hlang.dhall Normal file
View File

@ -0,0 +1,14 @@
let makeApp = ../app/make.dhall
let Config = ../app/config.dhall
let cfg =
Config::{
, name = "hlang"
, appPort = 5000
, image = "xena/hlang:latest"
, domain = "h.christine.website"
, leIssuer = "prod"
}
in makeApp cfg

51
k8s/http/deployment.dhall Normal file
View File

@ -0,0 +1,51 @@
let Prelude = ../Prelude.dhall
let kubernetes = ../kubernetes.dhall
let kv = Prelude.JSON.keyText
let Config = ../app/config.dhall
let selector = ./selector.dhall
let podSpec
: Config.Type → kubernetes.PodSpec.Type
= λ(config : Config.Type)
→ kubernetes.PodSpec::{
, containers =
[ kubernetes.Container::{
, name = "web"
, env = config.envVars
, image = Some config.image
, imagePullPolicy = Some "Always"
, ports =
[ kubernetes.ContainerPort::{ containerPort = config.appPort } ]
}
]
, imagePullSecrets =
[ kubernetes.LocalObjectReference::{ name = Some "regcred" } ]
}
let spec =
λ(config : Config.Type)
→ kubernetes.DeploymentSpec::{
, selector = kubernetes.LabelSelector::{
, matchLabels = selector config.name
}
, template = kubernetes.PodTemplateSpec::{
, metadata = kubernetes.ObjectMeta::{
, name = config.name
, labels = selector config.name
}
, spec = Some (podSpec config)
}
}
let deployment =
λ(config : Config.Type)
→ kubernetes.Deployment::{
, metadata = kubernetes.ObjectMeta::{ name = config.name }
, spec = Some (spec config)
}
in deployment

63
k8s/http/ingress.dhall Normal file
View File

@ -0,0 +1,63 @@
let Prelude = ../Prelude.dhall
let kubernetes = ../kubernetes.dhall
let kv = Prelude.JSON.keyText
let Config = ../app/config.dhall
let annotations
: Config.Type → List { mapKey : Text, mapValue : Text }
= λ(config : Config.Type)
→ [ kv "kubernetes.io/ingress.class" "nginx"
, kv
"certmanager.k8s.io/cluster-issuer"
"letsencrypt-${config.leIssuer}"
]
let metadata
: Config.Type → kubernetes.ObjectMeta.Type
= λ(config : Config.Type)
→ kubernetes.ObjectMeta::{
, name = config.name
, labels = [ kv "app" config.name ]
, annotations = annotations config
}
let tls
: Config.Type → kubernetes.IngressTLS.Type
= λ(config : Config.Type)
→ kubernetes.IngressTLS::{
, hosts = [ config.domain ]
, secretName = Some "${config.leIssuer}-certs-${config.name}"
}
let rule
: Config.Type → kubernetes.IngressRule.Type
= λ(config : Config.Type)
→ kubernetes.IngressRule::{
, host = Some config.domain
, http = Some kubernetes.HTTPIngressRuleValue::{
, paths =
[ kubernetes.HTTPIngressPath::{
, backend = kubernetes.IngressBackend::{
, serviceName = config.name
, servicePort = kubernetes.IntOrString.Int config.appPort
}
}
]
}
}
let ingress
: Config.Type → kubernetes.Ingress.Type
= λ(config : Config.Type)
→ kubernetes.Ingress::{
, metadata = metadata config
, spec = Some kubernetes.IngressSpec::{
, tls = [ tls config ]
, rules = [ rule config ]
}
}
in ingress

9
k8s/http/selector.dhall Normal file
View File

@ -0,0 +1,9 @@
let Prelude = ../Prelude.dhall
let kv = Prelude.JSON.keyText
let selector
: Text → List { mapKey : Text, mapValue : Text }
= λ(appName : Text) → [ kv "app" appName ]
in selector

45
k8s/http/service.dhall Normal file
View File

@ -0,0 +1,45 @@
let Prelude = ../Prelude.dhall
let Config = ../app/config.dhall
let kubernetes = ../kubernetes.dhall
let kv = Prelude.JSON.keyText
let annotations
: Config.Type → List { mapKey : Text, mapValue : Text }
= λ(config : Config.Type)
→ [ kv "external-dns.alpha.kubernetes.io/hostname" config.domain
, kv "external-dns.alpha.kubernetes.io/ttl" "120"
, kv "external-dns.alpha.kubernetes.io/cloudflare-proxied" "false"
]
let selector = ./selector.dhall
let spec
: Config.Type → kubernetes.ServiceSpec.Type
= λ(config : Config.Type)
→ kubernetes.ServiceSpec::{
, selector = selector config.name
, type = Some "ClusterIP"
, ports =
[ kubernetes.ServicePort::{
, targetPort = Some (kubernetes.IntOrString.Int config.appPort)
, port = config.appPort
}
]
}
let service
: Config.Type → kubernetes.Service.Type
= λ(config : Config.Type)
→ kubernetes.Service::{
, metadata = kubernetes.ObjectMeta::{
, name = config.name
, labels = [ kv "app" config.name ]
, annotations = annotations config
}
, spec = Some (spec config)
}
in service

1
k8s/kubernetes.dhall Normal file
View File

@ -0,0 +1 @@
https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/master/1.15/package.dhall sha256:4bd5939adb0a5fc83d76e0d69aa3c5a30bc1a5af8f9df515f44b6fc59a0a4815

42
k8s/main.dhall Normal file
View File

@ -0,0 +1,42 @@
let Prelude =
https://prelude.dhall-lang.org/package.dhall sha256:4aa8581954f7734d09b7b21fddbf5d8df901a44b54b4ef26ea71db92de0b1a12
let kubernetes = ./kubernetes.dhall
let kv = Prelude.JSON.keyText
let appName = env:APP_NAME as Text ? "nginx"
let imageName = env:IMAGE_NAME as Text ? "nginx"
let imageTag = env:IMAGE_TAG as Text ? "latest"
let deployment =
kubernetes.Deployment::{
, metadata = kubernetes.ObjectMeta::{ name = appName }
, spec = Some kubernetes.DeploymentSpec::{
, replicas = Some 2
, revisionHistoryLimit = Some 10
, selector = kubernetes.LabelSelector::{
, matchLabels = [ kv "app" appName ]
}
, template = kubernetes.PodTemplateSpec::{
, metadata = kubernetes.ObjectMeta::{
, name = "nginx"
, labels = [ kv "app" appName ]
}
, spec = Some kubernetes.PodSpec::{
, containers =
[ kubernetes.Container::{
, name = "web"
, image = Some "${imageName}:${imageTag}"
, imagePullPolicy = Some "Always"
, ports = [ kubernetes.ContainerPort::{ containerPort = 80 } ]
}
]
}
}
}
}
in deployment

1
k8s/typesUnion.dhall Normal file
View File

@ -0,0 +1 @@
https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/master/1.15/typesUnion.dhall sha256:930a34021bd380209b6763d4a98fb16e1f5608fe5e8d1403d0ec03f6c4a08f00