Get Started with Dagger Cloud
Introduction
Dagger Cloud provides pipeline visualization, operational insights, and distributed caching for your Daggerized pipelines.
This guide helps you get started with Dagger Cloud. Here are the steps you'll follow:
- Sign up for Dagger Cloud
- Connect Dagger Cloud with your CI provider or CI tool
- Visualize CI runs with Dagger Cloud
- Improve CI performance with Dagger Cloud's distributed caching
The next sections will walk you through these steps in detail.
Prerequisites
This guide assumes that:
- You have an understanding of how Dagger works. If not, read the Dagger Quickstart.
- You have a GitHub account (required for Dagger Cloud identity verification). If not, register for a free GitHub account.
- You have a source code repository and a Dagger pipeline that interacts with it. If not, follow the steps in Appendix A to create and populate a GitHub repository with a sample application and Dagger pipeline.
Step 1: Sign up for Dagger Cloud
At the end of this step, you will have signed up for Dagger Cloud and obtained a Dagger Cloud token. If you already have a Dagger Cloud account and token, you may skip this step.
Follow the steps below to sign up for Dagger Cloud, create an organization and obtain a Dagger Cloud token.
Browse to the Dagger Cloud website. Click Continue with GitHub to log in with your GitHub account.
On the GitHub authorization screen, confirm the Dagger Cloud connection for authentication. Once authorized, you will be redirected to a welcome page and prompted to create a new Dagger Cloud organization. Enter a name for your organization in the Organization Name field. Click Next to proceed.
infoThe organization name can only contain alphanumeric characters and dashes and is unique across Dagger Cloud.
Review the available Dagger Cloud subscription plans. Choose a plan by clicking Select.
If you selected the Team plan, you will be presented with the option to add teammates to your Dagger Cloud account. This step is optional and not available in individual plans. Enter one or more email addresses as required. Click Next to proceed.
Enter the required payment details. Click Sign up to proceed.
Your payment information will now be verified. If all is well, your new organization will be created and you will be redirected to a success page confirming that your Dagger Cloud account and organization have been created.
Click Go to dashboard to visit the Dagger Cloud dashboard, which allows you to manage your Dagger Cloud organization and account.
The Dagger Cloud dashboard will not display any data until you connect your Dagger Cloud account with a CI provider or CI tool. The next step describes how to do this.
Step 2: Connect Dagger Cloud with your CI
At the end of this step, you will have connected Dagger Cloud with your CI provider or CI tool using your Dagger Cloud token. If you have already connected Dagger Cloud with your CI provider/tool, you may skip this step.
To connect your Dagger Cloud account with a CI provider or CI tool, you must first obtain a Dagger Cloud token.
Browse to the Organizations Settings page of the Dagger Cloud dashboard (accessible by clicking your user profile icon in the Dagger Cloud interface). Select your organization and navigate to the Configuration tab. Note the Dagger Cloud token carefully.
Once you have a token, the general procedure to connect Dagger Cloud with a CI provider/CI tool is:
- Store the token as a secret with your CI provider/in your CI tool.
- Add the secret to your CI environment as a variable named
DAGGER_CLOUD_TOKEN
. - For Team plan subscribers with ephemeral CI runners only: Adjust the Docker configuration to wait longer before killing the Dagger Engine container, to give it more time to push data to the Dagger Cloud cache
You must store the Dagger Cloud token as a secret (not plaintext) with your CI provider and reference it in your CI’s workflow. Using a secret is recommended to protect your Dagger Cloud account from being used by forks of your project.
When using self-hosted CI runners on AWS infrastructure, NAT Gateways are a common source of unexpected network charges. It's advisable to setup an Amazon S3 Gateway for these cases. Refer to the AWS documentation for detailed information on how to do this.
- GitHub Actions
- GitLab CI
- CircleCI
- Jenkins
- Argo Workflows
Create a new secret for your GitHub repository named
DAGGER_CLOUD_TOKEN
, and set it to the value of the token obtained in Step 1. Refer to the GitHub documentation on creating repository secrets.Update your GitHub Actions workflow and add the secret to your
dagger run
step as an environment variable. The environment variable must be namedDAGGER_CLOUD_TOKEN
and can be referenced in the workflow using the formatDAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN }}
. Refer to the GitHub documentation on using secrets in a workflow.For Team plan subscribers with ephemeral CI runners only: Update your GitHub Actions workflow and adjust the
docker stop
timeout period so that Docker waits longer before killing the Dagger Engine container, to give it more time to push data to the Dagger Cloud cache. Refer to the Docker documentation on thedocker stop
command.Install the Dagger Cloud GitHub App. Once installed, GitHub automatically adds a new check for your GitHub pull requests, with a link to see CI status for each workflow run in Dagger Cloud.
Here is a sample GitHub Actions workflow file with the Dagger Cloud integration highlighted:
name: dagger
on:
push:
branches: [main]
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install deps
run: npm ci
- name: Install Dagger CLI
run: cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
- name: Run Dagger pipeline
run: dagger run node index.mjs
env:
DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN }}
# for ephemeral runners only: override the default docker stop timeout and
# give the Dagger Engine more time to push cache data to Dagger Cloud
- name: Stop Engine
run: docker stop -t 300 $(docker ps --filter name="dagger-engine-*" -q)
if: always()
You can use this file with the starter application and Dagger pipeline in Appendix A to test your Dagger Cloud/GitHub Actions integration.
Create a new CI/CD project variable in your GitLab project named
DAGGER_CLOUD_TOKEN
, and set it to the value of the token obtained in Step 1. Ensure that you configure the project variable to be masked and protected. Refer to the GitLab documentation on creating CI/CD project variables and CI/CD variable security.Update your GitLab CI workflow and add the variable to your CI environment. The environment variable must be named
DAGGER_CLOUD_TOKEN
. Refer to the GitLab documentation on using CI/CD variables.For Team plan subscribers with ephemeral CI runners only: Update your GitLab CI workflow and adjust the
docker stop
timeout period so that Docker waits longer before killing the Dagger Engine container, to give it more time to push data to the Dagger Cloud cache. Refer to the Docker documentation on thedocker stop
command.
Here is a sample GitLab CI workflow with the Dagger Cloud integration highlighted:
.docker:
image: node:16-alpine
services:
- docker:${DOCKER_VERSION}-dind
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_VERIFY: '1'
DOCKER_TLS_CERTDIR: '/certs'
DOCKER_CERT_PATH: '/certs/client'
DOCKER_DRIVER: overlay2
DOCKER_VERSION: '20.10.16'
DAGGER_CLOUD_TOKEN: $DAGGER_CLOUD_TOKEN
.dagger:
extends: [.docker]
before_script:
- apk add docker-cli curl
- cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
build:
extends: [.dagger]
script:
- npm ci
- dagger run node index.mjs
# for ephemeral runners only: override the default docker stop timeout and
# give the Dagger Engine more time to push cache data to Dagger Cloud
- docker stop -t 300 $(docker ps --filter name="dagger-engine-*" -q)
Create a new environment variable in your CircleCI project named
DAGGER_CLOUD_TOKEN
and set it to the value of the token obtained in Step 1. Refer to the CircleCI documentation on creating environment variables for a project.For Team plan subscribers with ephemeral CI runners only: Update your CircleCI workflow and adjust the
docker stop
timeout period so that Docker waits longer before killing the Dagger Engine container, to give it more time to push data to the Dagger Cloud cache. Refer to the Docker documentation on thedocker stop
command.For GitHub, GitLab or Atlassian Bitbucket source code repositories only: Update your CircleCI workflow and add the following pipeline values to the CI environment. Refer to the CircleCI documentation on using pipeline values.
GitHub:
environment:
CIRCLE_PIPELINE_NUMBER: << pipeline.number >>GitLab:
environment:
CIRCLE_PIPELINE_NUMBER: << pipeline.number >>
CIRCLE_PIPELINE_TRIGGER_LOGIN: << pipeline.trigger_parameters.gitlab.user_username >>
CIRCLE_PIPELINE_REPO_URL: << pipeline.trigger_parameters.gitlab.repo_url >>
CIRCLE_PIPELINE_REPO_FULL_NAME: << pipeline.trigger_parameters.gitlab.repo_name >>Atlassian BitBucket:
environment:
CIRCLE_PIPELINE_NUMBER: << pipeline.number >>
Here is a sample CircleCI workflow. The DAGGER_CLOUD_TOKEN
environment variable will be automatically injected.
yaml
version: 2.1
jobs:
build:
docker:
- image: cimg/node:lts # select appropriate runtime for pipeline
environment: # for GitHub, GitLab, BitBucket only
CIRCLE_PIPELINE_NUMBER: << pipeline.number >> # for GitHub, GitLab, BitBucket only
CIRCLE_PIPELINE_TRIGGER_LOGIN: << pipeline.trigger_parameters.gitlab.user_username >> # for GitLab only
CIRCLE_PIPELINE_REPO_URL: << pipeline.trigger_parameters.gitlab.repo_url >> # for GitLab only
CIRCLE_PIPELINE_REPO_FULL_NAME: << pipeline.trigger_parameters.gitlab.repo_name >> # for GitLab only
steps:
- checkout
- setup_remote_docker
- run:
name: Install deps
command: npm ci
- run:
name: Install Dagger CLI
command: cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
- run:
name: Run Dagger pipeline
command: dagger run node index.mjs
# for ephemeral runners only: override the default docker stop timeout and
# give the Dagger Engine more time to push cache data to Dagger Cloud
- run:
name: Stop Dagger Engine
command: docker stop -t 300 $(docker ps --filter name="dagger-engine-*" -q)
workflows:
dagger:
jobs:
- build
Configure a Jenkins credential named
DAGGER_CLOUD_TOKEN
and set it to the value of the token obtained in Step 1. Refer to the Jenkins documentation on creating credentials and credential security.Update your Jenkins Pipeline and add the variable to the CI environment. The environment variable must be named
DAGGER_CLOUD_TOKEN
and can be referenced in the Pipeline environment using the formatDAGGER_CLOUD_TOKEN = credentials('DAGGER_CLOUD_TOKEN')
. Refer to the Jenkins documentation on handling credentials.
Here is a sample Jenkins Pipeline with the Dagger Cloud integration highlighted:
pipeline {
agent { label 'dagger' }
environment {
DAGGER_CLOUD_TOKEN = credentials('DAGGER_CLOUD_TOKEN')
}
stages {
stage("dagger") {
steps {
sh '''
npm ci
dagger run node index.mjs
'''
}
}
}
}
- This Jenkins Pipeline assumes that the the Dagger CLI is pre-installed on the Jenkins runner(s), together with other required dependencies.
- If you use the same Jenkins server for more than one Dagger Cloud organization, create distinct credentials for each organization and link them to their respective Dagger Cloud tokens.
- Typically, Jenkins servers are non-ephemeral and therefore it is not necessary to adjust the
docker stop
timeout.
Create a new Kubernetes secret named
dagger-cloud
and set it to the value of the token obtained in Step 1. An example command to achieve this is shown below (replace theTOKEN
placeholder with your actual token value). Refer to the Kubernetes documentation on creating secrets.kubectl create secret generic dagger-cloud --from-literal=token=TOKEN
Update your Argo Workflows specification and add the secret as an environment variable. The environment variable must be named
DAGGER_CLOUD_TOKEN
.
Here is a sample Argo Workflows specification with Dagger Cloud integration:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dagger-in-argo-
spec:
entrypoint: dagger-workflow
volumes:
- name: dagger-conn
hostPath:
path: /var/run/dagger
- name: gomod-cache
persistentVolumeClaim:
claimName: gomod-cache
templates:
- name: dagger-workflow
inputs:
artifacts:
- name: project-source
path: /work
git:
repo: https://github.com/kpenfound/greetings-api.git
revision: "main"
- name: dagger-cli
path: /usr/local/bin
mode: 0755
http:
url: https://github.com/dagger/dagger/releases/download/v0.8.7/dagger_v0.8.7_linux_arm64.tar.gz
container:
image: golang:1.21.0-bookworm
command: ["sh", "-c"]
args: ["dagger run go run ./ci ci"]
workingDir: /work
env:
- name: "_EXPERIMENTAL_DAGGER_RUNNER_HOST"
value: "unix:///var/run/dagger/buildkitd.sock"
- name: "DAGGER_CLOUD_TOKEN"
valueFrom:
secretKeyRef:
name: dagger-cloud
key: token
volumeMounts:
- name: dagger-conn
mountPath: /var/run/dagger
- name: gomod-cache
mountPath: /go/pkg/mod
Learn more about using Dagger with Argo Workflows.
Step 3: Visualize a CI run with Dagger Cloud
At the end of this step, you will have data from one or more CI runs available for inspection and analysis in Dagger Cloud.
Once your CI provider/tool is connected with Dagger Cloud, it’s time to test the integration.
To do this, trigger your CI workflow and Dagger pipeline by pushing a commit or opening a pull request. If you are using the starter application and pipeline from Appendix A, use the following commands:
sed -i 's/Welcome to Dagger/Welcome to Dagger Cloud/g' src/App.tsx
git commit -a -m "Updated welcome message"
git push
Once your CI workflow begins, navigate to the All Runs page of the Dagger Cloud dashboard. You should see your most recent CI run as the first entry in the table, as shown below:
A run represents one invocation of a Dagger pipeline. It contains detailed information about the steps performed by the pipeline.
The All Runs page provides an overview of all runs. You can drill down into the details of a specific run by clicking it. This directs you to a run-specific Run Details page, as shown below:
The Run Details page includes detailed status and duration metadata about the pipeline steps. The tree view shows Dagger pipelines and steps within those pipelines. If there are any errors in the run, Dagger Cloud automatically brings you to the first error in the list. You see detailed logs and output of each step, making it easy for you to debug your pipelines and collaborate with your teammates.
Learn more about the Dagger Cloud user interface.
Step 4: Integrate the Dagger Cloud cache
At the end of this step, you will have integrated Dagger Cloud's distributed cache with your CI pipeline.
Dagger Cloud's distributed caching feature is only available under the Team plan.
One of Dagger's most powerful features is its ability to cache data across pipeline runs. This is especially useful when dealing with package managers such as npm
, maven
, pip
and similar. For these tools to cache properly, they need their own cache data (usually a directory) to be persisted between runs. Since these dependencies are usually locked to specific versions in the application's manifest, re-downloading them on every pipeline run is inefficient and time-consuming.
Dagger comes with built-in support to define one or more such directories as cache volumes and persist their contents across runs. Dagger Cloud enhances caching support significantly and allows cross-host synchronization of cache volumes. This allows multiple machines, including ephemeral runners, to intelligently share a distributed cache.
Dagger Cloud automatically detects and creates cache volumes when they are declared in your code. To see how this works, add a cache volume to your Dagger pipeline and then trigger a CI run. If you're using the starter application and Dagger pipeline from Appendix A, do this by updating the Dagger pipeline code as shown below (changes are highlighted):
import { connect } from "@dagger.io/dagger"
connect(
async (client) => {
const nodeCache = client.cacheVolume("node")
const source = client
.container()
.from("node:16-slim")
.withDirectory(
"/src",
client.host().directory(".", { exclude: ["node_modules/", "ci/"] })
)
.withMountedCache("/src/node_modules", nodeCache)
const runner = source.withWorkdir("/src").withExec(["npm", "install"])
const test = runner.withExec(["npm", "test", "--", "--watchAll=false"])
await test
.withExec(["npm", "run", "build"])
.directory("./build")
.export("./build")
const imageRef = await client
.container()
.from("nginx:1.23-alpine")
.withDirectory(
"/usr/share/nginx/html",
client.host().directory("./build")
)
.publish("ttl.sh/hello-dagger-" + Math.floor(Math.random() * 10000000))
console.log(`Published image to: ${imageRef}`)
},
{ LogOutput: process.stdout }
)
This revised pipeline now uses a cache volume for the application dependencies.
- It uses the client's
cacheVolume()
method to initialize a new cache volume namednode
. - It uses the
Container.withMountedCache()
method to mount this cache volume at the node_modules/ mount point in the container.
Next, trigger your CI workflow by pushing a commit or opening a pull request. Once your CI workflow begins, browse to the Organizations Settings -> Organization page of the Dagger Cloud dashboard (accessible by clicking your user profile icon in the Dagger Cloud interface) and navigate to the Configuration tab. You should see the newly-created volume listed and enabled.
You can create as many volumes as needed and manage them from the Configuration tab of your Dagger Cloud organization page.
Conclusion
This guide introduced you to Dagger Cloud and walked you registering a new organization, integrating Dagger Cloud with your CI provider/tool, and using Dagger Cloud’s visualization and caching features. For more information and technical support, visit the Dagger Cloud reference pages or contact Dagger via the support messenger in Dagger Cloud.
Appendix A: Create a Dagger pipeline
Before you can integrate Dagger Cloud into your CI process, you need a Dagger pipeline and source code for it to interact with.
If you don't have these already, follow the steps below to create an application and its accompanying Dagger pipeline.
This section assumes that you have a Node.js development environment. It uses the starter React application and Dagger pipeline from the Dagger Quickstart in tandem with a GitHub repository. If you wish to use a different application or a different VCS, adapt the steps below accordingly.
Begin by cloning the example application's repository:
git clone https://github.com/dagger/hello-dagger.git
Install the Dagger Node.js SDK:
cd hello-dagger
npm install @dagger.io/dagger --save-devIn the application directory, create a file named
index.mjs
and add the following code to it.import { connect } from "@dagger.io/dagger"
connect(
async (client) => {
const source = client
.container()
.from("node:16-slim")
.withDirectory(
"/src",
client.host().directory(".", { exclude: ["node_modules/", "ci/"] })
)
const runner = source.withWorkdir("/src").withExec(["npm", "install"])
const test = runner.withExec(["npm", "test", "--", "--watchAll=false"])
await test
.withExec(["npm", "run", "build"])
.directory("./build")
.export("./build")
const imageRef = await client
.container()
.from("nginx:1.23-alpine")
.withDirectory(
"/usr/share/nginx/html",
client.host().directory("./build")
)
.publish("ttl.sh/hello-dagger-" + Math.floor(Math.random() * 10000000))
console.log(`Published image to: ${imageRef}`)
},
{ LogOutput: process.stdout }
)This Dagger pipeline uses the Dagger Node.js SDK to test, build and publish a containerized version of the application to a public registry.
infoExplaining the details of how this pipeline works is outside the scope of this guide; however, you can find a detailed explanation and equivalent pipeline code for Go and Python in the Dagger Quickstart.
Commit the changes:
git add .
git commit -a -m "Added Dagger pipeline"Create a private repository in your GitHub account and push the changes to it:
git remote remove origin
gh auth login
gh repo create hello-dagger --push --source . --private