-
Notifications
You must be signed in to change notification settings - Fork 39
Add DevContainer setup #723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughA development container configuration for Go projects has been introduced, including a new Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant VSCode
participant DevContainer
participant Docker
participant Host
Developer->>VSCode: Open project with devcontainer config
VSCode->>Docker: Build devcontainer using devcontainer.Dockerfile
Docker->>DevContainer: Start container with specified environment
DevContainer->>DevContainer: Run post-create command (go mod tidy)
VSCode->>DevContainer: Install extensions (Go, SQLTools, etc.)
Developer->>DevContainer: Develop using Go tools and extensions
Developer->>Host: Run dev/docker/compose script
Host->>Docker: Execute docker compose with env and config
Docker->>DevContainer: Mount Prometheus config using env variable
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Configure VS Code development environment by adding DevContainer setup with Go 1.24, Docker integration, and standardized tooling
📍Where to StartStart with the DevContainer configuration in devcontainer.json which defines the core development environment setup and references the other new files. Macroscope summarized 8e6d3ed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request adds a DevContainer configuration that allows the container to access Docker on the host machine.
- Updates the volume mapping in docker-compose.yml to use an environment variable for the host folder.
- Prepares a configuration that supports in-container testing and development via VSCode.
Files not reviewed (3)
- .devcontainer/devcontainer.json: Language not supported
- dev/docker/compose: Language not supported
- dev/docker/devcontainer.Dockerfile: Language not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (6)
dev/docker/docker-compose.yml (1)
33-33: Validate Prometheus config path and enforceHOST_DOCKER_DEV_FOLDER.
The fallback${HOST_DOCKER_DEV_FOLDER:-.}may resolve to an unintended directory if the environment variable is not set. Consider requiringHOST_DOCKER_DEV_FOLDERor updating the fallback to a known path (e.g.,$PWD/dev/docker) to prevent silent misconfiguration.dev/docker/devcontainer.Dockerfile (2)
4-4: Pin and verify thegolangci-lintinstaller source for reproducibility.
Downloading the install script fromHEADcan introduce unpredictability; pin to a tagged commit or add checksum verification to ensure the exact v2.0.2 binary and guard against upstream changes.
7-9: Optimize image layer size and caching.
Combineapt-get updateandinstallinto a singleRUN, add--no-install-recommends, and clean up apt caches to reduce image bloat:RUN apt-get update && \ apt-get install -y --no-install-recommends shellcheck jq && \ rm -rf /var/lib/apt/lists/*dev/docker/compose (1)
4-7: Handle missingdev/local.envand ensure executability.
Add a guard to verify thatdev/local.envexists before passing it to--env-fileand confirm the script is marked executable (chmod +x dev/docker/compose):if [ ! -f dev/local.env ]; then echo "Error: dev/local.env not found." >&2 exit 1 fi.devcontainer/devcontainer.json (2)
26-26: Reconsider using host networking for the devcontainer.
--network=hostreduces isolation and can introduce security risks. As noted, migrating to Docker’s bridge/internal networks is preferable—consider removing this once you tackle the larger refactor.
28-30: Pin the Docker feature version for stability.
Usingdocker-outside-of-docker:1may bring in minor updates unexpectedly. Consider specifying a more granular tag (e.g.,:1.0.0) to lock the feature version for reproducible builds.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.devcontainer/devcontainer.json(1 hunks)dev/docker/compose(1 hunks)dev/docker/devcontainer.Dockerfile(1 hunks)dev/docker/docker-compose.yml(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
- GitHub Check: Test (Node)
- GitHub Check: Upgrade Tests
- GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
🔇 Additional comments (2)
.devcontainer/devcontainer.json (2)
3-8: Validate build context and Dockerfile path resolution.
Ensure that"context": ".."and"dockerfile": "../dev/docker/devcontainer.Dockerfile"correctly resolve in single-root and multi-root scenarios so the Dockerfile is always found.
9-9:Details
❓ Verification inconclusive
Verify property for container environment variables.
The keyremoteEnvmay not inject variables into the container; the devcontainer specification usescontainerEnv. Please confirm or switch tocontainerEnvto ensureLOCAL_WORKSPACE_FOLDERandHOST_DOCKER_DEV_FOLDERare set.
🌐 Web query:
Does VS Code devcontainer.json support `remoteEnv` or `containerEnv` for setting container environment variables?💡 Result:
Yes, Visual Studio Code's
devcontainer.jsonfile supports bothcontainerEnvandremoteEnvproperties for setting environment variables in development containers.Comparison:
containerEnvvs.remoteEnv
Property Scope When to Use Update Behavior containerEnvSets variables for the entire container (all processes) For variables all processes need, or when static values Requires a full container rebuild to change remoteEnvSets variables only for VS Code server/sub-processes For variables needed just by VS Code or its sub-tools Can be updated by relaunching VS Code server Details
containerEnv:
- Sets or overrides environment variables for the entire container.
- Variables are accessible to any process inside the container.
- The variables are static for the container's life—updating them requires a container rebuild.
- Use for application-wide or system-wide environment variables[1][2][3][5].
remoteEnv:
- Sets or overrides environment variables only for VS Code server and supporting processes (terminals, tasks, debuggers, etc.).
- These do not affect processes running directly in the container outside the VS Code environment.
- Values can be changed more dynamically, usually requiring only a server process restart, not a container rebuild[1][3][5].
- Useful for customizing the environment specifically for your development tools[1][3][5].
Examples
// In devcontainer.json "containerEnv": { "DATABASE_URL": "postgresql://user:password@db:5432/mydb", "NODE_ENV": "development" }, "remoteEnv": { "PATH": "${containerEnv:PATH}:/custom/bin", "JAVA_HOME": "/docker-java-home" }
- In this example,
DATABASE_URLandNODE_ENVwill be available to all container processes.PATH(with the custom addition) andJAVA_HOMEwill affect only VS Code and its related tools[1][3][5].Recommendations
- Prefer
containerEnvfor variables needed container-wide.- Use
remoteEnvfor variables required only by VS Code or when you want to avoid rebuilding the container for each change[2][3][5].- If you use Docker Compose, only
remoteEnvis supported indevcontainer.json. For container-wide variables in that case, use theenvironmentproperty in yourdocker-compose.yml[1].Key Documentation and References
- [Visual Studio Code: Environment variables in dev containers][1]
- [Dev Container specification: containerEnv vs remoteEnv][3][5]
In summary, both
containerEnvandremoteEnvare officially supported for setting environment variables in a VS Code development container, each serving different scopes and update mechanisms[1][3][5].Citations:
- 1: https://code.visualstudio.com/remote/advancedcontainers/environment-variables
- 2: devcontainers/spec#233
- 3: https://devcontainers.github.io/implementors/json_reference/
- 4: https://code.visualstudio.com/docs/devcontainers/attach-container
- 5: https://www.daytona.io/dotfiles/ensuring-consistent-container-behavior
- 6: https://devcontainers.github.io/implementors/json_schema/
- 7: microsoft/vscode-remote-release#6903
- 8: https://code.visualstudio.com/docs/devcontainers/containers
- 9: https://youtrack.jetbrains.com/issue/IJPL-65950/remoteEnv-is-not-respected-during-postStartupCommand
Clarify environment variable scope in devcontainer.json
TheremoteEnvproperty is valid but only injects variables into the VS Code server and its sub‑processes (terminals, tasks, debuggers). It does not affect other processes running in the container. In contrast,containerEnvsets environment variables container‑wide (all processes) but requires a full rebuild to take effect.Please confirm your intended scope for
LOCAL_WORKSPACE_FOLDERandHOST_DOCKER_DEV_FOLDERand adjust accordingly:
- If you need these variables in all container processes (application code, build scripts, Docker Compose services), move them to
containerEnv.- If you only need them for VS Code’s integrated tools (terminals, debug sessions), keeping them in
remoteEnvis sufficient..devcontainer/devcontainer.json (around line 9)
- "remoteEnv": { - "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}", - "HOST_DOCKER_DEV_FOLDER": "${localWorkspaceFolder}/dev/docker" - }, + // For container‑wide variables (all processes), use: + "containerEnv": { + "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}", + "HOST_DOCKER_DEV_FOLDER": "${localWorkspaceFolder}/dev/docker" + }, + + // Or retain remoteEnv if only VS Code processes need these: + // "remoteEnv": { … }
| #!/bin/bash | ||
| set -eo pipefail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add explicit execution context.
docker compose will look for files relative to the current working directory. To avoid failures when invoked from elsewhere, change into the repo root at the top of the script:
cd "$(dirname "$0")/../.." || exit 1
mkysel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont use these but they can't hurt
|
I still haven't taken this to a place where I can use it daily (need the Graphite config). But it's a start. |
tl;dr
Give it a try. I could use feedback. I am able to run all the tests from inside the container, and VSCode works normally for me.
TODO
Summary by CodeRabbit
New Features
Chores