GitHub Actions
The following code sample demonstrates how to integrate Dagger with GitHub Actions.
.github/workflows/dagger.yml
name: dagger
on:
push:
branches: [main]
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
-
name: Call Dagger Function
uses: dagger/dagger-for-github@v6
with:
version: "latest"
verb: call
# assumes a Go project
# modify to use different function(s) as needed
module: github.com/kpenfound/dagger-modules/golang@v0.2.0
args: build --project=. --args=.
# assumes the Dagger Cloud token is in
# a repository secret named DAGGER_CLOUD_TOKEN
# set via the GitHub UI/CLI
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
The following code sample demonstrates how to use Dagger in a GitHub Action to publish a container image to GitHub Container Registry.
.github/workflows/dagger.yml
name: dagger
on:
push:
branches: [main]
jobs:
build-publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Call Dagger Function to build and publish to ghcr.io
uses: dagger/dagger-for-github@v6
with:
version: "latest"
verb: call
# modify to use different function(s) as needed
module: github.com/daggerverse/dagger-ghcr-demo@v0.1.5
args: build-and-push --registry=$DOCKER_REGISTRY --image-name=$DOCKER_IMAGE_NAME --username=$DOCKER_USERNAME --password=env:DOCKER_PASSWORD --build-context=github.com/daggerverse/dagger-ghcr-demo
# assumes the Dagger Cloud token is in
# a repository secret named DAGGER_CLOUD_TOKEN
# set via the GitHub UI/CLI
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
env:
DOCKER_REGISTRY: ghcr.io
DOCKER_IMAGE_NAME: ${{ github.repository }}
DOCKER_USERNAME: ${{ github.actor }}
# assumes the container registry password is in
# a repository secret named REGISTRY_PASSWORD
# set via the GitHub UI/CL
DOCKER_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
More information is available in the Dagger for GitHub Action page.