Skip to content

Dev container fixes and updates #1173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
10 changes: 5 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN apt update && apt install -y \

# Install Node.js
RUN npm install -g n && n 20.12.0

# Install Solidity compiler using pipx (isolated environment)
RUN pipx install solc-select && \
pipx ensurepath && \
Expand All @@ -40,10 +40,10 @@ RUN pipx install solc-select && \
cp -r /root/.solc-select/* /home/vscode/.solc-select/ && \
chown -R vscode:vscode /home/vscode/.solc-select

# Install Hardhat and related tools as root
RUN npm install -g hardhat@2.22.16 @nomicfoundation/hardhat-ethers@3.0.8 ethers@6.13.4 && \
ln -sf /usr/local/lib/node_modules/hardhat/internal/cli/cli.js /usr/local/bin/hardhat && \
chmod +x /usr/local/bin/hardhat
RUN npm install -g ethers@6.13.4

# Install cloc for code analysis
RUN npm install -g cloc

# Install Foundry for Anvil (as root for global installation)
RUN curl -L https://foundry.paradigm.xyz | bash && \
Expand Down
8 changes: 5 additions & 3 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,30 @@ This script creates all required cache directories on the host, including:

The script is idempotent and can be run multiple times without issues.

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`.

### 2. Start the Dev Container

After creating the cache directories, you can start the dev container:

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

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

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

## Environment Variables

Environment variables are defined in two places:

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

### Git Configuration

Expand Down
6 changes: 0 additions & 6 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ services:
- PIP_CACHE_DIR=/cache/pip
- PYTHONPYCACHEPREFIX=/cache/pycache
- PYTHONDONTWRITEBYTECODE=1
networks:
- shared
volumes:
# Mount cache directory
- /cache:/cache
Expand All @@ -56,7 +54,3 @@ services:
- /cache/vscode-config:/home/vscode/.config
- /cache/vscode-data:/home/vscode/.local/share
- /cache/vscode-bin:/home/vscode/.local/bin

networks:
shared:
external: true
1 change: 0 additions & 1 deletion .devcontainer/project-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ else
fi

# Set up Git SSH signing
echo "Setting up Git SSH signing..."
if [ -f "$SCRIPT_DIR/setup-git-signing.sh" ]; then
"$SCRIPT_DIR/setup-git-signing.sh"
else
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ addresses-fork.json

# Forge artifacts
cache_forge
forge-artifacts/

# Graph client
.graphclient
Expand Down
1 change: 1 addition & 0 deletions packages/issuance/lib/forge-std
Submodule forge-std added at 77041d
76 changes: 76 additions & 0 deletions scripts/count-changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash

# Count changes in Solidity files between two branches, categorizing by code, comments, and blank lines
set -euo pipefail

# Check if cloc is installed
if ! command -v cloc &> /dev/null; then
echo "Error: cloc is not installed. Install with: sudo npm install -g cloc"
exit 1
fi

# Define the branches to compare
BASE_BRANCH="${1:-main}" # Default to 'main' if no argument provided
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)

echo "Comparing Solidity changes between $BASE_BRANCH and $CURRENT_BRANCH..."
echo

# Get all modified Solidity contract files
ALL_FILES=$(git diff --name-only "$BASE_BRANCH" -- 'packages/*/contracts/**/*.sol')

# Get excluded files (mock and test files)
EXCLUDED_FILES=$(echo "$ALL_FILES" | grep -E '(/mocks?/|/tests?/|Mock[A-Z].*\.sol$|.*Test\.sol$|Test[A-Z].*\.sol$)' || true)

# Get included files (non-mock, non-test files)
FILES=$(echo "$ALL_FILES" | grep -v -E '(/mocks?/|/tests?/|Mock[A-Z].*\.sol$|.*Test\.sol$|Test[A-Z].*\.sol$)' || true)

# Check if there are any files to process
if [ -z "$FILES" ]; then
echo "No Solidity files changed between $BASE_BRANCH and $CURRENT_BRANCH."
exit 0
fi

echo "Found changed Solidity files (excluding mocks and tests):"
echo "$FILES" | sed 's/^/- /'
echo

# Display excluded files if any
if [ -n "$EXCLUDED_FILES" ]; then
echo "Excluded mock and test files:"
echo "$EXCLUDED_FILES" | sed 's/^/- /'
echo
fi

# Create directories for diff analysis
TEMP_DIR=$(mktemp -d)
trap 'rm -rf "$TEMP_DIR"' EXIT
mkdir -p "$TEMP_DIR/old"
mkdir -p "$TEMP_DIR/new"

# Extract all changed files
echo "$FILES" | while IFS= read -r file; do
if [ -f "$file" ]; then
# Create directory structure
dir=$(dirname "$file")
mkdir -p "$TEMP_DIR/new/$dir"
mkdir -p "$TEMP_DIR/old/$dir"

# Copy current version
cp "$file" "$TEMP_DIR/new/$file"

# Get old version if it exists
if git show "$BASE_BRANCH:$file" &>/dev/null; then
git show "$BASE_BRANCH:$file" > "$TEMP_DIR/old/$file"
fi
fi
done

# Run cloc diff on all files
echo "Summary of changes (excluding mock and test files):"
echo "================================================"
cloc --diff "$TEMP_DIR/old" "$TEMP_DIR/new" --include-lang=Solidity --quiet

echo
echo "Note: This analysis only counts changes in Solidity files, excluding mock and test contracts."
echo "The 'same' category shows lines that were unchanged in modified files."
Loading