diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index a6053ab5d..f59b062e2 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,32 +10,16 @@ ARG PYTHON_VERSION ENV TZ="$TZ" -# Install basic development tools and iptables/ipset +# Install build dependencies needed for further installations RUN apt-get update && apt-get install -y --no-install-recommends \ - sqlite3 \ - less \ - git \ - procps \ - sudo \ - fzf \ - zsh \ - man-db \ - unzip \ - gnupg2 \ - gh \ - iptables \ - ipset \ - iproute2 \ - dnsutils \ - aggregate \ - jq \ - nano \ - vim \ + wget \ + curl \ ca-certificates \ build-essential \ pkg-config \ - curl \ + gnupg2 \ python${PYTHON_VERSION}-dev \ + sudo \ && apt-get clean && rm -rf /var/lib/apt/lists/* # Ensure default node user has access to /usr/local/share @@ -128,7 +112,6 @@ RUN rustc --version \ && go version \ && uv --version - # Install global packages ENV NPM_CONFIG_PREFIX=/usr/local/share/npm-global ENV PATH=$PATH:/usr/local/share/npm-global/bin @@ -140,6 +123,35 @@ ENV SHELL=/bin/zsh ENV EDITOR=vim ENV VISUAL=vim +# Switch back to root to install runtime dependencies +USER root + +# Install runtime dependencies for final image +RUN apt-get update && apt-get install -y --no-install-recommends \ + traceroute \ + iputils-ping \ + sqlite3 \ + less \ + git \ + procps \ + fzf \ + zsh \ + man-db \ + unzip \ + gh \ + iptables \ + ipset \ + iproute2 \ + dnsutils \ + aggregate \ + jq \ + nano \ + vim \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +# Switch back to node user +USER node + # Default powerline10k theme RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v${ZSH_IN_DOCKER_VERSION}/zsh-in-docker.sh)" -- \ -p git \ @@ -151,11 +163,3 @@ RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/ # Install Claude RUN npm install -g @anthropic-ai/claude-code@${CLAUDE_CODE_VERSION} - -# Copy and set up firewall script -COPY init-firewall.sh /usr/local/bin/ -USER root -RUN chmod +x /usr/local/bin/init-firewall.sh && \ - echo "node ALL=(root) NOPASSWD: /usr/local/bin/init-firewall.sh" > /etc/sudoers.d/node-firewall && \ - chmod 0440 /etc/sudoers.d/node-firewall -USER node diff --git a/.devcontainer/Dockerfile.squid b/.devcontainer/Dockerfile.squid new file mode 100644 index 000000000..fd90e677d --- /dev/null +++ b/.devcontainer/Dockerfile.squid @@ -0,0 +1,2 @@ +FROM ubuntu/squid:latest +RUN apt-get update && apt-get install -y netcat-openbsd && rm -rf /var/lib/apt/lists/* diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4000a7ffc..ba4cd4632 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,18 +1,10 @@ { "name": "tursodb sandbox", - "build": { - "dockerfile": "Dockerfile", - "args": { - "TZ": "${localEnv:TZ:America/Los_Angeles}", - "CLAUDE_CODE_VERSION": "latest", - "GIT_DELTA_VERSION": "0.18.2", - "ZSH_IN_DOCKER_VERSION": "1.2.0", - "GO_VERSION": "1.24.10", - "RUST_VERSION": "1.88.0", - "PYTHON_VERSION": "3.11" - } - }, - "runArgs": ["--cap-add=NET_ADMIN", "--cap-add=NET_RAW"], + "dockerComposeFile": ["docker-compose.yml"], + "service": "tursodb", + "remoteUser": "node", + "workspaceFolder": "/workspace", + "waitFor": "postStartCommand", "customizations": { "vscode": { "extensions": [ @@ -52,19 +44,5 @@ } } } - }, - "remoteUser": "node", - "mounts": [ - "source=claude-code-bashhistory-${devcontainerId},target=/commandhistory,type=volume", - "source=claude-code-config-${devcontainerId},target=/home/node/.claude,type=volume" - ], - "containerEnv": { - "NODE_OPTIONS": "--max-old-space-size=4096", - "CLAUDE_CONFIG_DIR": "/home/node/.claude", - "POWERLEVEL9K_DISABLE_GITSTATUS": "true" - }, - "workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=delegated", - "workspaceFolder": "/workspace", - "postStartCommand": "sudo /usr/local/bin/init-firewall.sh", - "waitFor": "postStartCommand" + } } diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 000000000..2b61b6248 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,60 @@ +version: "3.9" + +services: + proxy: + build: + context: . + dockerfile: Dockerfile.squid + networks: [sandbox, egress] + volumes: + - ./squid.conf:/etc/squid/squid.conf:ro + healthcheck: + test: ["CMD", "nc", "-z", "127.0.0.1", "3128"] + interval: 1s + timeout: 5s + retries: 10 + start_period: 1s + tursodb: + depends_on: + proxy: + condition: service_healthy + build: + context: . + dockerfile: Dockerfile + args: + TZ: ${TZ:-America/Los_Angeles} + CLAUDE_CODE_VERSION: "latest" + GIT_DELTA_VERSION: "0.18.2" + ZSH_IN_DOCKER_VERSION: "1.2.0" + GO_VERSION: "1.24.10" + RUST_VERSION: "1.88.0" + PYTHON_VERSION: "3.11" + environment: + NODE_OPTIONS: "--max-old-space-size=4096" + CLAUDE_CONFIG_DIR: "/home/node/.claude" + POWERLEVEL9K_DISABLE_GITSTATUS: "true" + HTTP_PROXY: "http://proxy:3128" + HTTPS_PROXY: "http://proxy:3128" + ALL_PROXY: "http://proxy:3128" + NO_PROXY: "localhost,127.0.0.1" + networks: [sandbox] + volumes: + - ..:/workspace:delegated + - claude-code-bashhistory:/commandhistory + - claude-code-config:/home/node/.claude + + cap_add: + - NET_ADMIN + - NET_RAW + + init: true + tty: true + +volumes: + claude-code-bashhistory: + claude-code-config: +networks: + sandbox: + internal: true + egress: + driver: bridge diff --git a/.devcontainer/squid.conf b/.devcontainer/squid.conf new file mode 100644 index 000000000..2f59cb626 --- /dev/null +++ b/.devcontainer/squid.conf @@ -0,0 +1,35 @@ +http_port 3128 + +# DNS +dns_v4_first on + +# Allowed domains +acl allowed dstdomain \ + .pythonhosted.org \ + .pypi.org \ + .crates.io \ + .static.rust-lang.org \ + .npmjs.org \ + .github.com \ + .githubusercontent.com \ + .go.dev \ + .golang.org \ + .anthropic.com \ + .openai.com \ + .sentry.io \ + .statsig.com \ + .visualstudio.com \ + .windows.net + +# Allow HTTPS CONNECT only to allowed domains +acl SSL_ports port 443 +acl Safe_ports port 80 443 +acl CONNECT method CONNECT + +http_access deny !Safe_ports +http_access deny CONNECT !SSL_ports +http_access allow allowed +http_access deny all + +# Logging +access_log stdio:/var/log/squid/access.log