https://github.com/74th/test-devcontainer-feature-2
https://github.com/74th/test-devcontainer-feature-2
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/74th/test-devcontainer-feature-2
- Owner: 74th
- License: mit
- Created: 2025-07-27T01:30:01.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-07-27T05:37:13.000Z (10 months ago)
- Last Synced: 2025-10-10T11:54:21.103Z (8 months ago)
- Language: Shell
- Size: 44.9 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dev Container Feature自作のテスト
以下のテンプレートを使用
https://github.com/devcontainers/feature-starter
## flyway-8.1.0 を作ってみた
### テンプレートからの変更
- src/color, test/color を削除
- src/hello, test/hello を hello -> flyway-8.1.0名前にリネーム
- .github/workflows/test.yaml にfeaturesの記載があるので、colorを削除、hello -> flyway-8.1.0 に変更
### GitHub Actionsで動かなかったやつ
.github/workflows/release.yaml の変更点PR作るやつが動かない。
リポジトリの Settings -> Actions -> General -> Workflow permissions で、
Allow GitHub Actions to create and approve pull requests にチェック。
.github/workflows/release.yaml を以下の記述に変えた。
```
git rebase origin/"$branch" || git merge origin/"$branch"
```
↓
```
if git ls-remote --exit-code --heads origin "$branch"; then
git fetch origin "$branch"
git rebase origin/"$branch" || git merge origin/"$branch"
fi
```
### devcontainer-feature.json の記述
name, idを記述する。versionは、GitHub Packages上必ずバージョンを変えないといけ内っぽく、0.0.1 と一旦しておく。
```json
{
"name": "flyway-8.1.0",
"id": "flyway-8.1.0",
"version": "0.0.1",
"description": "A flyway feature",
"options": {},
"containerEnv": {
"PATH": "/flyway:${PATH}"
},
"dependsOn": {
"ghcr.io/devcontainers/features/java:1": {}
},
"installsAfter": ["ghcr.io/devcontainers/features/common-utils"]
}
```
- javaなど他のfeaturesに依存する場合は、dependsOnに記述する
- 環境変数の設定は devcontainer-feature.json の `containerEnv` に追加する
### テストの作成
test/flyway-8.1.0に test.sh, <シナリオ名>.sh, duplicate.sh を作成
一旦全部同じ内容でよさそう。
scenarios.json は以下のように記述。
```json
{
"ubuntu": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"flyway-8.1.0": {}
}
}
}
```
scenarios.jsonとubuntu.shを削除すれば、追加シナリオなしでテストが動いてくれてる。
### テストの実行
テストは以下のコマンドで実施
```
devcontainer features test --features flyway-8.1.0
```
### 重複インストールへの対応
duplicate.sh は、重複インストールをテストするのに使われる。
install.sh に重複を入れる
```bash
if [ -d "/flyway" ]; then
echo "Flyway is already installed"
exit 0
fi
```
### サブディレクトリ
./features にすべてを格納したい。
コマンドは以下で実行できる。
```
devcontainer features test --features flyway-8.1.0 -p ./features/
```
.github/workflows/test.yaml の devcontainer testコマンドに `-p ./features/` を追加する。
.github/workflows/{validate,release}.yaml の devcontainers/action@v1 の `base-path-to-features` に `./features/src` を指定する。
### 利用するときには
[features/src/flyway-8.1.0/README.md](features/src/flyway-8.1.0/README.md)の通り、以下のようにfeaturesを指定する
```
"features": {
"ghcr.io/74th/test-devcontainer-feature-2/flyway-8.1.0:0": {}
}
```
利用する前に、dockerからghcr.ioを使えるように以下のコマンドでログインしておく必要がある。
```bash
gh auth login
docker login ghcr.io -u <ユーザ名> -p $(gh auth token)
```
[./test-workspace/flyway-8.1.0/](./test-workspace/flyway-8.1.0/)にワークスペースを作ったので、そちら参照。