Skip to content

Commit ea650f2

Browse files
authored
Merge pull request #1168 from graphprotocol/husky-update
fix: fix and upgrade Husky pre-commit, and add dev container config
2 parents 22c47ec + bf7e584 commit ea650f2

13 files changed

+607
-23
lines changed

.devcontainer/Dockerfile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
FROM mcr.microsoft.com/devcontainers/base:debian
2+
3+
# Set non-interactive frontend for apt
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
# Switch to root for installing packages
7+
USER root
8+
9+
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
10+
11+
# Install additional dependencies
12+
RUN apt update && apt install -y \
13+
build-essential \
14+
nodejs \
15+
jq \
16+
python3 \
17+
python3-pip \
18+
python3-venv \
19+
pipx \
20+
&& apt clean \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
# Install Node.js
24+
RUN npm install -g n && n 20.12.0
25+
26+
# Install Solidity compiler using pipx (isolated environment)
27+
RUN pipx install solc-select && \
28+
pipx ensurepath && \
29+
/root/.local/bin/solc-select install 0.8.27 && \
30+
/root/.local/bin/solc-select use 0.8.27 && \
31+
# Copy binaries to /usr/local/bin with proper permissions (not symlinks)
32+
cp /root/.local/bin/solc /usr/local/bin/solc && \
33+
cp /root/.local/bin/solc-select /usr/local/bin/solc-select && \
34+
chmod 755 /usr/local/bin/solc && \
35+
chmod 755 /usr/local/bin/solc-select && \
36+
# Make sure pipx directory is accessible
37+
chmod -R a+rx /root/.local/pipx && \
38+
# Set up for vscode user
39+
mkdir -p /home/vscode/.solc-select && \
40+
cp -r /root/.solc-select/* /home/vscode/.solc-select/ && \
41+
chown -R vscode:vscode /home/vscode/.solc-select
42+
43+
# Install Hardhat and related tools as root
44+
RUN npm install -g hardhat@2.22.16 @nomicfoundation/hardhat-ethers@3.0.8 ethers@6.13.4 && \
45+
ln -sf /usr/local/lib/node_modules/hardhat/internal/cli/cli.js /usr/local/bin/hardhat && \
46+
chmod +x /usr/local/bin/hardhat
47+
48+
# Install Foundry for Anvil (as root for global installation)
49+
RUN curl -L https://foundry.paradigm.xyz | bash && \
50+
/root/.foundry/bin/foundryup && \
51+
# Copy binaries to /usr/local/bin with proper permissions
52+
cp /root/.foundry/bin/anvil /usr/local/bin/anvil && \
53+
cp /root/.foundry/bin/cast /usr/local/bin/cast && \
54+
cp /root/.foundry/bin/forge /usr/local/bin/forge && \
55+
cp /root/.foundry/bin/chisel /usr/local/bin/chisel && \
56+
# Ensure proper permissions
57+
chmod 755 /usr/local/bin/anvil && \
58+
chmod 755 /usr/local/bin/cast && \
59+
chmod 755 /usr/local/bin/forge && \
60+
chmod 755 /usr/local/bin/chisel
61+
62+
# Set up yarn
63+
RUN corepack enable && \
64+
corepack prepare yarn@4.0.2 --activate
65+
66+
# Ensure all users have access to the tools
67+
RUN chmod 755 /usr/local/bin/* && \
68+
# Create a directory for vscode user's binaries
69+
mkdir -p /home/vscode/.local/bin && \
70+
chown -R vscode:vscode /home/vscode/.local/bin
71+
72+
# Switch back to vscode user
73+
USER vscode
74+
75+
# Set environment variables
76+
ENV PATH="/usr/local/bin:/home/vscode/.foundry/bin:/home/vscode/.local/bin:/root/.local/bin:$PATH"
77+
78+
# Create .bashrc additions for PATH
79+
RUN echo 'export PATH="/usr/local/bin:$HOME/.local/bin:$PATH"' >> $HOME/.bashrc
80+
81+
# Set the default command
82+
CMD ["sleep", "infinity"]

.devcontainer/README.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Graph Protocol Contracts Dev Container
2+
3+
This directory contains configuration files for the Graph Protocol contracts development container.
4+
5+
> **Note:** This dev container setup is a work in progress and will not be fully portable.
6+
7+
## Overview
8+
9+
The dev container provides a consistent development environment with caching to improve performance.
10+
11+
### Key Components
12+
13+
1. **Docker Compose Configuration**: Defines the container setup, volume mounts, and environment variables
14+
2. **Dockerfile**: Specifies the container image and installed tools
15+
3. **project-setup.sh**: Configures the environment after container creation
16+
4. **host-setup.sh**: Sets up the host environment before starting the container
17+
5. **setup-git-signing.sh**: Automatically configures Git to use SSH signing with forwarded SSH keys
18+
19+
## Cache System
20+
21+
The container uses a simple caching system:
22+
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
29+
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`
32+
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+
```
42+
43+
This script creates all required cache directories on the host, including:
44+
45+
- Standard VS Code directories (for .cache, .config, etc.)
46+
- Tool-specific cache directories (for npm, yarn, cargo, etc.)
47+
48+
The script is idempotent and can be run multiple times without issues.
49+
50+
### 2. Start the Dev Container
51+
52+
After creating the cache directories, you can start the dev container:
53+
54+
1. Open VS Code
55+
2. Use the "Remote-Containers: Open Folder in Container" command
56+
3. Select the repository directory
57+
58+
When the container starts, the `project-setup.sh` script will automatically run and:
59+
60+
- Create package-specific cache directories
61+
- Set up symlinks for package cache directories
62+
- Install project dependencies using yarn
63+
- 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)
65+
66+
## Environment Variables
67+
68+
Environment variables are defined in two places:
69+
70+
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`
72+
73+
### Git Configuration
74+
75+
To enable Git commit signing, add the following settings to your environment file:
76+
77+
```env
78+
# Git settings for commit signing
79+
GIT_USER_NAME=Your Name
80+
GIT_USER_EMAIL=your.email@example.com
81+
```
82+
83+
These environment variables are needed for Git commit signing to work properly. If they are not defined, Git commit signing will not be configured, but the container will still work for other purposes.
84+
85+
## Troubleshooting
86+
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:
88+
89+
```bash
90+
sudo .devcontainer/host-setup.sh
91+
```
92+
93+
### Git SSH Signing Issues
94+
95+
If you encounter issues with Git SSH signing:
96+
97+
1. **SSH Agent Forwarding**: Make sure SSH agent forwarding is properly set up in your VS Code settings
98+
2. **GitHub Configuration**: Ensure your SSH key is added to GitHub as a signing key in your account settings
99+
3. **Manual Setup**: If automatic setup fails, you can manually configure SSH signing:
100+
101+
```bash
102+
# Check available SSH keys
103+
ssh-add -l
104+
105+
# Configure Git to use SSH signing
106+
git config --global gpg.format ssh
107+
git config --global user.signingkey "key::ssh-ed25519 YOUR_KEY_CONTENT"
108+
git config --global gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers
109+
git config --global commit.gpgsign true
110+
111+
# Create allowed signers file
112+
echo "your.email@example.com ssh-ed25519 YOUR_KEY_CONTENT" > ~/.ssh/allowed_signers
113+
```
114+
115+
For other issues, check the `project-setup.sh` and `setup-git-signing.sh` scripts for any errors.

.devcontainer/devcontainer.json

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

.devcontainer/docker-compose.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
services:
2+
dev-graph-contracts:
3+
container_name: dev-graph-contracts
4+
build:
5+
context: .
6+
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
12+
env_file:
13+
- /opt/configs/graphprotocol/contracts.env
14+
environment:
15+
# Cache directories
16+
- FOUNDRY_CACHE_DIR=/cache/foundry
17+
- SOLC_CACHE=/cache/solidity
18+
19+
# GitHub
20+
- GH_CONFIG_DIR=/cache/github
21+
22+
# XDG standard directories
23+
- XDG_CACHE_HOME=/home/vscode/.cache
24+
- XDG_CONFIG_HOME=/home/vscode/.config
25+
- XDG_DATA_HOME=/home/vscode/.local/share
26+
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
36+
37+
# Python settings
38+
- PIP_CACHE_DIR=/cache/pip
39+
- PYTHONPYCACHEPREFIX=/cache/pycache
40+
- PYTHONDONTWRITEBYTECODE=1
41+
networks:
42+
- shared
43+
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+
51+
# Git repo root
52+
- /git:/git
53+
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

.devcontainer/host-setup.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
# Host setup script for Graph Protocol Contracts dev container
3+
# Run this script on the host before starting the dev container
4+
# Usage: sudo .devcontainer/host-setup.sh
5+
6+
set -euo pipefail
7+
8+
echo "Setting up host environment for Graph Protocol Contracts dev container..."
9+
10+
# Check if running as root
11+
if [ "$(id -u)" -ne 0 ]; then
12+
echo "Error: This script must be run as root (sudo)" >&2
13+
exit 1
14+
fi
15+
16+
CACHE_DIRS=(
17+
"/cache/vscode-cache"
18+
"/cache/vscode-config"
19+
"/cache/vscode-data"
20+
"/cache/vscode-bin"
21+
"/cache/hardhat"
22+
"/cache/npm"
23+
"/cache/yarn"
24+
"/cache/pip"
25+
"/cache/pycache"
26+
"/cache/solidity"
27+
"/cache/foundry"
28+
"/cache/github"
29+
"/cache/apt"
30+
"/cache/apt-lib"
31+
)
32+
33+
echo "Creating cache directories..."
34+
for dir in "${CACHE_DIRS[@]}"; do
35+
if [ ! -d "$dir" ]; then
36+
echo "Creating $dir"
37+
mkdir -p "$dir"
38+
chmod 777 "$dir"
39+
else
40+
echo "$dir already exists"
41+
fi
42+
done
43+
44+
# Note: Package-specific directories will be created by the project-setup.sh script
45+
# inside the container, as they are tied to the project structure
46+
47+
echo "Host setup completed successfully!"
48+
echo "You can now start or rebuild your dev container."

0 commit comments

Comments
 (0)