Dagger というポータブルな CI/CD 開発キットを GitHub Actions で動かしてみました。
実際に動作するコードサンプルも用意してあります。
https://github.com/algas/dagger-github-actions-example
Dagger とは何か?
https://github.com/dagger/dagger
Dagger を使うとソフトウェアチームが強力なCICDパイプラインを最小限の努力で開発でき、どこでも動作するようになるというのがコンセプトらしいです。
次のような2つの利点があります。
- 開発環境とCI環境の統一
- CIロックインをなくす
CUE という言語を使ってパイプラインを記述します。
ドキュメントや周辺ツールの整備はまだこれからのようです。
使い方
Dagger 自体の記述や GitHub Actions の説明は今回はしません。
自分で書いた Dagger の設定を GitHub Actions から呼び出すことを目標とします。
- Dagger のインストール
HomeBrew を使う場合brew install dagger/tap/dagger
その他の環境では次を参照のこと https://docs.dagger.io/1200/local-dev - GitHub リポジトリの作成
リポジトリを作ったらgit clone
する - CUE ファイルを書く
- Dagger 環境のセットアップ
dagger project init && dagger project update
cue.mod というディレクトリが作成される - GitHub Actions Workflow ファイルを書く
- Git commit & Push
cue.mod も commit するのがポイント
git commit -a && git push origin main
- 動作確認
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 で動かすサンプルを書いてみました。
次はもう少し実践的なファイルを書いてみようと思います。