Open6

aqua を install する Development Container Feature を作ってみる

Shunsuke SuzukiShunsuke Suzuki

きっかけはこれ
https://github.com/aquaproj/aqua/discussions/1273

Development Containers の spec はこれ
https://containers.dev/

Custom の Development Container Feature の作り方は
https://github.com/devcontainers/spec/blob/main/proposals/devcontainer-features-distribution.md

template repository
https://github.com/devcontainers/feature-template

GitHub Actions
https://github.com/devcontainers/action

1 つのリポジトリで複数の feature を管理でき、 feature ごとに semver でバージョン管理できる。
特に複数の feature を作る予定はないのだが、 template とかツールが複数構成を前提にしている気がするので、それに従ったほうが良い気がする。

src/
  aqua/
    devcontainer-feature.json
    install.sh
  • devcontainer-feature.json
  • install.sh

この 2 つのファイルを用意すれば良い。

hello を見るとかなりシンプルである。
https://github.com/devcontainers/feature-template/tree/main/src/hello

リリースは GHCR (GitHub Container Registry) に publish する。
public にする。

GitHub Action とサンプルの Workflow が提供されている。
https://github.com/devcontainers/feature-template/blob/main/.github/workflows/release.yaml

workflow_dispatch を引数無しで実行すればいいのかな。

Shunsuke SuzukiShunsuke Suzuki

とりあえず Fork
https://github.com/suzuki-shunsuke/devcontainers-features

https://github.com/aquaproj/aqua-installer

PATH の追加もできると良い

$ export PATH="${AQUA_ROOT_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/aquaproj-aqua}/bin:$PATH"

https://containers.dev/implementors/features/#devcontainer-feature-json-properties

https://containers.dev/implementors/spec/#environment-variables

https://github.com/devcontainers/features/blob/065b5ec9e19d4f289a070c3d5337696fd2394dc0/src/go/devcontainer-feature.json#L28-L32

Requires the container be recreated / rebuilt to change. If you want to reference an existing container variable while setting this one (like updating the PATH), use remoteEnv instead.

Shunsuke SuzukiShunsuke Suzuki

とりあえず最低限これでも動いた。

.devcontainer/
  devcontainer.json
devcontainer.json
{
  "name": "Example Development Containers",
  "image": "alpine:3.16.2"
}
$ devcontainer up --workspace-folder .
$ devcontainer exec --workspace-folder . whoami
root
{"outcome":"success"}
Shunsuke SuzukiShunsuke Suzuki
{
	"name": "Example Development Containers",
	"build": {
		"dockerfile": "Dockerfile"
	},
	"postStartCommand": "aqua i -l",
	"remoteEnv": {
		"PATH": "/root/.local/share/aquaproj-aqua/bin:${containerEnv:PATH}"
	}
}
FROM alpine:3.16.2
RUN apk add curl \
 && curl -sSfL \
  https://raw.githubusercontent.com/aquaproj/aqua-installer/v1.1.2/aqua-installer | sh
---
# aqua - Declarative CLI Version Manager
# https://aquaproj.github.io/
checksum:
  # https://aquaproj.github.io/docs/reference/checksum/
  enabled: true
  require_checksum: true
registries:
- type: standard
  ref: v3.72.0 # renovate: depName=aquaproj/aqua-registry
packages:
- name: hashicorp/terraform@v1.3.2
$ devcontainer exec --workspace-folder . terraform version