|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This repository provides a Dev Container Feature that installs Jetify Devbox in development containers. Devbox is a command-line tool that creates isolated shells for development using Nix. |
| 8 | + |
| 9 | +## Key Commands |
| 10 | + |
| 11 | +### Testing |
| 12 | +```bash |
| 13 | +# Run all tests |
| 14 | +devcontainer features test . |
| 15 | + |
| 16 | +# Test specific feature |
| 17 | +devcontainer features test -f jetify-devbox . |
| 18 | + |
| 19 | +# Test specific scenario |
| 20 | +devcontainer features test -f jetify-devbox --skip-autogenerated . |
| 21 | + |
| 22 | +# Test with specific base image |
| 23 | +devcontainer features test -f jetify-devbox --base-image ubuntu:focal . |
| 24 | + |
| 25 | +# Run only global scenarios |
| 26 | +devcontainer features test --global-scenarios-only . |
| 27 | +``` |
| 28 | + |
| 29 | +### Development Setup |
| 30 | +```bash |
| 31 | +# Install devcontainer CLI (required for testing) |
| 32 | +npm install -g @devcontainers/cli |
| 33 | +``` |
| 34 | + |
| 35 | +## Architecture |
| 36 | + |
| 37 | +### Feature Structure |
| 38 | +- **src/jetify-devbox/**: Feature implementation |
| 39 | + - `devcontainer-feature.json`: Feature metadata defining options and dependencies |
| 40 | + - `install.sh`: Installation script that installs Devbox via Nix |
| 41 | + - `ReadMe.md`: Feature-specific documentation |
| 42 | + |
| 43 | +- **test/jetify-devbox/**: Feature tests |
| 44 | + - `test.sh`: Basic functionality tests |
| 45 | + - `scenarios.json`: Test scenarios configuration |
| 46 | + - `test_*.sh`: Scenario-specific test scripts |
| 47 | + - `devbox.json`: Sample Devbox configuration for testing |
| 48 | + |
| 49 | +### Installation Flow |
| 50 | +1. Nix dependency is installed automatically (via `dependsOn`) |
| 51 | +2. `install.sh` runs during container build: |
| 52 | + - Adds Nix unstable channel |
| 53 | + - Installs Devbox using Nix profile |
| 54 | + - Creates post-setup script at `/usr/local/share/devbox-post-setup.sh` |
| 55 | + - Creates manual setup helper at `/usr/local/bin/devbox-setup` |
| 56 | +3. Post-setup script runs on container creation via `onCreateCommand`: |
| 57 | + - Checks for `devbox.json` in workspace |
| 58 | + - Runs `devbox update` to initialize environment |
| 59 | + - Configures shell environment |
| 60 | + |
| 61 | +### Key Implementation Details |
| 62 | + |
| 63 | +#### Feature Options |
| 64 | +- `autoUpdate` (boolean, default: true): Controls whether `devbox update` runs automatically |
| 65 | + |
| 66 | +#### Environment Variables |
| 67 | +- `DEVBOX_FEATURE_INSTALLED`: Set to "true" in container environment |
| 68 | +- `WORKSPACE_FOLDER`: Used to locate `devbox.json` |
| 69 | +- `_REMOTE_USER`: Used to run commands as non-root user |
| 70 | + |
| 71 | +#### Scripts Created |
| 72 | +- `/usr/local/share/devbox-post-setup.sh`: Runs on container creation |
| 73 | +- `/usr/local/bin/devbox-setup`: Manual setup helper |
| 74 | +- `/usr/local/share/devbox-auto-update-enabled`: Stores autoUpdate preference |
| 75 | + |
| 76 | +### Testing Architecture |
| 77 | + |
| 78 | +The test suite verifies: |
| 79 | +1. **Basic functionality** (`test.sh`): |
| 80 | + - Devbox installation |
| 81 | + - PATH configuration |
| 82 | + - Basic commands (`devbox version`, `devbox init`, `devbox shell`) |
| 83 | + |
| 84 | +2. **Scenario tests**: |
| 85 | + - `auto_update_enabled`: Verifies automatic setup with devbox.json |
| 86 | + - `auto_update_disabled`: Verifies manual setup workflow |
| 87 | + - `test_vscode_integration`: Tests VS Code terminal integration |
| 88 | + - `test_with_user_oncreate`: Ensures compatibility with user onCreateCommand |
| 89 | + - `test_different_base_images`: Tests various base image compatibility |
| 90 | + |
| 91 | +### CI/CD Pipeline |
| 92 | + |
| 93 | +GitHub Actions workflow (`.github/workflows/test.yaml`): |
| 94 | +- Tests against multiple base images (Alpine, Debian, Ubuntu, devcontainers/base) |
| 95 | +- Runs autogenerated tests, scenario tests, and global tests |
| 96 | +- Uploads test logs on failure for debugging |
| 97 | + |
| 98 | +## Important Patterns |
| 99 | + |
| 100 | +1. **Shell Script Safety**: All scripts use `set -e` for error handling |
| 101 | +2. **User Context**: Scripts handle both root and non-root execution |
| 102 | +3. **Logging**: Post-setup script logs to `/tmp/devbox-setup.log` |
| 103 | +4. **Idempotency**: Scripts check for existing configurations before running |
| 104 | +5. **Feature ID**: The feature ID is `jetify-devbox` (not just `devbox`) |
0 commit comments