1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【DevContainer】Featureの作成方法

Posted at

リポジトリを作成する

Feature作成用のリポジトリを作成します。

以下のリポジトリをテンプレートとして使用します。

必要なファイルを作成する

まず、Feature用のディレクトリをsrc以下に作成します。

ディレクトリ名はFeatureの名称に対応させます。
sampleというFeatureを作成する場合にはsrc/sampleというディレクトリを作成します。

Feature用のディレクトリにはdevcontainer-feature.jsoninstall.shが必要です。

devcontainer-feature.jsonにはFeatureの設定を記述します。

devcontainer-feature.json
{
  "name": "Hello, World!",
  "id": "hello",
  "version": "1.0.0",
  "description": "A hello world feature",
  "options": {
    "greeting": {
      "type": "string",
      "proposals": [
          "hey",
          "hello"
      ],
      "default": "hey",
      "description": "Select a pre-made greeting, or enter your own"
    }
  }
}

name,id,description,optionsは後ほどの手順で自動生成されるREADME.mdに反映されます。
idはFeatureのディレクトリ名に対応させる必要があります。

devcontainer-feature.jsonで使用できるプロパティの詳細については以下のページをご参照ください。

install.shにはFeatureの処理を記述します。

install.sh
#!/usr/bin/env bash
set -e

GREETING=${GREETING:-undefined}
echo "The provided greeting is: $GREETING"

cat > /usr/local/bin/hello \
<< EOF
#!/bin/sh
RED='\033[0;91m'
NC='\033[0m' # No Color
echo "\${RED}${GREETING}, \$(whoami)!\${NC}"
EOF

chmod +x /usr/local/bin/hello

${GREETING}のように記述するとdevcontainer-feature.jsonoptionsに設定した値を受け取れます。

テスト

Featuresのテストを実行します。

テストの手順については以下をご参照ください。

テストにはdockerdevcontainer-cliが必要です。
上記のテンプレートリポジトリを使用している場合はDevContainersを起動するとdockerおよびdevcontainer-cliが使用できます。

GHCRに公開する

作成したFeatureをGitHub Container Registryに公開します。

まず変更をpushします。

リポジトリのホームから「Actions」をクリックして「Management Release dev container features & Generate Documentation」を実行します。

FF40E568-AE84-4C46-9FB6-7AE4A52AD4B4のコピー.png

するとsrc/Feature名/README.mdが自動生成されGHCRにFeatureが公開されます。

参考

1
1
0

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?