LoginSignup
4

More than 1 year has passed since last update.

Dagger.io を GitHub Actions で動かしてみた

Posted at

Dagger というポータブルな CI/CD 開発キットを GitHub Actions で動かしてみました。
実際に動作するコードサンプルも用意してあります。
https://github.com/algas/dagger-github-actions-example

Dagger とは何か?

https://github.com/dagger/dagger
Dagger を使うとソフトウェアチームが強力なCICDパイプラインを最小限の努力で開発でき、どこでも動作するようになるというのがコンセプトらしいです。
次のような2つの利点があります。

  1. 開発環境とCI環境の統一
  2. CIロックインをなくす

CUE という言語を使ってパイプラインを記述します。
ドキュメントや周辺ツールの整備はまだこれからのようです。

使い方

Dagger 自体の記述や GitHub Actions の説明は今回はしません。
自分で書いた Dagger の設定を GitHub Actions から呼び出すことを目標とします。

  1. Dagger のインストール
    HomeBrew を使う場合 brew install dagger/tap/dagger
    その他の環境では次を参照のこと https://docs.dagger.io/1200/local-dev
  2. GitHub リポジトリの作成
    リポジトリを作ったら git clone する
  3. CUE ファイルを書く
  4. Dagger 環境のセットアップ
    dagger project init && dagger project update
    cue.mod というディレクトリが作成される
  5. GitHub Actions Workflow ファイルを書く
  6. Git commit & Push
    cue.mod も commit するのがポイント
    git commit -a && git push origin main
  7. 動作確認
    GitHub リポジトリの Actions タブで動作を確認します

CUE ファイルのサンプル

公式リポジトリに載っている Hello World を出力するだけのサンプルです

package helloworld

import (
	"dagger.io/dagger"
	"dagger.io/dagger/core"
)

dagger.#Plan & {
	actions: {
		_alpine: core.#Pull & {source: "alpine:3"}
		// Hello world
		hello: core.#Exec & {
			input: _alpine.output
			args: ["echo", "hello, world!"]
			always: true
		}
	}
}

GitHub Actions Workflow のサンプル

上記の Dagger を動作させるための workflow ファイルのサンプルです

name: helloworld

on:
  push:
    branches:
      - main

jobs:
  dagger:
    runs-on: ubuntu-latest
    steps:
      - name: Clone repository
        uses: actions/checkout@v2
      - name: Hello World
        uses: dagger/dagger-for-github@v2
        with:
          version: 0.2
          cmds: |
            do hello --log-format=plain

まとめ

Dagger を GitHub Actions で動かすサンプルを書いてみました。
次はもう少し実践的なファイルを書いてみようと思います。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4