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
- Go
- Node.js
- Python
.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
.github/workflows/dagger.yaml
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: 18
- 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
.github/workflows/dagger.yaml
name: dagger
on:
push:
branches: [main]
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install deps
run: pip install .
- 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 python main.py
GitLab CI
- Go
- Node.js
- Python
.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
.gitlab-ci.yml
.docker:
image: node:18-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:
- npm ci
- dagger run node index.mjs
.gitlab-ci.yml
.docker:
image: python:3.11-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:
- pip install .
- dagger run python main.py
CircleCI
- Go
- Node.js
- Python
.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
.circleci/config.yml
version: 2.1
jobs:
build:
docker:
- image: cimg/node:lts
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- 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 | sudo sh; cd -; }
- run:
name: Run Dagger pipeline
command: dagger run --progress plain node index.mjs
workflows:
dagger:
jobs:
- build
.circleci/config.yml
version: 2.1
jobs:
build:
docker:
- image: cimg/python:3.11
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Install deps
command: pip install .
- 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 python main.py
workflows:
dagger:
jobs:
- build
Jenkins
- Go
- Node.js
- Python
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
.
Jenkinsfile
pipeline {
agent { label 'dagger' }
stages {
stage("dagger") {
steps {
sh '''
npm ci
cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
dagger run node index.mjs
'''
}
}
}
}
Requires docker
client and node
installed on your Jenkins agent, a Docker host available (can be docker:dind
), and agents labeled in Jenkins with dagger
.
Jenkinsfile
pipeline {
agent { label 'dagger' }
stages {
stage("dagger") {
steps {
sh '''
pip install .
cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
dagger run python main.py
'''
}
}
}
}
Requires docker
client and python
installed on your Jenkins agent, a Docker host available (can be docker:dind
), and agents labeled in Jenkins with dagger
.
Azure Pipelines
- Go
- Node.js
- Python
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'
azure-pipelines.yml
trigger:
- master
pool:
name: 'Default'
vmImage: ubuntu-latest
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
- script: npm ci
displayName: 'Install dependencies'
- script: cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
displayName: 'Install Dagger CLI'
- script: dagger run node index.mjs
displayName: 'Run Dagger'
azure-pipelines.yml
trigger:
- master
pool:
name: 'Default'
vmImage: ubuntu-latest
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
- script: pip install .
displayName: 'Install dependencies'
- script: cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
displayName: 'Install Dagger CLI'
- script: dagger run python main.py
displayName: 'Run Dagger'
AWS CodePipeline
- Go
- Node.js
- Python
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
buildspec.yml
version: 0.2
phases:
pre_build:
commands:
- echo "Installing dependencies"
- npm ci
- 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 node index.mjs
buildspec.yml
version: 0.2
phases:
pre_build:
commands:
- echo "Installing dependencies"
- pip install .
- 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 python main.py