Skip to content

Commit c94a2e1

Browse files
committed
Major refactoring done for feature and testing
1 parent bbde6db commit c94a2e1

20 files changed

Lines changed: 388 additions & 114 deletions

‎.devcontainer/devcontainer.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
"extensions": [
1616
"mads-hartmann.bash-ide-vscode",
1717
"GitHub.copilot",
18-
"GitHub.copilot-chat"
18+
"GitHub.copilot-chat",
19+
"Anthropic.claude-code"
1920
]
2021
}
2122
},
2223
"features": {
2324
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
2425
},
2526
"remoteUser": "node",
26-
"updateContentCommand": "npm install -g @devcontainers/cli"
27+
"updateContentCommand": "npm install -g @devcontainers/cli @anthropic-ai/claude-code"
2728
}

‎.github/workflows/test.yaml‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
features:
16-
- devbox
16+
- jetify-devbox # Changed from 'devbox' to match the feature ID
1717
baseImage:
1818
- alpine:latest
1919
- debian:latest
@@ -34,7 +34,7 @@ jobs:
3434
strategy:
3535
matrix:
3636
features:
37-
- devbox
37+
- jetify-devbox # Changed from 'devbox' to match the feature ID
3838
steps:
3939
- uses: actions/checkout@v4
4040

@@ -48,10 +48,11 @@ jobs:
4848
if: failure()
4949
uses: actions/upload-artifact@v4
5050
with:
51-
name: test-logs
51+
name: test-logs-${{ github.run_id }}
5252
path: |
5353
**/devbox-setup.log
5454
**/test-results.log
55+
/tmp/devbox-setup.log
5556
5657
test-global:
5758
runs-on: ubuntu-latest
@@ -69,7 +70,8 @@ jobs:
6970
if: failure()
7071
uses: actions/upload-artifact@v4
7172
with:
72-
name: test-logs
73+
name: test-logs-global-${{ github.run_id }}
7374
path: |
7475
**/devbox-setup.log
7576
**/test-results.log
77+
/tmp/devbox-setup.log

