Skip to content

Commit 03ffaa9

Browse files
authored
Merge pull request #1173 from graphprotocol/dev-container
Dev container fixes and updates
2 parents ea650f2 + 84d3a09 commit 03ffaa9

File tree

7 files changed

+178
-189
lines changed

7 files changed

+178
-189
lines changed

.devcontainer/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RUN apt update && apt install -y \
2222

2323
# Install Node.js
2424
RUN npm install -g n && n 20.12.0
25-
25+
2626
# Install Solidity compiler using pipx (isolated environment)
2727
RUN pipx install solc-select && \
2828
pipx ensurepath && \
@@ -40,10 +40,10 @@ RUN pipx install solc-select && \
4040
cp -r /root/.solc-select/* /home/vscode/.solc-select/ && \
4141
chown -R vscode:vscode /home/vscode/.solc-select
4242

43-
# Install Hardhat and related tools as root
44-
RUN npm install -g [email protected] @nomicfoundation/[email protected] [email protected] && \
45-
ln -sf /usr/local/lib/node_modules/hardhat/internal/cli/cli.js /usr/local/bin/hardhat && \
46-
chmod +x /usr/local/bin/hardhat
43+
RUN npm install -g [email protected]
44+
45+
# Install cloc for code analysis
46+
RUN npm install -g cloc
4747

4848
# Install Foundry for Anvil (as root for global installation)
4949
RUN curl -L https://foundry.paradigm.xyz | bash && \

.devcontainer/README.md

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,47 @@ The dev container provides a consistent development environment with caching to
1818

1919
## Cache System
2020

21-
The container uses a simple caching system:
21+
The container uses a conservative caching approach to prevent cache corruption issues:
2222

23-
1. **Host Cache Directories**: Created on the host and mounted into the container
24-
- `/cache/vscode-cache``/home/vscode/.cache`
25-
- `/cache/vscode-config``/home/vscode/.config`
26-
- `/cache/vscode-data``/home/vscode/.local/share`
27-
- `/cache/vscode-bin``/home/vscode/.local/bin`
28-
- `/cache/*` → Tool-specific cache directories
23+
1. **Local Cache Directories**: Each container instance maintains its own cache directories
2924

30-
2. **Package Cache Symlinks**: Created inside the container by project-setup.sh
31-
- Each package's cache directory is symlinked to a subdirectory in `/cache/hardhat`
25+
- `vscode-cache``/home/vscode/.cache` (VS Code cache)
26+
- `vscode-config``/home/vscode/.config` (VS Code configuration)
27+
- `vscode-data``/home/vscode/.local/share` (VS Code data)
28+
- `vscode-bin``/home/vscode/.local/bin` (User binaries)
3229

33-
## Setup Instructions
34-
35-
### 1. Host Setup (One-time)
36-
37-
Before starting the dev container for the first time, run the included host setup script to create the necessary cache directories on the host:
38-
39-
```bash
40-
sudo /git/graphprotocol/contracts/.devcontainer/host-setup.sh
41-
```
30+
2. **Safe Caches Only**: Only caches that won't cause cross-branch issues are configured
4231

43-
This script creates all required cache directories on the host, including:
32+
- GitHub CLI: `/home/vscode/.cache/github`
33+
- Python packages: `/home/vscode/.cache/pip`
4434

45-
- Standard VS Code directories (for .cache, .config, etc.)
46-
- Tool-specific cache directories (for npm, yarn, cargo, etc.)
35+
3. **Intentionally Not Cached**: These tools use their default cache locations to avoid contamination
36+
- NPM, Yarn (different dependency versions per branch)
37+
- Foundry, Solidity (different compilation artifacts per branch)
38+
- Hardhat (different build artifacts per branch)
4739

48-
The script is idempotent and can be run multiple times without issues.
40+
## Setup Instructions
4941

50-
### 2. Start the Dev Container
42+
### Start the Dev Container
5143

52-
After creating the cache directories, you can start the dev container:
44+
To start the dev container:
5345

5446
1. Open VS Code
5547
2. Use the "Remote-Containers: Open Folder in Container" command
56-
3. Select the repository directory
48+
3. Select the repository directory (for example `/git/graphprotocol/contracts`)
5749

5850
When the container starts, the `project-setup.sh` script will automatically run and:
5951

60-
- Create package-specific cache directories
61-
- Set up symlinks for package cache directories
6252
- Install project dependencies using yarn
6353
- Configure Git to use SSH signing with your forwarded SSH key
64-
- Source shell customizations if available in PATH (currently depends on base image configuration)
54+
- Source shell customizations if available in PATH
6555

6656
## Environment Variables
6757

6858
Environment variables are defined in two places:
6959

7060
1. **docker-compose.yml**: Contains most of the environment variables for tools and caching
71-
2. **Environment File**: Personal settings are stored in `/opt/configs/graphprotocol/contracts.env`
61+
2. **Environment File**: Personal settings are stored in `/opt/configs/graphprotocol/contracts.env` on the host
7262

7363
### Git Configuration
7464

@@ -84,11 +74,13 @@ These environment variables are needed for Git commit signing to work properly.
8474

8575
## Troubleshooting
8676

87-
If you encounter permission denied errors when trying to access directories, make sure you've run the `host-setup.sh` script on the host before starting the container:
77+
### Cache Issues
8878

89-
```bash
90-
sudo .devcontainer/host-setup.sh
91-
```
79+
If you encounter build or compilation issues that seem related to cached artifacts:
80+
81+
1. **Rebuild the container**: This will start with fresh local caches
82+
2. **Clean project caches**: Run `yarn clean` to clear project-specific build artifacts
83+
3. **Clear node modules**: Delete `node_modules` and run `yarn install` again
9284

9385
### Git SSH Signing Issues
9486

.devcontainer/devcontainer.json

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
11
{
2-
"name": "graph contracts",
3-
"dockerComposeFile": [
4-
"docker-compose.yml"
5-
],
6-
"service": "dev-graph-contracts",
7-
"features": {
8-
"ghcr.io/devcontainers/features/git:1": {
9-
"configureGitHubCLI": true,
10-
"gitCredentialHelper": "cache"
11-
},
12-
"ghcr.io/devcontainers/features/github-cli:1": {},
13-
"ghcr.io/devcontainers/features/common-utils:2.5.3": {},
14-
"ghcr.io/devcontainers/features/node:1": {
15-
"version": "20"
16-
},
17-
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
18-
},
19-
"postCreateCommand": ".devcontainer/project-setup.sh",
20-
"remoteUser": "vscode",
21-
"workspaceFolder": "${localWorkspaceFolder}",
22-
"customizations": {
23-
"vscode": {
24-
"extensions": [
25-
"rust-lang.rust-analyzer",
26-
"tamasfe.even-better-toml",
27-
"usernamehw.errorlens",
28-
"yzhang.markdown-all-in-one",
29-
"DavidAnson.vscode-markdownlint",
30-
"shd101wyy.markdown-preview-enhanced",
31-
"bierner.markdown-preview-github-styles",
32-
"Gruntfuggly.todo-tree",
33-
"ms-azuretools.vscode-docker",
34-
"donjayamanne.githistory",
35-
"eamodio.gitlens",
36-
"fill-labs.dependi",
37-
"streetsidesoftware.code-spell-checker",
38-
"Augment.vscode-augment",
39-
"NomicFoundation.hardhat-solidity",
40-
"foundry-rs.foundry-vscode"
41-
]
42-
}
43-
}
2+
"name": "graph contracts",
3+
"dockerComposeFile": ["docker-compose.yml"],
4+
"service": "dev-graph-contracts",
5+
"features": {
6+
"ghcr.io/devcontainers/features/git:1": {
7+
"configureGitHubCLI": true,
8+
"gitCredentialHelper": "cache"
9+
},
10+
"ghcr.io/devcontainers/features/github-cli:1": {},
11+
"ghcr.io/devcontainers/features/common-utils:2.5.3": {},
12+
"ghcr.io/devcontainers/features/node:1": {
13+
"version": "20"
14+
},
15+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
16+
},
17+
"postCreateCommand": ".devcontainer/project-setup.sh",
18+
"remoteUser": "vscode",
19+
"workspaceFolder": "${localWorkspaceFolder}",
20+
"customizations": {
21+
"vscode": {
22+
"extensions": [
23+
"rust-lang.rust-analyzer",
24+
"tamasfe.even-better-toml",
25+
"usernamehw.errorlens",
26+
"yzhang.markdown-all-in-one",
27+
"DavidAnson.vscode-markdownlint",
28+
"shd101wyy.markdown-preview-enhanced",
29+
"bierner.markdown-preview-github-styles",
30+
"Gruntfuggly.todo-tree",
31+
"ms-azuretools.vscode-docker",
32+
"donjayamanne.githistory",
33+
"eamodio.gitlens",
34+
"fill-labs.dependi",
35+
"streetsidesoftware.code-spell-checker",
36+
"Augment.vscode-augment",
37+
"NomicFoundation.hardhat-solidity",
38+
"foundry-rs.foundry-vscode"
39+
]
40+
}
41+
}
4442
}

.devcontainer/docker-compose.yml

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,43 @@
11
services:
22
dev-graph-contracts:
3-
container_name: dev-graph-contracts
43
build:
54
context: .
65
dockerfile: Dockerfile
7-
x-bake:
8-
cache-from:
9-
- type=local,src=/cache/docker
10-
cache-to:
11-
- type=local,dest=/cache/docker,mode=max
126
env_file:
137
- /opt/configs/graphprotocol/contracts.env
148
environment:
15-
# Cache directories
16-
- FOUNDRY_CACHE_DIR=/cache/foundry
17-
- SOLC_CACHE=/cache/solidity
9+
# Essential for large builds
10+
- NODE_OPTIONS=--max-old-space-size=4096
11+
12+
# Clean development environment
13+
- PYTHONDONTWRITEBYTECODE=1
1814

19-
# GitHub
20-
- GH_CONFIG_DIR=/cache/github
15+
# Disable interactive prompts
16+
- COREPACK_ENABLE_DOWNLOAD_PROMPT=0
2117

22-
# XDG standard directories
18+
# Standard user directories
2319
- XDG_CACHE_HOME=/home/vscode/.cache
2420
- XDG_CONFIG_HOME=/home/vscode/.config
2521
- XDG_DATA_HOME=/home/vscode/.local/share
2622

27-
# Tool-specific settings
28-
- HARDHAT_CACHE_DIR=/cache/hardhat
29-
- HARDHAT_ANALYTICS=true
30-
- HARDHAT_NO_ANALYTICS_PROMPT=true
31-
32-
# Node.js settings
33-
- NPM_CONFIG_CACHE=/cache/npm
34-
- YARN_CACHE_FOLDER=/cache/yarn
35-
- NODE_OPTIONS=--max-old-space-size=4096
23+
# Safe caches (won't cause cross-branch issues)
24+
- GH_CONFIG_DIR=/home/vscode/.cache/github
25+
- PIP_CACHE_DIR=/home/vscode/.cache/pip
3626

37-
# Python settings
38-
- PIP_CACHE_DIR=/cache/pip
39-
- PYTHONPYCACHEPREFIX=/cache/pycache
40-
- PYTHONDONTWRITEBYTECODE=1
41-
networks:
42-
- shared
27+
# Note: NPM, Yarn, Foundry, and Solidity caches are intentionally not set
28+
# to avoid cross-branch contamination. Tools will use their default locations.
4329
volumes:
44-
# Mount cache directory
45-
- /cache:/cache
46-
47-
# System-specific mounts that need specific locations
48-
- /cache/apt:/var/cache/apt
49-
- /cache/apt-lib:/var/lib/apt
50-
5130
# Git repo root
5231
- /git:/git
5332

54-
# Local cache directories for XDG standards
55-
- /cache/vscode-cache:/home/vscode/.cache
56-
- /cache/vscode-config:/home/vscode/.config
57-
- /cache/vscode-data:/home/vscode/.local/share
58-
- /cache/vscode-bin:/home/vscode/.local/bin
59-
60-
networks:
61-
shared:
62-
external: true
33+
# Local directories for user data (keep local to container)
34+
- vscode-cache:/home/vscode/.cache
35+
- vscode-config:/home/vscode/.config
36+
- vscode-data:/home/vscode/.local/share
37+
- vscode-bin:/home/vscode/.local/bin
38+
39+
volumes:
40+
vscode-cache:
41+
vscode-config:
42+
vscode-data:
43+
vscode-bin:

.devcontainer/project-setup.sh

Lines changed: 7 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,73 +11,15 @@ REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
1111
echo "Script directory: $SCRIPT_DIR"
1212
echo "Repository root: $REPO_ROOT"
1313

14-
# Check if cache directories exist
15-
echo "Checking if cache directories exist..."
14+
# Set up local user directories with proper permissions
15+
echo "Setting up local user directories..."
1616

17-
# Required cache directories
18-
REQUIRED_DIRS=(
19-
"/cache/hardhat"
20-
"/cache/npm"
21-
"/cache/yarn"
22-
)
17+
# Ensure all user directories exist and have proper ownership
18+
sudo mkdir -p /home/vscode/.cache /home/vscode/.config /home/vscode/.local/share /home/vscode/.local/bin
19+
sudo chown -R vscode:vscode /home/vscode/.cache /home/vscode/.config /home/vscode/.local
20+
sudo chmod -R 755 /home/vscode/.cache /home/vscode/.config /home/vscode/.local
2321

24-
# Check if required directories exist
25-
missing_dirs=()
26-
for dir in "${REQUIRED_DIRS[@]}"; do
27-
if [ ! -d "$dir" ]; then
28-
missing_dirs+=("$dir")
29-
fi
30-
done
31-
32-
# If any required directories are missing, show a warning
33-
# Note: With set -u, we need to ensure missing_dirs is always initialized
34-
if [ "${#missing_dirs[@]}" -gt 0 ]; then
35-
echo "WARNING: The following required cache directories are missing:"
36-
for dir in "${missing_dirs[@]}"; do
37-
echo " - $dir"
38-
done
39-
echo "Please run the host setup script before starting the container:"
40-
echo " sudo .devcontainer/host-setup.sh"
41-
echo "Continuing anyway, but you may encounter issues..."
42-
fi
43-
44-
# Set up cache symlinks
45-
echo "Setting up cache symlinks..."
46-
47-
# Function to create symlinks for package cache directories
48-
setup_cache_symlink() {
49-
# With set -u, we need to ensure all parameters are provided
50-
if [ "$#" -ne 1 ]; then
51-
echo "Error: setup_cache_symlink requires exactly 1 argument (package_name)"
52-
return 1
53-
fi
54-
55-
local package_name=$1
56-
local cache_path="$REPO_ROOT/packages/${package_name}/cache"
57-
local cache_dest="/cache/hardhat/${package_name}"
58-
59-
# Skip if the package directory doesn't exist
60-
if [ ! -d "$REPO_ROOT/packages/${package_name}" ]; then
61-
return
62-
fi
63-
64-
# Create the package-specific cache directory if it doesn't exist
65-
if [ ! -d "$cache_dest" ]; then
66-
echo "Creating package-specific cache directory: $cache_dest"
67-
mkdir -p "$cache_dest"
68-
chmod -R 777 "$cache_dest"
69-
fi
70-
71-
# Create the symlink (will replace existing symlink if it exists)
72-
ln -sf "$cache_dest" "$cache_path"
73-
echo "Created symlink for ${package_name} cache"
74-
}
75-
76-
# Set up cache symlinks for main packages
77-
setup_cache_symlink "contracts"
78-
setup_cache_symlink "horizon"
79-
setup_cache_symlink "subgraph-service"
80-
setup_cache_symlink "data-edge"
22+
echo "User directories set up with proper permissions"
8123

8224
# Install project dependencies
8325
echo "Installing project dependencies..."
@@ -131,7 +73,6 @@ else
13173
fi
13274

13375
# Set up Git SSH signing
134-
echo "Setting up Git SSH signing..."
13576
if [ -f "$SCRIPT_DIR/setup-git-signing.sh" ]; then
13677
"$SCRIPT_DIR/setup-git-signing.sh"
13778
else

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ addresses-fork.json
5252

5353
# Forge artifacts
5454
cache_forge
55+
forge-artifacts/
5556

5657
# Graph client
5758
.graphclient

0 commit comments

Comments
 (0)