Skip to content

Commit 52e5f15

Browse files
committed
aztec sandbox devcontainer feature
1 parent 4c2c28a commit 52e5f15

File tree

13 files changed

+370
-2
lines changed

13 files changed

+370
-2
lines changed

.github/workflows/test.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
test-global:
10+
test-noir-barretenberg:
1111
runs-on: ubuntu-latest
1212
continue-on-error: true
1313
steps:
@@ -17,4 +17,16 @@ jobs:
1717
run: npm install -g @devcontainers/cli
1818

1919
- name: "Testing global scenarios"
20-
run: devcontainer features test --global-scenarios-only .
20+
run: devcontainer features test -f noir_barretenberg
21+
22+
test-aztec-sandbox:
23+
runs-on: ubuntu-latest
24+
continue-on-error: true
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: "Install latest devcontainer CLI"
29+
run: npm install -g @devcontainers/cli
30+
31+
- name: "Testing aztec-sandbox feature"
32+
run: devcontainer features test -f aztec-sandbox

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CLAUDE.md

src/aztec-sandbox/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Aztec Sandbox (aztec-sandbox)
2+
3+
Installs and automatically runs the Aztec Sandbox development environment with test accounts pre-configured.
4+
5+
## Example Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/aztecprotocol/devcontainer-feature/aztec-sandbox:1": {}
10+
}
11+
```
12+
13+
## Options
14+
15+
| Options Id | Description | Type | Default Value |
16+
|-----|-----|-----|-----|
17+
| autoStart | Automatically start the sandbox on container creation | boolean | true |
18+
| importTestAccounts | Import test accounts using aztec-wallet | boolean | true |
19+
20+
## What This Feature Does
21+
22+
This feature:
23+
1. Installs the Aztec CLI and related tools
24+
2. Sets up the Aztec Sandbox to run automatically on container startup (if autoStart is true)
25+
3. Configures the environment with HOME set to /workspaces for Aztec compatibility
26+
4. Provides the aztec command in your PATH
27+
28+
## Usage
29+
30+
After installation, the `aztec` command is available in your PATH:
31+
32+
```bash
33+
# If autoStart is false, manually start the sandbox:
34+
aztec start --sandbox
35+
36+
# Check the version
37+
aztec --version
38+
```
39+
40+
## Sandbox Management
41+
42+
When autoStart is enabled (default), the sandbox runs in the background automatically. Logs are written to `/workspaces/.aztec/aztec-sandbox.log`.
43+
44+
To monitor the sandbox logs in real-time:
45+
```bash
46+
tail -f /workspaces/.aztec/aztec-sandbox.log
47+
```
48+
49+
## Test Accounts
50+
51+
When `importTestAccounts` is enabled (default), test accounts are automatically imported and ready to use. These accounts come pre-funded and are ideal for development and testing.
52+
53+
## Customization
54+
55+
To disable auto-start and manage the sandbox manually:
56+
```json
57+
"features": {
58+
"ghcr.io/aztecprotocol/devcontainer-feature/aztec-sandbox:1": {
59+
"autoStart": false
60+
}
61+
}
62+
```
63+
64+
## Dependencies
65+
66+
This feature automatically includes:
67+
- **Docker-in-Docker** (`ghcr.io/devcontainers/features/docker-in-docker:2`): Provides Docker daemon access required by the Aztec Sandbox
68+
69+
## Notes
70+
71+
- Node.js v20+ is required (v22 will be installed automatically if needed)
72+
- Port 8080 is used by the sandbox for the JSON-RPC endpoint
73+
- The Aztec tools are installed using the official installation script from install.aztec.network
74+
- Binaries are installed to `/workspaces/.aztec/bin`
75+
- HOME is set to `/workspaces` to ensure compatibility with Aztec's containerized applications
76+
- The sandbox runs in a Docker container managed by the Docker-in-Docker feature
77+
78+
## GitHub Codespaces Support
79+
80+
This feature includes special support for GitHub Codespaces:
81+
- Automatically configures the PXE_URL environment variable for Codespaces port forwarding
82+
- Ensures port 8080 is properly forwarded for sandbox access
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "Aztec Sandbox",
3+
"id": "aztec-sandbox",
4+
"version": "1.0.0",
5+
"description": "A feature to install and run Aztec Sandbox with test accounts",
6+
"options": {
7+
"autoStart": {
8+
"type": "boolean",
9+
"default": true,
10+
"description": "Automatically start the sandbox on container creation"
11+
},
12+
"importTestAccounts": {
13+
"type": "boolean",
14+
"default": true,
15+
"description": "Import test accounts using aztec-wallet"
16+
}
17+
},
18+
"dependsOn": {
19+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
20+
},
21+
"postCreateCommand": "/usr/local/share/aztec-sandbox-start.sh"
22+
}

src/aztec-sandbox/install.sh

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
echo "Activating feature 'aztec-sandbox'"
5+
6+
# Get options
7+
AUTO_START="${AUTOSTART:-true}"
8+
IMPORT_TEST_ACCOUNTS="${IMPORTTESTACCOUNTS:-true}"
9+
10+
# Install dependencies
11+
echo "Installing system dependencies..."
12+
apt-get update && apt-get install -y \
13+
curl \
14+
jq \
15+
git
16+
17+
# Install Node.js v22 if not present or version is too old
18+
echo "Checking Node.js version..."
19+
if ! command -v node &> /dev/null || [ $(node -v | cut -d'.' -f1 | sed 's/v//') -lt 20 ]; then
20+
echo "Installing Node.js v22..."
21+
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
22+
apt-get install -y nodejs
23+
fi
24+
25+
# Set HOME to /workspaces persistently for all users and shells
26+
echo "Setting HOME to /workspaces persistently..."
27+
28+
# Add to profile for login shells
29+
cat > /etc/profile.d/01_set_home.sh << 'PROFILE_EOF'
30+
# Set HOME to /workspaces for Aztec compatibility
31+
export HOME="/workspaces"
32+
33+
# Add Aztec binaries to PATH
34+
if [ -d "/workspaces/.aztec/bin" ]; then
35+
export PATH="/workspaces/.aztec/bin:$PATH"
36+
fi
37+
PROFILE_EOF
38+
39+
chmod +x /etc/profile.d/01_set_home.sh
40+
41+
# Add to bashrc for non-login shells
42+
cat >> /etc/bash.bashrc << 'BASHRC_EOF'
43+
44+
# Set HOME to /workspaces for Aztec compatibility
45+
export HOME="/workspaces"
46+
47+
# Add Aztec binaries to PATH
48+
if [ -d "/workspaces/.aztec/bin" ]; then
49+
export PATH="/workspaces/.aztec/bin:$PATH"
50+
fi
51+
BASHRC_EOF
52+
53+
# Create Aztec installation script that runs with correct HOME
54+
echo "Creating Aztec installation script..."
55+
cat > /usr/local/share/install-aztec.sh << 'EOF'
56+
#!/usr/bin/env bash
57+
set -e
58+
59+
echo "Installing Aztec tools..."
60+
61+
# Set HOME to /workspaces and change to that directory
62+
export HOME="/workspaces"
63+
cd /workspaces
64+
65+
# Install Aztec using the official installation script (non-interactive mode)
66+
echo "Running Aztec installation script..."
67+
NON_INTERACTIVE=1 bash -c "curl -s https://install.aztec.network | bash -s"
68+
69+
# Create .bashrc if it doesn't exist and set up PXE_URL for Codespaces
70+
if [ ! -f ~/.bashrc ]; then
71+
touch ~/.bashrc
72+
fi
73+
74+
if [ -n "\$CODESPACE_NAME" ] && ! grep -q "PXE_URL" ~/.bashrc; then
75+
echo "export PXE_URL=https://\$CODESPACE_NAME-8080.preview.\$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN" >> ~/.bashrc
76+
fi
77+
78+
echo "Aztec tools installation complete!"
79+
EOF
80+
81+
chmod +x /usr/local/share/install-aztec.sh
82+
83+
# Create startup script for postCreateCommand
84+
echo "Creating startup script..."
85+
cat > /usr/local/share/aztec-sandbox-start.sh << EOF
86+
#!/usr/bin/env bash
87+
set -e
88+
89+
# Set HOME to /workspaces
90+
export HOME="/workspaces"
91+
cd /workspaces
92+
93+
# Wait for Docker to be ready
94+
echo "Waiting for Docker to be ready..."
95+
for i in {1..30}; do
96+
if docker info &> /dev/null; then
97+
echo "Docker is ready!"
98+
break
99+
fi
100+
if [ \$i -eq 30 ]; then
101+
echo "Timeout waiting for Docker to start. Docker may not be available."
102+
echo "You can manually install Aztec later by running: /usr/local/share/install-aztec.sh"
103+
exit 0
104+
fi
105+
echo "Docker not ready yet, waiting... (\$i/30)"
106+
sleep 2
107+
done
108+
109+
# Add Aztec to PATH for this session
110+
export PATH="/workspaces/.aztec/bin:\$PATH"
111+
112+
# Install Aztec tools if not already installed
113+
if ! command -v aztec &> /dev/null; then
114+
echo "Aztec tools not found. Installing..."
115+
/usr/local/share/install-aztec.sh
116+
# Re-export PATH after installation
117+
export PATH="/workspaces/.aztec/bin:\$PATH"
118+
fi
119+
120+
# Start the sandbox automatically if enabled
121+
if [ "${AUTO_START}" = "true" ]; then
122+
echo "Starting Aztec Sandbox in background..."
123+
mkdir -p /workspaces/.aztec
124+
nohup /workspaces/.aztec/bin/aztec start --sandbox > /workspaces/.aztec/aztec-sandbox.log 2>&1 &
125+
echo \$! > /workspaces/.aztec/aztec-sandbox.pid
126+
echo "Aztec Sandbox started in background!"
127+
echo "Logs: /workspaces/.aztec/aztec-sandbox.log"
128+
echo "PID: \$(cat /workspaces/.aztec/aztec-sandbox.pid)"
129+
else
130+
echo "Aztec setup complete!"
131+
echo "The 'aztec' command is now available in your PATH."
132+
echo "Run 'aztec start --sandbox' to start the sandbox manually."
133+
fi
134+
EOF
135+
136+
chmod +x /usr/local/share/aztec-sandbox-start.sh
137+
138+
echo "Aztec Sandbox feature installation complete!"
139+
echo "Aztec tools will be installed when the container starts."

test/aztec-sandbox/default.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
# This test file will be executed against an auto-generated devcontainer.json that
4+
# includes the 'aztec-sandbox' Feature with no options.
5+
#
6+
# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md
7+
#
8+
# Eg:
9+
# {
10+
# "image": "<..some-base-image...>",
11+
# "features": {
12+
# "aztec-sandbox": {}
13+
# },
14+
# "remoteUser": "root"
15+
# }
16+
#
17+
# Thus, the value of all options will fall back to the default value in the
18+
# Feature's 'devcontainer-feature.json'.
19+
20+
set -e
21+
22+
# Optional: Import test library bundled with the devcontainer CLI
23+
source dev-container-features-test-lib
24+
25+
# Feature-specific tests
26+
# The 'check' command comes from the dev-container-features-test-lib.
27+
28+
# Check that installation and startup scripts exist
29+
check "install-script-exists" bash -c "test -x /usr/local/share/install-aztec.sh"
30+
check "startup-script-exists" bash -c "test -x /usr/local/share/aztec-sandbox-start.sh"
31+
32+
# Check that HOME is set to /workspaces
33+
check "home-is-workspaces" bash -c "grep -q 'export HOME=\"/workspaces\"' /etc/profile.d/01_set_home.sh"
34+
35+
# Check that PATH includes aztec binaries
36+
check "path-includes-aztec" bash -c "grep -q '/workspaces/.aztec/bin' /etc/profile.d/01_set_home.sh"
37+
38+
# Check that Node.js is installed
39+
check "node-installed" bash -c "command -v node"
40+
41+
# Report results
42+
# If any of the checks above exited with a non-zero exit code, the test will fail.
43+
reportResults

test/aztec-sandbox/scenarios.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"default": {
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
4+
"features": {
5+
"aztec-sandbox": {}
6+
}
7+
},
8+
"with-options": {
9+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
10+
"features": {
11+
"aztec-sandbox": {
12+
"autoStart": false,
13+
"importTestAccounts": false
14+
}
15+
}
16+
}
17+
}

test/aztec-sandbox/test.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# This is the primary test file that gets executed by default when running:
4+
# devcontainer features test -f aztec-sandbox
5+
#
6+
# It should test the basic functionality of the feature with default options.
7+
8+
set -e
9+
10+
# Import test library bundled with the devcontainer CLI
11+
source dev-container-features-test-lib
12+
13+
# Feature-specific tests
14+
# Check that installation and startup scripts exist
15+
check "install-script-exists" bash -c "test -x /usr/local/share/install-aztec.sh"
16+
check "startup-script-exists" bash -c "test -x /usr/local/share/aztec-sandbox-start.sh"
17+
18+
# Check that HOME is set to /workspaces
19+
check "home-is-workspaces" bash -c "grep -q 'export HOME=\"/workspaces\"' /etc/profile.d/01_set_home.sh"
20+
21+
# Check that PATH includes aztec binaries
22+
check "path-includes-aztec" bash -c "grep -q '/workspaces/.aztec/bin' /etc/profile.d/01_set_home.sh"
23+
24+
# Check that Node.js is installed
25+
check "node-installed" bash -c "command -v node"
26+
27+
# Report results
28+
reportResults

test/aztec-sandbox/with-options.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# This test file will be executed against the 'with-options' scenario in scenarios.json
4+
5+
set -e
6+
7+
# Import test library
8+
source dev-container-features-test-lib
9+
10+
# Feature-specific tests
11+
# Check that installation and startup scripts exist
12+
check "install-script-exists" bash -c "test -x /usr/local/share/install-aztec.sh"
13+
check "startup-script-exists" bash -c "test -x /usr/local/share/aztec-sandbox-start.sh"
14+
15+
# Check that HOME is set to /workspaces
16+
check "home-is-workspaces" bash -c "grep -q 'export HOME=\"/workspaces\"' /etc/profile.d/01_set_home.sh"
17+
18+
# Check that PATH includes aztec binaries
19+
check "path-includes-aztec" bash -c "grep -q '/workspaces/.aztec/bin' /etc/profile.d/01_set_home.sh"
20+
21+
# Since autoStart is false in this scenario, check that sandbox is NOT running
22+
# We can't check this directly as postCreateCommand hasn't run yet in tests
23+
24+
reportResults

0 commit comments

Comments
 (0)