|
| 1 | +# Development Container |
| 2 | + |
| 3 | +This project uses a [Development Container](https://containers.dev/) to provide a consistent development environment. |
| 4 | + |
| 5 | +## Getting Started |
| 6 | + |
| 7 | +1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop) |
| 8 | +2. Install [VS Code](https://code.visualstudio.com/) and the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) |
| 9 | +3. Open this folder in VS Code |
| 10 | +4. When prompted, click "Reopen in Container" (or run command: `Dev Containers: Reopen in Container`) |
| 11 | + |
| 12 | +## Local Customization |
| 13 | + |
| 14 | +To customize your local development environment without modifying the committed configuration, create a `.devcontainer/devcontainer.local.json` file (this file is gitignored). |
| 15 | + |
| 16 | +### Example: Add Additional VS Code Extensions |
| 17 | + |
| 18 | +```json |
| 19 | +{ |
| 20 | + "customizations": { |
| 21 | + "vscode": { |
| 22 | + "extensions": [ |
| 23 | + "esbenp.prettier-vscode", |
| 24 | + "usernamehw.errorlens" |
| 25 | + ] |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +### Example: Mount Additional Volumes |
| 32 | + |
| 33 | +```json |
| 34 | +{ |
| 35 | + "mounts": [ |
| 36 | + "source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig,type=bind,consistency=cached" |
| 37 | + ] |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +### Example: Override or Add Environment Variables |
| 42 | + |
| 43 | +The container sets several Python-related environment variables by default (see `Dockerfile.dev`). You can override them or add new ones using `remoteEnv`: |
| 44 | + |
| 45 | +```json |
| 46 | +{ |
| 47 | + "remoteEnv": { |
| 48 | + "PYTHONUNBUFFERED": "0", |
| 49 | + "DEBUG": "1", |
| 50 | + "LOG_LEVEL": "DEBUG" |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +See `devcontainer.local.json.example` for a complete list of default environment variables that can be overridden. |
| 56 | + |
| 57 | +Alternatively, create a `.devcontainer/.env` file (also gitignored): |
| 58 | +```bash |
| 59 | +DEBUG=1 |
| 60 | +LOG_LEVEL=DEBUG |
| 61 | +``` |
| 62 | + |
| 63 | +And reference it in `devcontainer.local.json`: |
| 64 | +```json |
| 65 | +{ |
| 66 | + "runArgs": ["--env-file", ".devcontainer/.env"] |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +### Example: Forward Additional Ports |
| 71 | + |
| 72 | +```json |
| 73 | +{ |
| 74 | + "forwardPorts": [8080, 3000] |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +## How It Works |
| 79 | + |
| 80 | +The Dev Container will: |
| 81 | +- Build from `Dockerfile.dev` |
| 82 | +- Mount your workspace to `/app` |
| 83 | +- Install Git and GitHub CLI features |
| 84 | +- Run `uv sync --all-groups` to create a virtual environment at `/app/.venv` |
| 85 | +- Configure VS Code to use the virtual environment's Python interpreter |
| 86 | +- Set up bash as the default terminal |
| 87 | + |
| 88 | +### Default Environment Variables |
| 89 | + |
| 90 | +The following Python-related environment variables are set in the container: |
| 91 | + |
| 92 | +- **`PYTHONUNBUFFERED=1`** - Ensures real-time output in logs |
| 93 | +- **`PYTHONDONTWRITEBYTECODE=1`** - Prevents `.pyc` file creation |
| 94 | +- **`PYTHONIOENCODING=utf-8`** - Ensures UTF-8 encoding for I/O |
| 95 | +- **`PIP_NO_CACHE_DIR=1`** - Disables pip caching to reduce container size |
| 96 | +- **`PIP_DISABLE_PIP_VERSION_CHECK=1`** - Suppresses pip update warnings |
| 97 | +- **`UV_NO_CACHE=1`** - Disables uv caching |
| 98 | +- **`UV_PROJECT_ENVIRONMENT=/app/.venv`** - Sets the virtual environment location for uv |
| 99 | +- **`LANG=C.UTF-8`** - Sets locale for proper Unicode handling |
| 100 | +- **`LC_ALL=C.UTF-8`** - Sets all locale categories to UTF-8 |
| 101 | + |
| 102 | +These can be overridden in `devcontainer.local.json` using the `remoteEnv` property. |
| 103 | + |
| 104 | +### Virtual Environment |
| 105 | + |
| 106 | +The project uses `uv` to manage dependencies. When the container is created: |
| 107 | +1. `uv sync --all-groups` is automatically run to create a virtual environment at `/app/.venv` |
| 108 | +2. VS Code is configured to use `/app/.venv/bin/python` as the Python interpreter |
| 109 | +3. All dependencies from `pyproject.toml` (including dev groups) are installed |
| 110 | + |
| 111 | +To manually update dependencies, run: |
| 112 | +```bash |
| 113 | +uv sync --all-groups |
| 114 | +``` |
| 115 | + |
| 116 | +## Rebuilding the Container |
| 117 | + |
| 118 | +If you modify the Dockerfile or devcontainer configuration: |
| 119 | +1. Run command: `Dev Containers: Rebuild Container` |
| 120 | +2. Or run: `Dev Containers: Rebuild Container Without Cache` for a clean build |
0 commit comments