This is a demo of using Dagger to implement the following CI/CD DAG:
More context can be found in my PlatformCon 2022 talk.
To summarize here:
The goal of this DAG is to build, test and release a simple client and server. For the demo, the server is an AWS Lambda function (written in javascript). The client is a simple go binary that just invokes the Lambda function (using a public HTTP endpoint) and prints its response.
The integration test step deploys the Lambda function to a test endpoint, builds the client and then invokes the client against the test endpoint, validating the output is as expected.
The "release client" step will upload the client binary to an S3 bucket (and also export it to a local directory, for demo-ing convenience). The "deploy server" step will, as expected, deploy the Lambda function to the prod endpoint.
Dependencies between these steps are setup to ensure that the client and server are only released/deployed when they have both been verified to pass both unit and integration tests. Each execution also takes advantage of BuildKit's intelligent caching ability to ensure that steps only re-run when their inputs have changed.
There's a few pre-reqs to try this demo out yourself:
- Clone this repo locally
- Install Dagger
- Setup AWS credentials (to deploy AWS Lambda functions and create an S3 bucket)
demo.cue
will readAWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
environment variables
- Setup a Pulumi access token
demo.cue
will read thePULUMI_ACCESS_TOKEN
environment variable
From there, you should be able to simply run dagger do all
from this locally pulled repo and watch Dagger build, test and deploy everything for you. Note that this will result in the creation of the following AWS resources:
- An S3 bucket with a name
<your username>-dagger-demo
(can be overriden by setting theBUCKET_NAME
env var) - Two Lambda functions with name prefixed with
dagger-demo-
- Two IAM roles for the Lambda functions, each with name prefixed with
iamForLambda
Individual parts of the DAG can be run too by running dagger do <action>
, where <action>
is a field under the actions
key in demo.cue
. You can list the available actions by just running dagger do
.
- The main implementation of the Dagger plan is in
demo.cue
. See the comments within for more details. - The client code is a very simple go main func found under
client/
. - The server code is a NodeJS AWS Lambda handler managed with yarn found under
server/
. - The
pulumi/
dir contains the pulumi resource specification for creating the Lambda functions cue.mod
is where CUE package dependencies are automatically stored whendagger project update
is run (see docs here).