‎.vscode/extensions.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
// List of extensions which should be recommended for users of this workspace.
66
"recommendations": [
77
"github.copilot",
8-
"github.copilot-chat"
8+
"github.copilot-chat",
9+
"anthropic.claude-code"
910
],
1011
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
1112
"unwantedRecommendations": [

‎CLAUDE.md‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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`)

‎README.md‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To use the feature in your devcontainer, add it to your `devcontainer.json`:
1111
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
1212
"features": {
1313
"ghcr.io/righteouslabs/devcontainer-jetify-devbox/devbox:1": {
14-
"initRepo": true
14+
"autoUpdate": true
1515
}
1616
}
1717
}
@@ -21,17 +21,17 @@ To use the feature in your devcontainer, add it to your `devcontainer.json`:
2121

2222
| Option | Type | Default | Description |
2323
|--------|------|---------|-------------|
24-
| initRepo | boolean | true | Initialize the repository by running 'devbox update' from the root of the repository. This relies on 'devbox.json' file being present in the root of the repository. |
24+
| autoUpdate | boolean | true | Automatically run 'devbox update' after container creation. This relies on 'devbox.json' file being present in the root of the repository. |
2525

2626
## Prerequisites
2727

2828
- The feature requires the Nix package manager and automatically installs it as a dependency.
29-
- For initialization (`initRepo: true`), a `devbox.json` file must be present in the root of your repository.
29+
- For automatic updates (`autoUpdate: true`), a `devbox.json` file must be present in the root of your repository.
3030

3131
## How it works
3232

3333
1. Installs Devbox using Nix
34-
2. If `initRepo` is true and a `devbox.json` file exists in your repository:
34+
2. If `autoUpdate` is true and a `devbox.json` file exists in your repository:
3535
- Changes to the repository root
3636
- Runs `devbox update` to initialize the development environment
3737

@@ -42,11 +42,11 @@ This repository follows the standard [dev container Feature](https://containers.
4242
```
4343
.
4444
├── src
45-
│ └── devbox
45+
│ └── jetify-devbox
4646
│ ├── devcontainer-feature.json # Feature metadata and options
4747
│ └── install.sh # Installation script
4848
└── test
49-
└── devbox # Feature-specific tests
49+
└── jetify-devbox # Feature-specific tests
5050
├── scenarios.json # Test scenarios
5151
└── test.sh # Test script
5252
```
@@ -64,12 +64,12 @@ The feature includes automated tests that verify the functionality through diffe
6464
- Checks that basic commands work (e.g., `devbox version`)
6565

6666
2. Scenario Tests:
67-
- `devbox_without_init.sh`: Tests feature with `initRepo: false`
68-
- `devbox_with_init.sh`: Tests feature with `initRepo: true`
67+
- `test_auto_update_disabled.sh`: Tests feature with `autoUpdate: false`
68+
- `test_auto_update_enabled.sh`: Tests feature with `autoUpdate: true`
6969
- Both scenarios use Ubuntu-based container image
7070

7171
3. Test Configuration:
72-
- Sample `devbox.json` in `test/devbox/` with basic packages:
72+
- Sample `devbox.json` in `test/jetify-devbox/` with basic packages:
7373
```json
7474
{
7575
"packages": [
@@ -92,11 +92,11 @@ The feature includes automated tests that verify the functionality through diffe
9292
# Test all features
9393
devcontainer features test .
9494

95-
# Test only your devbox feature
96-
devcontainer features test -f devbox .
95+
# Test only your jetify-devbox feature
96+
devcontainer features test -f jetify-devbox .
9797

9898
# Test with specific base image
99-
devcontainer features test -f devbox --base-image ubuntu:focal .
99+
devcontainer features test -f jetify-devbox --base-image ubuntu:focal .
100100

101101
# Run only scenario tests
102102
devcontainer features test --skip-autogenerated .
@@ -107,11 +107,11 @@ The feature includes automated tests that verify the functionality through diffe
107107

108108
#### Test Scenarios Configuration
109109

110-
The test scenarios are defined in `test/devbox/scenarios.json`
110+
The test scenarios are defined in `test/jetify-devbox/scenarios.json`
111111

112112
#### Test Configuration
113113

114-
The test suite uses a sample `devbox.json` in the `test/devbox` directory:
114+
The test suite uses a sample `devbox.json` in the `test/jetify-devbox` directory:
115115

116116
```json
117117
{
File renamed without changes.

src/devbox/devcontainer-feature.json renamed to src/jetify-devbox/devcontainer-feature.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"id": "jetify-devbox",
44
"version": "1.0.0",
55
"description": "Instant, easy, and predictable development environments using Jetify Devbox",
6+
"documentationURL": "https://github.com/righteouslabs/devcontainer-jetify-devbox",
67
"dependsOn": {
78
"ghcr.io/devcontainers/features/nix": {}
89
},
@@ -13,8 +14,11 @@
1314
"description": "Automatically run 'devbox update' after container creation"
1415
}
1516
},
16-
"onCreateCommand": "/usr/local/share/devbox-post-setup.sh",
17+
"installsAfter": [
18+
"ghcr.io/devcontainers/features/common-utils"
19+
],
1720
"containerEnv": {
1821
"DEVBOX_FEATURE_INSTALLED": "true"
19-
}
22+
},
23+
"onCreateCommand": "/usr/local/share/devbox-post-setup.sh"
2024
}
Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,23 @@ fi
2424

2525
echo "devbox installed successfully."
2626

27-
# Create post-setup script for devbox update
27+
# Save the autoUpdate option value for the onCreate script
28+
echo "${AUTOUPDATE}" > /usr/local/share/devbox-auto-update-enabled
29+
30+
# Always create the onCreate script, but make it check the option
2831
cat << 'EOF' > /usr/local/share/devbox-post-setup.sh
2932
#!/bin/bash
3033
set -e
3134
35+
# Check if auto-update is enabled
36+
AUTO_UPDATE_ENABLED=$(cat /usr/local/share/devbox-auto-update-enabled 2>/dev/null || echo "true")
37+
38+
if [ "${AUTO_UPDATE_ENABLED}" != "true" ]; then
39+
echo "Devbox auto-update is disabled. Skipping automatic setup."
40+
echo "To manually set up devbox, run: devbox-setup"
41+
exit 0
42+
fi
43+
3244
# Log output for debugging
3345
exec 1> >(tee -a /tmp/devbox-setup.log)
3446
exec 2>&1
@@ -56,5 +68,28 @@ fi
5668
echo "Devbox setup completed successfully"
5769
EOF
5870

59-
# Make the post-setup script executable
6071
chmod +x /usr/local/share/devbox-post-setup.sh
72+
73+
# Always create the manual setup helper script
74+
cat << 'EOF' > /usr/local/bin/devbox-setup
75+
#!/bin/bash
76+
set -e
77+
78+
echo "Running manual Devbox setup..."
79+
80+
# Check if devbox.json exists in workspace
81+
if [ -f "${WORKSPACE_FOLDER:-/workspaces/*}/devbox.json" ]; then
82+
echo "Found devbox.json, running devbox update..."
83+
cd "${WORKSPACE_FOLDER:-/workspaces/*}"
84+
devbox update
85+
86+
# Also set up the shell environment for VS Code processes
87+
devbox shellenv --init-hook >> ~/.profile
88+
echo "Devbox setup completed successfully"
89+
else
90+
echo "No devbox.json found in workspace"
91+
fi
92+
EOF
93+
94+
chmod +x /usr/local/bin/devbox-setup
95+
echo "Devbox installation completed. Manual setup helper available at: devbox-setup"

‎test/_global/scenarios.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"test_all_features": {
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
4+
"features": {
5+
"jetify-devbox": {
6+
"autoUpdate": true
7+
}
8+
}
9+
}
10+
}

‎test/_global/test_all_features.sh‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# ==================================================
3+
# test/_global/test_all_features.sh
4+
# ==================================================
5+
set -e
6+
7+
source dev-container-features-test-lib
8+
9+
# Test that devbox feature is installed
10+
check "devbox available globally" command -v devbox
11+
12+
reportResults

0 commit comments

Comments
 (0)