Tristan de Cacqueray
Februrary 18, 2021
If like me, you are tired of writting YAML files, this talk is for you.
NO
!= false
.a programmable configuration language that you can think of as: JSON + functions + types + imports
$ sudo dnf install -y dhall dhall-json
Simple scalar types:
"Hello, world!"
True
, False
0
, 1
, 2
, …-2
, -1
, +0
, +1
, +2
, …3.14159265
, 6.0221409e+23
Complex composite types:
Some 1
, None Natural
[1, 2, 3]
{ x = 1.2, y = -2.5 }
< A | C | G | T >.A
Example configuration:
{ job =
{ name = "koji-build-x86_64"
, run = "playbooks/rpmbuild.yaml"
, vars = { arch = "x86_64", build = < scratch | final >.scratch }
}
}
… corresponds to this YAML:
let job =
let arch = "x86_64"
let build = < scratch | final >.scratch
in { name = "koji-build-${arch}"
, run = "playbooks/rpmbuild.yaml"
, vars = { arch, build }
}
in { job }
-- ./koji-job.dhall file content:
let arch = "x86_64"
let build = < scratch | final >.scratch
in { name = "koji-build-${arch}"
, run = "playbooks/rpmbuild.yaml"
, vars = { arch, build }
}
-- ./koji-job.dhall
\(build : < scratch | final >) ->
\(arch : Text) ->
{ name = "koji-build-${arch}"
, run = "playbooks/rpmbuild.yaml"
, vars = { arch, build }
}
… corresponds to this YAML:
https://softwarefactory-project.io/cgit/software-factory/sf-infra/plain/Infra/OpenShift/deployWithEnv.dhall
"service-name"
"quay.io/software-factory/service-name:v1"
8080
"service-name.prod.psi.redhat.com"
(toMap { option = "value", logLevel = "INFO" })
… corresponds to this YAML:
---
apiVersion: v1
kind: Route
metadata:
name: service-name
spec:
host: service-name.prod.psi.redhat.com
path: /
port:
targetPort: 8080
tls:
insecureEdgeTerminationPolicy: Redirect
termination: edge
to:
kind: Service
name: service-name-service
weight: 100
---
apiVersion: v1
kind: Service
metadata:
name: service-name-service
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: service-name
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: service-name
spec:
replicas: 1
selector:
matchLabels:
app: service-name
template:
metadata:
labels:
app: service-name
name: service-name
spec:
containers:
- env:
- name: logLevel
value: INFO
- name: option
value: value
image: quay.io/software-factory/service-name:v1
name: service-name
ports:
- containerPort: 8080
Adopt Dhall in four steps:
Dhall can also be used for:
Import supports semantic integrity checks.
Dhall code can be tested with inlined assertion.
Dhall diff can compare the semantic of two expressions.
Dhall is total and not Turing complete:
Mature community and ecosystem: awesome-dhall
Checkout the Language tour
Learn more at https://dhall-lang.org