æ°ã«ãªã£ã¦ããã®ã«è§¦ã£ã¦ããªãã£ãæè¡ã¨ãã¦dev containerããã£ãã
Dev Containerã¯ãã®ååã®éããéçºç°å¢ãã³ã³ããåããæè¡ã ããããã¨ãéçºç°å¢ã¨ã¯ä½ããã¨ãã話ã«ãªãããã ãã©ãããã§ããéçºç°å¢ã¨ã¯ãã³ã¼ããæ¸ãããã®ç°å¢ãã§ãããããã¯ãã³ã¼ããæ¸ãããã®ãã¼ã«ãã©ã¤ãã©ãªããå«ãç°å¢ã§ãããã
- ã¢ã¼ããã¯ãã£
- è¨å®ãã¡ã¤ã«
- å®éã«ããã°è¨è¿°ç°å¢ã«ä½¿ã£ã¦ã¿ã
- Workspaceå¤ã«ããè¨å®ãã¡ã¤ã«ãã³ã³ããã«æã¡è¾¼ã
- 使ã£ã¦ã¿ã¦
ã¢ã¼ããã¯ãã£
ããã¯ãã£ã¦ãçµå±ã©ããããã¨ãªã®ãã¨ããç念ã¯æããªããããªã®ã§ãããå ·ä½çãªã¢ã¼ããã¯ãã£ã示ãå¿ è¦ãããã以ä¸ã¯Developing inside a Container using Visual Studio Code Remote Developmentããå¼ç¨ãããã®ã
ã³ã³ããã®ä¸ã«ãVS Code Serverããããã½ã¼ã¹ã³ã¼ãã¯ãã¼ã«ã«PCã®ãã®ãã³ã³ããã«Volume MountãããVS Codeã®ï¼UIå¨ããé¤ãï¼æ¡å¼µãã³ã³ããå´ã§åä½ããããããã«ãã£ã¦ãã½ããã¦ã§ã¢éçºè ãããã¸ã§ã¯ããã¨ã«å¿ è¦ãªãã¼ã«ãã©ã¤ãã©ãªãå«ãã ç°å¢ãç°¡åã«æ§ç¯ãå ±æãåç¾ã§ããããã«ãã¦ããã
ãã¡ãããVS Codeã ããã£ã¦ãéçºç°å¢ã¨ãã¦ã¯ä¸ååãªã®ã§ãNodeãPythonã¨ãã£ãè¨èªã®ã©ã³ã¿ã¤ã ãããããã¬çã®ãã¼ã«ãå«ãã¦ã³ã³ããã«éãè¾¼ããã ãã®ã¢ããã¼ãã«ããã以ä¸ã®åé¡ã解決ããããå°ãªãã¨ã解決ã«è¿ã¥ãã
- "ç§ã®ç°å¢ã§ã¯åä½ãããããªãã®ç°å¢ã§ã¯åä½ããªã"ã¨ããåé¡ã®ææ¢
- åä¸ãã¼ã ã®ä¸ã§ã®éçºç°å¢æ§ç¯ãã³ã¼ã管çã§ããæ§ç¯ä½æ¥ãç°¡ç¥åã§ãã
- ãã¼ã«ã«PCã«ãã¼ã«ãéä¸ã¤ã³ã¹ãã¼ã«ããå¿ è¦ããªããªããPCç°å¢ãæ±ããªãã¦æ¸ã
è¨å®ãã¡ã¤ã«
ãã¡ããããã®ç°å¢ãããããã¨æã§ä½ã£ã¦ããã®ã§ã¯çµå±ç°å¢æ§ç¯ã®æéã大ãããªã£ã¦ãã¾ãããã³ã¼ã管çã§ããªããããã§ãDev Container metadataã®ä»æ§ã決ã¾ã£ã¦ãããããã«å¾ã£ã¦è¨å®ãã¡ã¤ã«ãä½æãããã¨ã§ãç°å¢ãæ§ç¯ã§ãããå
·ä½çã«ã¯ã.devcotainer
ãã£ã¬ã¯ããªé
ä¸ã®.devcontainer.json
ã¸è¨è¿°ãããã¨ã«ãªãã
å®éã«ããã°è¨è¿°ç°å¢ã«ä½¿ã£ã¦ã¿ã
ãã®ããã°ãè¨è¿°ããç°å¢ããå®ã¯ä»¥ä¸ã®ãããªã©ã³ã¿ã¤ã ããã¼ã«ãå¿ è¦ã¨ãã¦ããã
- node
- make
- hadolint
- textlint
- ShellCheck
- blogsync
ã¨ããããã§ãæå§ãã«ãã®ããã°è¨è¿°ç°å¢ãDev Containeråãã¦ã¿ãéç¨ã§ãDev Containeråã¨ããã®ã¯ã©ããããã¨ããç解ãããã¨ã«ããã
ã³ã³ãããã©ãä½æããã
Dev Containerã®ä¸è¬çãªãã³ãã¬ã¼ãã¯Templatesãããã«ç¨æããã¦ãããããç´æ¥ããã使ã£ã¦ãè¯ãã ä»ã®ãªãã·ã§ã³ã¨ãã¦ã¯Dockerfileãæå®ããããããã¯ãDocker composeã®ãã¡ã¤ã«ãæå®ããã¨ããæ¹æ³ããããä»åã¯DBçã®ãµã¼ãã¹ã¯ä½¿ããªãã®ã§ãDockerfileãæå®ããæ¹æ³ã§é²ããã
Dockerfileãä½æããã¼ã«ãã¤ã³ã¹ãã¼ã«ãã
nodeã®Runtimeãå¿ è¦ã ã£ãã®ã§ãNode.js Development Container Imagesã使ããã¨ã«ããã
dev containerã«ä½¿ãã¨ãã£ã¦ããDockerfileã使ã以ä¸dev containerãç¹å¥ã«æèãããã¨ã¯ãªãã éä¸ã§hadolintã¨blogsyncãã¤ã³ã¹ãã¼ã«ããå¿ è¦ããã£ãã®ã§ãæçµçã«ä»¥ä¸ã®ãããªDockerfileãçèªããã
FROM mcr.microsoft.com/devcontainers/javascript-node:dev-20-bookworm ENV BLOGSYNC_VERSION v0.20.1 ENV HADOLINT_VERSION v2.12.0 SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN apt-get update \ # Install hadolint && curl -SL "https://github.com/hadolint/hadolint/releases/download/${HADOLINT_VERSION}/hadolint-Linux-arm64" -o /usr/local/bin/hadolint \ && chmod +x /usr/local/bin/hadolint \ # Install blogsync && curl -SL "https://github.com/x-motemen/blogsync/releases/download/${BLOGSYNC_VERSION}/blogsync_${BLOGSYNC_VERSION}_linux_arm64.tar.gz" | tar -xzC /tmp/ \ && mv /tmp/blogsync_${BLOGSYNC_VERSION}_linux_arm64/blogsync /usr/local/bin/ \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/*
VS Codeã®æ¡å¼µãã¤ã³ã¹ãã¼ã«ãã
VS Codeã®æ¡å¼µãã³ã³ããå´ã«ã¤ã³ã¹ãã¼ã«ããã«ã¯ã.devcontainer.json
ã«customizations.vscode.extensions
ã追å ããã
devcontainer.json
ã¯ä¸å¿IDEã«ä¾åããªãä»æ§ã¨ãªã£ã¦ããããcustomizations
é
ä¸ã¯ãããã¯ãåºæã®è¨å®ãæ¸ãã¦è¯ããã¨ã«ãªã£ã¦ãããcostomizations.vscode
ã¯VS Codeç¨ã®è¨å®ã¨ãã¦ãã¤ã³ã¹ãã¼ã«ãã¹ãæ¡å¼µãæå®ã§ããã
ãã®è¾ºãã®è©³ç´°ã¯Supporting tools and servicesãåç
§ã
"customizations": { "vscode": { "extensions": [ "GitHub.copilot-chat", "GitHub.copilot", (snip) ] } }
éä¸ãå¿
è¦ãªæ¡å¼µãè¨è¿°ãã¦ããã®ã¯éª¨ãæããããVS Codeã®æ¡å¼µæ©è½ã¡ãã¥ã¼ã®ã³ã³ããã¹ãã¡ãã¥ã¼ããç´æ¥.devcontainer.json
ã«è¿½å ã§ããã
Workspaceã«ä¾åãããã¼ã«ãå°å ¥ãã
åç´ã«Dev containerãå®ç¾©ããã·ã³ãã«ãªmetadataã¯æ¬¡ã®ããã«ãªã£ãã
Dockerfileãæå®ããããã«ã¯build.dockerfile
ãæå®ããã°è¯ãã
{ "name": "ã¯ã¦ãªããã°ã¨ãã£ã¿", "build": { "dockerfile": "Dockerfile" }, "forwardPorts": [ 3000 ], "postCreateCommand": "npm install", }
å°å
¥å¯¾è±¡ãã¼ã«ã§ããtextlintã¯Workspaceã«ããpackage.json
ã§å®ç¾©ããã¦ããããããã³ã³ããã«å°å
¥ããããã«ã¯postCreateCommand
ã§npm install
ãå®è¡ããã
Dockerfileã§RUN npm install
ããã°è¯ããããã¼ãã¨ãã話ã¯ããããããã¯ãã¾ããããªãã
ããã¯ãVS Codeã®Workspaceã«ãããã¡ã¤ã«ï¼ããã§ã¯package.json
ï¼ã¯ã³ã³ãããä½æãããå¾ã§ãã¦ã³ããããããã
the Dockerfile runs before the dev container is created and the workspace folder is mounted and therefore does not have access to the files in the workspace folder. A Dockerfile is most suitable for installing packages and tools independent of your workspace files.
Create a development container using Visual Studio Code Remote Development
ãã®ããã«postCreateCommand
ã¨ããããã¯ãç¨æããã¦ããã
Workspaceå¤ã«ããè¨å®ãã¡ã¤ã«ãã³ã³ããã«æã¡è¾¼ã
"éçºç°å¢"ã¯VS Codeã®Workspaceã«éããªãã$HOME/.config
(See: XDG Base Directory Specification)ãªã©ãWorkspaceå¤ã«ããè¨å®ãã¡ã¤ã«ãã³ã³ããã«æã¡è¾¼ã¾ãªããã°ãªããªãã±ã¼ã¹ããããå®éãblogsyncã¯$HOME/.config/blogsync`ã«è¨å®ãã¡ã¤ã«ãç½®ããã¨ãæ³å®ããã¦ããã
ãããå®ç¾ããããã«ã¯ã.devcontainer.json
ã®ä¸ã§mounts
ã使ããmounts
ã¯ãã¹ãå´ã®ãã¡ã¤ã«ãã³ã³ããã«ãã¦ã³ãããããã®è¨å®ãDockerã®ãã¦ã³ãè¨å®ãã®ãã®ã
"mounts": [ { "source": "${localEnv:HOME}/.config/blogsync", "target": "/home/node/.config/blogsync", "type": "bind" } ]
ãã¨ã¯ã³ã³ããããã«ããã¦ãWorkspaceãã³ã³ããå´ã§éãã°è¯ãã
Workspaceãéããå¾ãblogsyncã®è¨å®ãã¡ã¤ã«ãã³ã³ããã«ãã¦ã³ãããã¦ãããã¨ã確èªã§ããã
$ whoami; ls ~/.config/blogsync node config.yaml
使ã£ã¦ã¿ã¦
ã³ã³ããã®ä¸ã§åä½ãã¦ããã¨ã¯æããªãã»ã©è»½å¿«ã«åãããã¼ã«ã«ã§éçºããã¦ããä½é¨ã¨ä½ãå¤ãããªãã å ¨å¡ãåãç°å¢ã§éçºãé²ããããã¨ããã®ã¯ãããã¸ã§ã¯ãã«ã¨ã£ã¦ã¯ãããããã ãã®ã¨ã³ããªãDev Containerã使ã£ã¦æ¸ãããã¾ã£ããéåæããªãã
VS Codeæ´¾ã¨IntelliJæ´¾ãæ··å¨ããç°å¢ã§ã¯ã©ããªã®ã ããã