Skip to main content

Use Dagger SDKs in CI

Introduction

This guide explains how to integrate the Dagger SDKs with various CI services/tools.

Requirements

This guide assumes that:

  • You have a Go, Python or Node.js environment on the CI runner.
  • You have a Dagger SDK for one of the above languages installed on the CI runner. If not, install your preferred language SDK within your CI workflow following the installation instructions for the Dagger Go, Python or Node.js SDK.

Use Dagger in CI

GitHub Actions

.github/workflows/dagger.yml
name: dagger
on:
push:
branches: [main]

jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.20'
- 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 go run main.go

GitLab CI

.gitlab-ci.yml
.docker:
image: golang:1.20-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:
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:
- dagger run go run main.go

CircleCI

.circleci/config.yml
version: 2.1
jobs:
build:
docker:
- image: cimg/go:1.20
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Install Dagger CLI
command: cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sudo sh; cd -; }
- run:
name: Run Dagger pipeline
command: dagger run --progress plain go run main.go
workflows:
dagger:
jobs:
- build

Jenkins

Jenkinsfile
pipeline {
agent { label 'dagger' }

stages {
stage("dagger") {
steps {
sh '''
cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
dagger run go run main.go
'''
}
}
}
}

Requires docker client and go installed on your Jenkins agent, a Docker host available (can be docker:dind), and agents labeled in Jenkins with dagger.

Azure Pipelines

azure-pipelines.yml
trigger:
- master

pool:
name: 'Default'
vmImage: ubuntu-latest

steps:
- task: GoTool@0
inputs:
version: '1.20'

- script: cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
displayName: 'Install Dagger CLI'

- script: dagger run go run main.go
displayName: 'Run Dagger'

AWS CodePipeline

buildspec.yml
version: 0.2

phases:
pre_build:
commands:
- echo "Installing Dagger CLI"
- cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }

build:
commands:
- echo "Running Dagger pipeline"
- dagger run go run main.go