2021-03-18 06:44:50 +01:00
|
|
|
# Dagger Programmer Guide
|
2021-02-08 20:47:07 +01:00
|
|
|
|
2021-03-25 09:56:26 +01:00
|
|
|
## Overview
|
2021-03-18 06:44:50 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
A Dagger deployment is a continuously running workflow delivering a specific application in a specific way.
|
2021-03-25 09:56:26 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
The same application can be delivered via different deployments, each with a different configuration.
|
|
|
|
For example a production deployment might include manual validation and addition performance testing,
|
|
|
|
while a staging deployment might automatically deploy from a git branch, load test data into the database,
|
|
|
|
and run on a separate cluster.
|
2021-03-25 09:56:26 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
A deployment is made of 3 parts: a deployment plan, inputs, and outputs.
|
2021-03-25 09:56:26 +01:00
|
|
|
|
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
## The Deployment Plan
|
2021-03-25 09:56:26 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
The deployment plan is the source code of the deployment. It is written in [Cue](https://cuelang.org),
|
|
|
|
a powerful declarative language by the creator of GQL, the language used to deploy all applications at Google.
|
2021-02-08 20:47:07 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
The deployment plan lays out every node in the application supply chain, and how they are interconnected:
|
2021-02-08 20:47:07 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
* Development tools: source control, CI, build systems, testing systems
|
|
|
|
* Hosting infrastructure: compute, storage, networking, databases, CDN..
|
|
|
|
* Software dependencies: operating systems, languages, libraries, frameworks, etc.
|
2021-02-08 20:47:07 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
Each node is a standalone software component, with its own code, inputs and outputs.
|
|
|
|
The interconnected network of component inputs and outputs forms a special kind of graph called a [DAG]().
|
2021-02-08 20:47:07 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
Dagger follows a *reactive* programming model: when a component receives a new input
|
|
|
|
(for example a new version of source code, or a new setting), it recomputes its outputs,
|
|
|
|
which then propagate to adjacent nodes, and so on. Thus the flow of data through
|
|
|
|
the DAG mimics the flow of goods through a supply chain.
|
2021-02-08 20:47:07 +01:00
|
|
|
|
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
## Using third-party components
|
2021-02-08 20:47:07 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
Cue includes a complete package system. This makes it easy to create a complex deployment plan in very few
|
|
|
|
lines of codes, simply by composing existing packages.
|
2021-03-18 06:44:50 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
For example, to create a deployment plan involving Github, Heroku and Amazon RDS, one might import the three
|
|
|
|
corresponding packages:
|
2021-03-18 06:44:50 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
```
|
|
|
|
import (
|
|
|
|
"dagger.io/github"
|
|
|
|
"dagger.io/heroku"
|
|
|
|
"dagger.io/amazon/rds"
|
|
|
|
)
|
2021-03-18 06:44:50 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
repo: github.#Repository & {
|
|
|
|
// Github configuration values
|
|
|
|
}
|
2021-03-18 06:44:50 +01:00
|
|
|
|
2021-03-26 23:57:52 +01:00
|
|
|
backend: heroku.#App & {
|
|
|
|
// Heroku configuration values
|
|
|
|
}
|
|
|
|
|
|
|
|
db: rds.#Database & {
|
|
|
|
// RDS configuration values
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
## Creating a new component
|
|
|
|
|
|
|
|
Sometimes there is no third-party component available for a particular node in the application's supply chain;
|
|
|
|
or it exists but needs to be customized.
|
|
|
|
|
|
|
|
A Dagger component is simply a Cue definition annotated with [LLB](https://github.com/moby/buildkit) pipelines.
|
|
|
|
LLB is a standard executable format pioneered by the Buildkit project. It allows Dagger components to run
|
|
|
|
sophisticated pipelines to ingest, and process artifacts such as source code, binaries, database exports, etc.
|
|
|
|
Best of all LLB pipelines can securely build and run any docker container, effectively making Dagger
|
|
|
|
scriptable in any language.
|