Skip to content

Commit d35b6ba

Browse files
committed
fix(container): reducing amount of caching to avoid cross environment issues
1 parent ebebc9f commit d35b6ba

File tree

3 files changed

+50
-134
lines changed

3 files changed

+50
-134
lines changed

.devcontainer/README.md

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,37 @@ 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
23+
1. **Local Cache Directories**: Each container instance maintains its own cache directories
2424

25-
- `/cache/vscode-cache``/home/vscode/.cache`
26-
- `/cache/vscode-config``/home/vscode/.config`
27-
- `/cache/vscode-data``/home/vscode/.local/share`
28-
- `/cache/vscode-bin``/home/vscode/.local/bin`
29-
- `/cache/*` → Tool-specific cache directories
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)
3029

31-
2. **Package Cache Symlinks**: Created inside the container by project-setup.sh
32-
- Each package's cache directory is symlinked to a subdirectory in `/cache/hardhat`
30+
2. **Safe Caches Only**: Only caches that won't cause cross-branch issues are configured
3331

34-
## Setup Instructions
35-
36-
### 1. Host Setup (One-time)
37-
38-
Before starting the dev container for the first time, run the included host setup script to create the necessary cache directories on the host:
39-
40-
```bash
41-
sudo /git/graphprotocol/contracts/.devcontainer/host-setup.sh
42-
```
32+
- GitHub CLI: `/home/vscode/.cache/github`
33+
- Python packages: `/home/vscode/.cache/pip`
4334

44-
This script creates all required cache directories on the host, including:
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)
4539

46-
- Standard VS Code directories (for .cache, .config, etc.)
47-
- Tool-specific cache directories (for npm, yarn, cargo, etc.)
48-
49-
The script is idempotent and can be run multiple times without issues.
50-
51-
The container was designed to be used for development with contracts repo at `/git/graphprotocol/contracts` and with `/git` mounted from the host by `docker-compose.yml`.
40+
## Setup Instructions
5241

53-
### 2. Start the Dev Container
42+
### Start the Dev Container
5443

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

5746
1. Open VS Code
5847
2. Use the "Remote-Containers: Open Folder in Container" command
5948
3. Select the repository directory (for example `/git/graphprotocol/contracts`)
6049

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

63-
- Create package-specific cache directories
64-
- Set up symlinks for package cache directories
6552
- Install project dependencies using yarn
6653
- Configure Git to use SSH signing with your forwarded SSH key
6754
- Source shell customizations if available in PATH
@@ -87,11 +74,13 @@ These environment variables are needed for Git commit signing to work properly.
8774

8875
## Troubleshooting
8976

90-
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
9178

92-
```bash
93-
sudo .devcontainer/host-setup.sh
94-
```
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
9584

9685
### Git SSH Signing Issues
9786

.devcontainer/docker-compose.yml

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,38 @@ services:
33
build:
44
context: .
55
dockerfile: Dockerfile
6-
x-bake:
7-
cache-from:
8-
- type=local,src=/cache/docker
9-
cache-to:
10-
- type=local,dest=/cache/docker,mode=max
116
env_file:
127
- /opt/configs/graphprotocol/contracts.env
138
environment:
14-
# Cache directories
15-
- FOUNDRY_CACHE_DIR=/cache/foundry
16-
- SOLC_CACHE=/cache/solidity
9+
# Essential for large builds
10+
- NODE_OPTIONS=--max-old-space-size=4096
1711

18-
# GitHub
19-
- GH_CONFIG_DIR=/cache/github
12+
# Clean development environment
13+
- PYTHONDONTWRITEBYTECODE=1
2014

21-
# XDG standard directories
15+
# Standard user directories
2216
- XDG_CACHE_HOME=/home/vscode/.cache
2317
- XDG_CONFIG_HOME=/home/vscode/.config
2418
- XDG_DATA_HOME=/home/vscode/.local/share
2519

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

36-
# Python settings
37-
- PIP_CACHE_DIR=/cache/pip
38-
- PYTHONPYCACHEPREFIX=/cache/pycache
39-
- PYTHONDONTWRITEBYTECODE=1
24+
# Note: NPM, Yarn, Foundry, and Solidity caches are intentionally not set
25+
# to avoid cross-branch contamination. Tools will use their default locations.
4026
volumes:
41-
# Mount cache directory
42-
- /cache:/cache
43-
44-
# System-specific mounts that need specific locations
45-
- /cache/apt:/var/cache/apt
46-
- /cache/apt-lib:/var/lib/apt
47-
4827
# Git repo root
4928
- /git:/git
5029

51-
# Local cache directories for XDG standards
52-
- /cache/vscode-cache:/home/vscode/.cache
53-
- /cache/vscode-config:/home/vscode/.config
54-
- /cache/vscode-data:/home/vscode/.local/share
55-
- /cache/vscode-bin:/home/vscode/.local/bin
30+
# Local directories for user data (keep local to container)
31+
- vscode-cache:/home/vscode/.cache
32+
- vscode-config:/home/vscode/.config
33+
- vscode-data:/home/vscode/.local/share
34+
- vscode-bin:/home/vscode/.local/bin
35+
36+
volumes:
37+
vscode-cache:
38+
vscode-config:
39+
vscode-data:
40+
vscode-bin:

.devcontainer/project-setup.sh

Lines changed: 7 additions & 65 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..."

0 commit comments

Comments
 (0)