åºæåè©ã®å¤ãã¿ã¤ãã«ã§å¤±ç¤¼ãã¾ãã
åå¼·ãããã°ã108è¨äºã¢ã¦ããããããæ¥ ã«åå ä¸ã®ç°åã§ãã forceoutput.github.io
Devcontainer 㧠Tilt ã®ç°å¢ãä½ã£ã¦ Docker Compose ã§è¨è¿°ãããµã¼ãã¹ãç«ã¡ä¸ãã¦ããã¾ãã
- ãªã«ãããã®ã
- Devcontainer ã®æºå
- ãµã³ãã«ã¢ããªã®æºå
- Tiltfile ã®æºå
- ãµã¼ãã¹ãåãã
- ãããã«
ãªã«ãããã®ã
Tilt (https://tilt.dev/)ã¯ã"A toolkit for fixing the pains of microservice development." ã¨éæãããããã¼ã«ã«ç°å¢ã§è¤æ°ã³ã³ããããã¾ãæ±ãããã®ãã®ã§ãã Tilt 㯠k8s ä¸ã«æ§ç¯ããããµã¼ãã¹ããã¼ã«ã«ã§èµ·åãããã¨ã主ããç®çã«ãã¦ãã¾ãããDocker Compose ã§æ§ç¯ããããµã¼ãã¹ãæ±ããã¨ãã§ãã¾ãã
ä»åã¯ãã¾ã Devcontainer 㧠Tilt ãã®ãã®ã®ç°å¢ãä½ãããã®ãã㧠Docker Compose ã§è¨è¿°ããããµã¼ãã¹ããã¼ã«ã«ã§åããã¦ã¿ã¾ãã
Devcontainer ã®æºå
Tilt ã使ãããã® Devcontainer ãç¨æãã¾ãã
Tilt ã®ã¤ã³ã¹ãã¼ã«ã¯ãããã¥ã¡ã³ãã«ãããã£ã¦ curl ã§ã¤ã³ã¹ãã¼ã«ã¹ã¯ãªãããè½ã¨ãã¦ãã¦ããããå®è¡ããããã¨ã«ãã¾ãã Install | Tilt
Tilt ã«å ãã¦ãDocker ãå¿ è¦ã«ãªãã¾ããããã«ã¯ DinD (Docker in Docker) ã§ããããDooD (Docker outside of Docker) ã§ãããã®é¸æè¢ãããã¾ãã ä»åã¯ãã㦠Docker ç°å¢ãåé¢ããã¢ããã¼ã·ã§ã³ãç¡ããããç´ ç´ã« DooD ã§æ§ç¯ãã¾ãã
ããããéã¿ã¦æ¸ãã devcontainer.json
㨠Dockerfile
ããã¡ãã«ãªãã¾ãã
devcontainer.json
// For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/docker-outside-of-docker { "name": "Tilt Dev Container", "build": { "dockerfile": "Dockerfile" }, "features": { "ghcr.io/devcontainers/features/docker-outside-of-docker:1": { "version": "latest", "enableNonRootDocker": "true", "moby": "true" } }, // Use this environment variable if you need to bind mount your local source code into a new container. "remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" } // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. // "postCreateCommand": "docker --version", // Configure tool-specific properties. // "customizations": {}, // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" }
Dockerfile
FROM mcr.microsoft.com/devcontainers/base:ubuntu RUN apt update && apt install -y xdg-utils RUN curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
ãã㧠VSCode 㧠Devcontainer ãéããTilt ãå®è¡ã§ããããã«ãªãã¾ããã
ãµã³ãã«ã¢ããªã®æºå
ã¤ãã« Tilt ã§èµ·åããããµã³ããªã¢ããªãæºåãã¾ãã GET ãªã¯ã¨ã¹ãã«å¯¾ã㦠"Hello, World!" ãè¿ã Python ã¹ã¯ãªããããã·ã³ãã«ã«ã³ã³ããåãã¾ãã
app1.py
import http.server import socketserver PORT = 3000 class Handler(http.server.SimpleHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-type', 'text/plain') self.end_headers() self.wfile.write(b'Hello, World!') with socketserver.TCPServer(("", PORT), Handler) as httpd: print(f"Serving on port {PORT}") httpd.serve_forever()
Dockerfile
FROM python:3.13-bookworm WORKDIR /app COPY app1.py /app/ EXPOSE 3000 CMD ["python", "app1.py"]
ããã«ããã Docker Compose ã§è¨è¿°ãã¾ãã
docker-compose.yml
services: app1: image: sample/app1 container_name: sample_app1 build: ./app1 ports: - "3000:3000"
ãã®æ®µéã§ãdocker compose up
ã§ãµã¼ãã¹ãèµ·åã§ããç¶æ
ã«ãªãã¾ããã
Tiltfile ã®æºå
æå¾ã« Tiltfile ãæ¸ãã¦ããã¾ããTilt ã¯ãããèªãã§ãµã¼ãã¹ãèµ·åãããã¨ã«ãªãã¾ãã
Tiltfile 㯠Starlark ã¨ãã Python æ¹è¨ã§è¨è¿°ãã¾ãã Launching & Managing Resources | Tilt
ä»å使ã Titlefile ã¯ãã¡ãã
Tiltfile
version_settings(constraint='>=0.33.21') docker_compose('docker-compose.yml') docker_build( 'sample/app1', './app1', live_update = [ sync('./app1', '/app'), restart_container() ]) dc_resource('app1', labels=["server"])hon
ããã¾ã§ã§ã以ä¸ã®ãããªãã¡ã¤ã«ã®é ç½®ã«ãªã£ã¦ãã¾ãã
$ tree . -a -I ".git" . âââ .devcontainer â  âââ Dockerfile â  âââ devcontainer.json âââ Tiltfile âââ app1 â  âââ Dockerfile â  âââ app1.py âââ docker-compose.yml 2 directories, 6 files
ãµã¼ãã¹ãåãã
ãµã¼ãã¹ãç«ã¡ä¸ãã¦ã¿ã¾ããDevcontainer ã®ã·ã§ã«ã§ tilt up
ãå®è¡ãã¾ãã
vscode â /workspaces/tilt-multi-docker-compose (main) $ tilt up Tilt started on http://localhost:10350/ v0.33.21, built 2024-11-08 (space) to open the browser (s) to stream logs (--stream=true) (t) to open legacy terminal mode (--legacy=true) (ctrl-c) to exit Opening browser: http://localhost:10350/
ã¹ãã¼ã¹ãæ¼ãã¦ããã©ã¦ã¶ã§ Tilt ã® Web UI ãéãã¾ãã
ãã㧠Tiltfile ã valid ã§ããããµã¼ãã¹ã®ã³ã³ãããç«ã¡ä¸ãããã¨ã«æåãã¦ãããã¨ããããã¾ããããããã§ä½ãã¨ã©ã¼ãããã°ãããã«ã¨ã©ã¼ãã¯ã¼ãã³ã°ã表示ããã¾ãã
Endpoints ã®æ¬ã«ãã localhost:3000
ã«ã¢ã¯ã»ã¹ããã¨ãç¡äºã«ãµã³ãã«ã¢ããªãåãã¦ãããã¨ããããã¾ãã
Tilt ã®ç¹é·ã®ã²ã¨ã¤ã«ãæè»ãªã©ã¤ããªãã¼ããããã¾ãã
å
ã»ã©ã® Tiltfile ã§ã ./app1/
é
ä¸ã®ãã¡ã¤ã«ã«å¤æ´ããã£ããã³ã³ãããåèµ·åãããè¨è¿°ããã¦ãã¾ããããã試ãã¦ã¿ã¾ãããã
app1.py
ã§ãã¬ã¹ãã³ã¹ã®ã¡ãã»ã¼ã¸ãæ¸ãæãã¦ã¿ã¾ãã
ãããä¿åããã¨ã"1 File Changed: [app1/app1.py] ⢠app1" ã¨ããããã«ããã¡ã¤ã«ã®å¤æ´ãæ¤ç¥ãããã³ã³ããã®åèµ·åãèµ°ãã¾ãã
å度 localhost:3000
ã«ã¢ã¯ã»ã¹ããã¨ãç¡äºã«ã¬ã¹ãã³ã¹ãæ´æ°ããã¦ãããã¨ããããã¾ãã
ãã®ããã«ãè¨èªããã¬ã¼ã ã¯ã¼ã¯ã«é¢ä¿ãªãã©ã¤ãã¢ãããã¼ããä»è¾¼ããã¨ãã§ããã®ã§ã¯ãTilt ã®å¼·ã¿ã¨è¨ãã¾ãããã
ãããã«
Devcontainerã§Tiltã®ç°å¢ãä½ã£ã¦Docker Composeã§è¨è¿°ãããµã¼ãã¹ãç«ã¡ä¸ããæé ãç´¹ä»ãã¾ããã ã¿ãªããã® Tilt æ å ±ããå¾ ã¡ãã¦ããã¾ãã