0
0

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.

【Thunder Client】devcontainer内でThunder Clientを使用する

Last updated at Posted at 2023-02-13

Dev Containersの設定

devcontainer内にThunder Clientがインストールされるように.devcontainer/devcontainer.jsoncustomizations.vscode.extensionsrangav.vscode-thunder-clientを追加します。

devcontainer.json
{

...

  "customizations": {
    "vscode": {
      "extensions": [
        ...
        "rangav.vscode-thunder-client"
      ]
    }
  }
}

データの永続化

Thunder Clientのデータを永続化するために.devcontainer/compose.devcontainer.ymlを作成して既存のcompose.ymlをオーバーライドします。

Thunder Clientのデータは~/.vscode-server/data/User/globalStorage/rangav.vscode-thunder-clientに保存されます。
上記の情報は~/.th-client/thunder-cache.jsonに記述されています。

thunder-cache.json
{"globalPath":"/home/user/.vscode-server/data/User/globalStorage/rangav.vscode-thunder-client"}

~/.vscode-server/data/User/globalStorage/rangav.vscode-thunder-clientにボリュームマウントを設定するためcompose.devcontainer.ymlを次のように記述します。

compose.devcontainer.yml
services:
  api:
    volumes:
      - th-client-storage:/home/user/.vscode-server/data/User/globalStorage/rangav.vscode-thunder-client
    command: bash -c "while sleep 1000; do :; done"
volumes:
  th-client-storage:

devcontainer起動時にcompose.devcontainer.ymlが読み込まれるように.devcontainer/devcontainer.jsondockerComposeFile./compose.devcontainer.ymlを追加します。

devcontainer.json
{
  ...

  "dockerComposeFile": ["../compose.yml", "./compose.devcontainer.yml"],

  ...

}

devcontainerをrootで実行している場合には上記で問題ないと思いますがDockerfile内で一般ユーザーに変更している場合にはdevcontainer起動時に次のようなエラーとなります。

mkdir: cannot create directory ‘/home/user/.vscode-server/bin’: Permission denied

~/.vscode-server/data/User/globalStorage/rangav.vscode-thunder-clientにボリュームマウントを設定したためコンテナ起動時にrootで.vscode-serverディレクトリが作成されることが原因です。

.vscode-serverの所有者を変更するため次の内容で.devcontainer/devcontainer-entrypoint.shを作成します。

devcontainer-entrypoint.sh
#!/usr/bin/env bash

set -eu

user="$(whoami)"
sudo chown -R "${user}" "/home/${user}/.vscode-server"

exec "$@"

コンテナ内でsudoを使用できるようにするためdevcontainer.jsonfeaturesに次の記述を追加します。

devcontainer.json
{
  "features": {
    "ghcr.io/devcontainers/features/common-utils:2": {},
  }
}

コンテナ起動時に上記のファイルを実行するためcompose.devcontainer.ymlを編集します。

compose.devcontainer.yml
services:
  api:
    volumes:
      - th-client-storage:/home/user/.vscode-server/data/User/globalStorage/rangav.vscode-thunder-client
    entrypoint:
      - bash
      - ./.devcontainer/devcontainer-entrypoint.sh
    command: bash -c "while sleep 1000; do :; done"
volumes:
  th-client-storage:

これでdevcontainerが起動できるようになります。

localhostの代わりにhost.docker.internalを使用する

devcontainer内でThunder

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?