No Description

Akshay Mankar 4b7eb6c7cf Add GroupedJob type and function to render 5 years ago
defaults ad240857a7 Remove all "CHANGEME"s from defaults 5 years ago
extractors adce5cc8a4 Add integrity checks to all package.dhall files 5 years ago
helpers adce5cc8a4 Add integrity checks to all package.dhall files 5 years ago
lib b9926995f2 Use Prelude 11.1.0 5 years ago
render 4b7eb6c7cf Add GroupedJob type and function to render 5 years ago
schemas 9d88509466 Update all cache integrity checks 5 years ago
types 4b7eb6c7cf Add GroupedJob type and function to render 5 years ago
utils 38de891aa0 Add extractors for resources and resource types 5 years ago
.travis.yml e65145d9d6 Add travis config to typecheck everything 5 years ago
README.md 2d1441e679 Add instructions to use native rendering 5 years ago
package.dhall 4b7eb6c7cf Add GroupedJob type and function to render 5 years ago

README.md

Dhall Concourse

Concourse types and helpers in dhall.

Note: A lot of this README is inspired (some of it copied) from the dhall-kubernetes README, so thanks to the authors!

Dhall Concourse provides Dhall bindings for Concourse, so you can generate concourse pipelines from Dhall expressions. This will let you easily typecheck, template and modularize your Concourse pipelines.

Why do I need this?

There are a lot of issues one could face while building any non-trivial pipeline. Few of them could be:

  1. Pipeline yaml becomes very big and unmanageable
  2. Same set of jobs are required to be run in different environments
  3. Same set of hooks but with slight changes in all jobs. E.g. slack notifications, releasing resources on failure, etc.

Most common way to deal with these have been to use a templating language like erb, but it gets very messy very fast. We can do a lot better.

Dhall solves all of this, being a programming language with builtin templating, all while being non-Turing complete, strongly typed and strongly normalizing (i.e.: reduces everything to a normal form, no matter how much abstraction you build), so saving you from the "oh-noes-I-made-my-config-in-code-and-now-its-too-abstract" nightmare.

For a Dhall Tutorial, see the readme of the project, or the full tutorial.

Usage

Using dhall-fly

To use dhall-concourse you need to install dhall-fly.

Using dhall-to-json and jq (Experimental)

To use native rendering to render a list of jobs in a file called jobs.dhall, you'd have to write a dhall expression like this:

let Concourse = 
      https://raw.githubusercontent.com/akshaymankar/dhall-concourse/0.3.0/package.dhall

let jobs = ./jobs.dhall

in Concourse.render.pipeline jobs

Now you can render this using dhall-to-json and jq like this:

dhall-to-json <<< './pipeline.dhall' \
  | jq '.resources = (.resources|unique)' \
  | jq '.resource_types = (.resource_types|unique)'

Defining a pipeline

Example 1: Hello World

This dhall expression will create a pipeline with one job, which would have one task. The task would run in a busybox container and echo "Hello Dhall".

let Concourse =
      https://raw.githubusercontent.com/akshaymankar/dhall-concourse/0.3.0/package.dhall

let Prelude =
      https://prelude.dhall-lang.org/v11.1.0/package.dhall sha256:99462c205117931c0919f155a6046aec140c70fb8876d208c7c77027ab19c2fa

let busyboxImage =
      Concourse.schemas.ImageResource::{
      , type = "docker-image"
      , source = Some (toMap { repository = Prelude.JSON.string "busybox" })
      }

let job =
      Concourse.schemas.Job::{
      , name = "hello"
      , plan =
          [ Concourse.helpers.taskStep
              Concourse.schemas.TaskStep::{
              , task = "hello"
              , config =
                  Concourse.Types.TaskSpec.Config
                    Concourse.schemas.TaskConfig::{
                    , image_resource = Some busyboxImage
                    , run =
                        Concourse.schemas.TaskRunConfig::{
                        , path = "bash"
                        , args = Some [ "-c", "echo Hello Dhall" ]
                        }
                    }
              }
          ]
      }

in  [ job ]

To set the pipeline, run this command:

fly -t <TARGET> set-pipeline -p hello-dhall -c <(dhall-fly <pipeline.dhall)

Example 2 (Real World™️)

We in the Eirini team were facing issues with templating our pipeline YAMLs. Recently, we started converting our spruce/aviator based yaml templating into dhall. The work in progress can be seen in our CI repo.