Skip to content

Commit bbfec3d

Browse files
ari-beckerGabriella439
authored andcommitted
Add package.dhall (#95)
* Add a `package.dhall` file, which re-exports `schemas.dhall` and adds `IntOrString`. The expected hash of `package.dhall` is currently: sha256:3ea8628b704704de295261dfc7626c15247c589c10a266f970cade262543fdda * Update documentation and examples to clarify that expected usage is through the `package.dhall` file. * README.md cleanup: Update tutorial reference URL to the latest `1.28` release of `dhall-haskell`, and change code language hints from `haskell` to `dhall`.
1 parent 7af2ab5 commit bbfec3d

File tree

8 files changed

+167
-157
lines changed

8 files changed

+167
-157
lines changed

README.md

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,22 @@ or the [full tutorial][dhall-tutorial].
3838
Let's say we'd like to configure a Deployment exposing an `nginx` webserver.
3939

4040
In the following example, we:
41-
1. Import the Kubernetes definitions as Dhall Types (the `types.dhall` file) from the local repo.
41+
1. Import the Kubernetes definitions as a Dhall package (the `package.dhall` file) from the local repo.
4242
In your case you will want to replace the local path with a remote one, e.g.
43-
`https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/0a4f0b87fbdd4b679853c81ff804bde7b44336cf/types.dhall`.
43+
`https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/master/package.dhall`
4444
Note: the `sha256:..` is applied to some imports so that:
4545
1. the import is cached locally after the first evaluation, with great time savings (and avoiding network calls)
4646
2. prevent execution if the content of the file changes. This is a security feature, and you
4747
can read more [in Dhall's "Security Guarantees" document][security-hashes]
48-
2. Import the defaults for the above types.
49-
Since _most_ of the fields in any definition are optional, for better ergonomics while
50-
coding Dhall we have generated default values for all types, so we can just use the `//`
51-
operator (right-biased record merge) to add our data to the default configuration.
52-
The pattern looks something like this: `defaultValue // { ourDataHere = ..}`
53-
3. Define the [Deployment][deployment] using this pattern (see the default [here][default-deployment])
54-
and hardcoding the deployment details:
55-
56-
```haskell
48+
Note: instead of using the `package.dhall` from the `master` branch, you may want to use a tagged release,
49+
as the contents of the `master` branch are liable to change without warning.
50+
2. Define the [Deployment][deployment] using the schema pattern and hardcoding the deployment details:
51+
52+
```dhall
5753
-- examples/deploymentSimple.dhall
5854

5955
let kubernetes =
60-
../schemas.dhall sha256:9704063d1e2d17050cb18afae199a24f4cd1264e6c8e696ca94781309e213785
56+
../package.dhall sha256:3ea8628b704704de295261dfc7626c15247c589c10a266f970cade262543fdda
6157

6258
let deployment =
6359
kubernetes.Deployment::{
@@ -134,7 +130,7 @@ and reuse those objects for configuring other things (e.g. configuring the servi
134130
templating documentation, configuring Terraform deployments, you name it).
135131

136132
As an example of that, next we'll define an Ingress (an [Nginx Ingress][nginx-ingress] in this case),
137-
containing stuff like TLS certs and routes for every service - see the [type][Ingress] and [default][Ingress-default] for it.
133+
containing stuff like TLS certs and routes for every service - see the [schema][Ingress].
138134

139135
Things to note in the following example:
140136
- we define the `Service` type inline in the file, but in your case you'll want to have a
@@ -145,7 +141,7 @@ Things to note in the following example:
145141
`mkIngress` function instead of applying it, so you can do something like
146142
`dhall-to-yaml --omitEmpty <<< "./mkIngress.dhall ./myServices.dhall"`
147143

148-
```haskell
144+
```dhall
149145
-- examples/ingress.dhall
150146

151147
let Prelude = ../Prelude.dhall
@@ -154,33 +150,30 @@ let map = Prelude.List.map
154150

155151
let kv = Prelude.JSON.keyText
156152

157-
let types =
158-
../types.dhall sha256:e48e21b807dad217a6c3e631fcaf3e950062310bfb4a8bbcecc330eb7b2f60ed
159-
160153
let kubernetes =
161-
../schemas.dhall sha256:9704063d1e2d17050cb18afae199a24f4cd1264e6c8e696ca94781309e213785
154+
../package.dhall sha256:3ea8628b704704de295261dfc7626c15247c589c10a266f970cade262543fdda
162155

163156
let Service = { name : Text, host : Text, version : Text }
164157

165158
let services = [ { name = "foo", host = "foo.example.com", version = "2.3" } ]
166159

167160
let makeTLS
168-
: Service types.IngressTLS
161+
: Service kubernetes.IngressTLS.Type
169162
= λ(service : Service)
170163
{ hosts = [ service.host ]
171164
, secretName = Some "${service.name}-certificate"
172165
}
173166

174167
let makeRule
175-
: Service types.IngressRule
168+
: Service kubernetes.IngressRule.Type
176169
= λ(service : Service)
177170
{ host = Some service.host
178171
, http =
179172
Some
180173
{ paths =
181174
[ { backend =
182175
{ serviceName = service.name
183-
, servicePort = types.IntOrString.Int 80
176+
, servicePort = kubernetes.IntOrString.Int 80
184177
}
185178
, path = None Text
186179
}
@@ -189,7 +182,7 @@ let makeRule
189182
}
190183

191184
let mkIngress
192-
: List Service types.Ingress
185+
: List Service kubernetes.Ingress.Type
193186
= λ(inputServices : List Service)
194187
let annotations =
195188
[ kv "kubernetes.io/ingress.class" "nginx"
@@ -206,8 +199,14 @@ let mkIngress
206199

207200
let spec =
208201
kubernetes.IngressSpec::{
209-
, tls = map Service types.IngressTLS makeTLS ingressServices
210-
, rules = map Service types.IngressRule makeRule ingressServices
202+
, tls =
203+
map Service kubernetes.IngressTLS.Type makeTLS ingressServices
204+
, rules =
205+
map
206+
Service
207+
kubernetes.IngressRule.Type
208+
makeRule
209+
ingressServices
211210
}
212211

213212
in kubernetes.Ingress::{
@@ -284,7 +283,7 @@ it's possible to use it together with the [union type of all k8s types that we g
284283

285284
So if we want to deploy e.g. a Deployment and a Service together, we can do:
286285

287-
```haskell
286+
```dhall
288287
let k8s = ./typesUnion.dhall
289288

290289
in
@@ -344,10 +343,8 @@ to run this command afterwards.
344343
[kubernetes]: https://kubernetes.io/
345344
[normalization]: https://en.wikipedia.org/wiki/Normalization_property_(abstract_rewriting)
346345
[nginx-ingress]: https://github.com/kubernetes/ingress-nginx
347-
[dhall-tutorial]: http://hackage.haskell.org/package/dhall-1.21.0/docs/Dhall-Tutorial.html
348-
[default-deployment]: ./defaults/io.k8s.api.apps.v1.Deployment.dhall
349-
[deployment]: ./types/io.k8s.api.apps.v1.Deployment.dhall
350-
[Ingress]: ./types/io.k8s.api.extensions.v1beta1.Ingress.dhall
351-
[Ingress-default]: ./default/io.k8s.api.extensions.v1beta1.Ingress.dhall
346+
[dhall-tutorial]: http://hackage.haskell.org/package/dhall-1.28.0/docs/Dhall-Tutorial.html
347+
[deployment]: ./schemas/io.k8s.api.apps.v1.Deployment.dhall
348+
[Ingress]: ./schemas/io.k8s.api.extensions.v1beta1.Ingress.dhall
352349
[prometheus-operator]: https://github.com/coreos/prometheus-operator
353350
[dhall-prometheus-operator]: https://github.com/coralogix/dhall-prometheus-operator

docs/README.md.dhall

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,18 @@ or the [full tutorial][dhall-tutorial].
3939
Let's say we'd like to configure a Deployment exposing an `nginx` webserver.
4040

4141
In the following example, we:
42-
1. Import the Kubernetes definitions as Dhall Types (the `types.dhall` file) from the local repo.
42+
1. Import the Kubernetes definitions as a Dhall package (the `package.dhall` file) from the local repo.
4343
In your case you will want to replace the local path with a remote one, e.g.
44-
`https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/0a4f0b87fbdd4b679853c81ff804bde7b44336cf/types.dhall`.
44+
`https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/master/package.dhall`
4545
Note: the `sha256:..` is applied to some imports so that:
4646
1. the import is cached locally after the first evaluation, with great time savings (and avoiding network calls)
4747
2. prevent execution if the content of the file changes. This is a security feature, and you
4848
can read more [in Dhall's "Security Guarantees" document][security-hashes]
49-
2. Import the defaults for the above types.
50-
Since _most_ of the fields in any definition are optional, for better ergonomics while
51-
coding Dhall we have generated default values for all types, so we can just use the `//`
52-
operator (right-biased record merge) to add our data to the default configuration.
53-
The pattern looks something like this: `defaultValue // { ourDataHere = ..}`
54-
3. Define the [Deployment][deployment] using this pattern (see the default [here][default-deployment])
55-
and hardcoding the deployment details:
56-
57-
```haskell
49+
Note: instead of using the `package.dhall` from the `master` branch, you may want to use a tagged release,
50+
as the contents of the `master` branch are liable to change without warning.
51+
2. Define the [Deployment][deployment] using the schema pattern and hardcoding the deployment details:
52+
53+
```dhall
5854
-- examples/deploymentSimple.dhall
5955

6056
${../examples/deploymentSimple.dhall as Text}
@@ -87,7 +83,7 @@ and reuse those objects for configuring other things (e.g. configuring the servi
8783
templating documentation, configuring Terraform deployments, you name it).
8884

8985
As an example of that, next we'll define an Ingress (an [Nginx Ingress][nginx-ingress] in this case),
90-
containing stuff like TLS certs and routes for every service - see the [type][Ingress] and [default][Ingress-default] for it.
86+
containing stuff like TLS certs and routes for every service - see the [schema][Ingress].
9187

9288
Things to note in the following example:
9389
- we define the `Service` type inline in the file, but in your case you'll want to have a
@@ -98,7 +94,7 @@ Things to note in the following example:
9894
`mkIngress` function instead of applying it, so you can do something like
9995
`dhall-to-yaml --omitEmpty <<< "./mkIngress.dhall ./myServices.dhall"`
10096

101-
```haskell
97+
```dhall
10298
-- examples/ingress.dhall
10399

104100
${../examples/ingress.dhall as Text}
@@ -137,7 +133,7 @@ it's possible to use it together with the [union type of all k8s types that we g
137133

138134
So if we want to deploy e.g. a Deployment and a Service together, we can do:
139135

140-
```haskell
136+
```dhall
141137
let k8s = ./typesUnion.dhall
142138

143139
in
@@ -197,11 +193,9 @@ to run this command afterwards.
197193
[kubernetes]: https://kubernetes.io/
198194
[normalization]: https://en.wikipedia.org/wiki/Normalization_property_(abstract_rewriting)
199195
[nginx-ingress]: https://github.com/kubernetes/ingress-nginx
200-
[dhall-tutorial]: http://hackage.haskell.org/package/dhall-1.21.0/docs/Dhall-Tutorial.html
201-
[default-deployment]: ./defaults/io.k8s.api.apps.v1.Deployment.dhall
202-
[deployment]: ./types/io.k8s.api.apps.v1.Deployment.dhall
203-
[Ingress]: ./types/io.k8s.api.extensions.v1beta1.Ingress.dhall
204-
[Ingress-default]: ./default/io.k8s.api.extensions.v1beta1.Ingress.dhall
196+
[dhall-tutorial]: http://hackage.haskell.org/package/dhall-1.28.0/docs/Dhall-Tutorial.html
197+
[deployment]: ./schemas/io.k8s.api.apps.v1.Deployment.dhall
198+
[Ingress]: ./schemas/io.k8s.api.extensions.v1beta1.Ingress.dhall
205199
[prometheus-operator]: https://github.com/coreos/prometheus-operator
206200
[dhall-prometheus-operator]: https://github.com/coralogix/dhall-prometheus-operator
207201
''

0 commit comments

Comments
 (0)