|
| 1 | +// For format details, see https://containers.dev/implementors/json_reference/ |
| 2 | +{ |
| 3 | + "name": "Python 3 Developer Container", |
| 4 | + "build": { |
| 5 | + "dockerfile": "../Dockerfile", |
| 6 | + "target": "developer" |
| 7 | + },{% if add_claude %} |
| 8 | + // Tell VS Code the remote user is root so copyGitConfig writes to |
| 9 | + // /root/.gitconfig (matching $HOME in the shell); otherwise it falls back |
| 10 | + // to the base image's USER and the copy lands in the wrong home. |
| 11 | + "remoteUser": "root",{% endif %} |
| 12 | + "remoteEnv": { |
| 13 | + // Allow X11 apps to run inside the container |
| 14 | + "DISPLAY": "${localEnv:DISPLAY}",{% if add_claude %} |
| 15 | + // Disable SSH agent forwarding — prevents Claude from using host SSH keys |
| 16 | + "SSH_AUTH_SOCK": "", |
| 17 | + // Disable VS Code git credential injection — prevents askpass from |
| 18 | + // relaying host GitHub credentials into the container over the IPC socket |
| 19 | + "GIT_ASKPASS": "", |
| 20 | + "VSCODE_GIT_IPC_HANDLE": "", |
| 21 | + "VSCODE_GIT_ASKPASS_MAIN": "", |
| 22 | + "VSCODE_GIT_ASKPASS_NODE": "", |
| 23 | + "VSCODE_GIT_ASKPASS_EXTRA_ARGS": "",{% endif %} |
| 24 | + // Mark this shell as running inside the devcontainer |
| 25 | + "IN_DEVCONTAINER": "1", |
| 26 | + // Put things that allow it in the persistent cache |
| 27 | + "PRE_COMMIT_HOME": "/cache/pre-commit", |
| 28 | + "UV_CACHE_DIR": "/cache/uv", |
| 29 | + "UV_PYTHON_CACHE_DIR": "/cache/uv-python", |
| 30 | + // Make a venv that is specific for this workspace path as the cache is shared |
| 31 | + "UV_PROJECT_ENVIRONMENT": "/cache/venv-for${localWorkspaceFolder}", |
| 32 | + // Do the equivalent of "activate" the venv so we don't have to "uv run" everything |
| 33 | + "VIRTUAL_ENV": "/cache/venv-for${localWorkspaceFolder}", |
| 34 | + "PATH": "/cache/venv-for${localWorkspaceFolder}/bin:${containerEnv:PATH}" |
| 35 | + }, |
| 36 | + "customizations": { |
| 37 | + "vscode": { |
| 38 | + // Set *default* container specific settings.json values on container create. |
| 39 | + "settings": { |
| 40 | + // Use the container's python by default |
| 41 | + "python.defaultInterpreterPath": "/cache/venv-for${localWorkspaceFolder}/bin/python", |
| 42 | + // Don't activate the venv as it is already in the PATH |
| 43 | + "python.terminal.activateEnvInCurrentTerminal": false, |
| 44 | + "python.terminal.activateEnvironment": false, |
| 45 | + // Workaround to prevent garbled python REPL in the terminal |
| 46 | + // https://github.com/microsoft/vscode-python/issues/25505 |
| 47 | + "python.terminal.shellIntegration.enabled": false{% if sphinx %}, |
| 48 | + // Only forward explicitly listed ports — auto-detection races with |
| 49 | + // sphinx-autobuild and steals the port on restart |
| 50 | + "remote.autoForwardPorts": false{% endif %} |
| 51 | + }, |
| 52 | + // Add the IDs of extensions you want installed when the container is created. |
| 53 | + "extensions": [ |
| 54 | + "ms-python.python", |
| 55 | + "github.vscode-github-actions", |
| 56 | + "tamasfe.even-better-toml", |
| 57 | + "redhat.vscode-yaml", |
| 58 | + "ryanluker.vscode-coverage-gutters", |
| 59 | + "charliermarsh.ruff", |
| 60 | + "ms-azuretools.vscode-docker"{% if add_claude %}, |
| 61 | + "anthropic.claude-code"{% endif %} |
| 62 | + ] |
| 63 | + } |
| 64 | + },{% if sphinx %} |
| 65 | + // Explicitly forward sphinx-autobuild port (auto-detection disabled above) |
| 66 | + "forwardPorts": [ |
| 67 | + 8000 |
| 68 | + ],{% endif %} |
| 69 | + // Create host-side dirs needed for bind mounts before the container starts |
| 70 | + "initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config{% if add_claude %} ${localEnv:HOME}/.claude{% endif %}", |
| 71 | + "runArgs": [ |
| 72 | + // Allow the container to access the host X11 display and EPICS CA |
| 73 | + "--net=host", |
| 74 | + // Make sure SELinux does not disable with access to host filesystems like tmp |
| 75 | + "--security-opt=label=disable" |
| 76 | + ], |
| 77 | + "mounts": [ |
| 78 | + // Mount in the user terminal config folder so it can be edited |
| 79 | + { |
| 80 | + "source": "${localEnv:HOME}/.config/terminal-config", |
| 81 | + "target": "/user-terminal-config", |
| 82 | + "type": "bind" |
| 83 | + }, |
| 84 | + // Keep a persistent cross container cache for uv, pre-commit, and the venvs |
| 85 | + { |
| 86 | + "source": "devcontainer-shared-cache", |
| 87 | + "target": "/cache", |
| 88 | + "type": "volume" |
| 89 | + }{% if install_gh %}, |
| 90 | + // Persist gh auth across container rebuilds with per-repo scoped PAT |
| 91 | + { |
| 92 | + "source": "gh-auth-${localWorkspaceFolderBasename}", |
| 93 | + "target": "/root/.config/gh", |
| 94 | + "type": "volume" |
| 95 | + }{% endif %}{% if install_glab %}, |
| 96 | + // Persist glab auth across container rebuilds (GitLab CLI) |
| 97 | + { |
| 98 | + "source": "glab-auth-${localWorkspaceFolderBasename}", |
| 99 | + "target": "/root/.config/glab-cli", |
| 100 | + "type": "volume" |
| 101 | + }{% endif %}{% if add_claude %}, |
| 102 | + // Mount Claude config from host (settings, memory, skills) |
| 103 | + { |
| 104 | + "source": "${localEnv:HOME}/.claude", |
| 105 | + "target": "/root/.claude", |
| 106 | + "type": "bind" |
| 107 | + }{% endif %} |
| 108 | + ], |
| 109 | + // Mount the parent as /workspaces so we can pip install peers as editable |
| 110 | + "workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",{% if add_claude %} |
| 111 | + "postCreateCommand": ".devcontainer/postCreate.sh", |
| 112 | + "postStartCommand": ".devcontainer/postStart.sh"{% else %} |
| 113 | + // After the container is created, recreate the venv then make pre-commit first run faster |
| 114 | + "postCreateCommand": "uv venv --clear && uv sync && pre-commit install --install-hooks"{% endif %} |
| 115 | +} |
0 commit comments