|
| 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 conservative caching approach to prevent cache corruption issues: |
| 22 | + |
| 23 | +1. **Local Cache Directories**: Each container instance maintains its own cache directories |
| 24 | + |
| 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) |
| 29 | + |
| 30 | +2. **Safe Caches Only**: Only caches that won't cause cross-branch issues are configured |
| 31 | + |
| 32 | + - GitHub CLI: `/home/vscode/.cache/github` |
| 33 | + - Python packages: `/home/vscode/.cache/pip` |
| 34 | + |
| 35 | +3. **Intentionally Not Cached**: These tools use their default cache locations to avoid contamination |
| 36 | + - NPM (different dependency versions per branch) |
| 37 | + - Foundry, Solidity (different compilation artifacts per branch) |
| 38 | + - Hardhat (different build artifacts per branch) |
| 39 | + |
| 40 | +## Setup Instructions |
| 41 | + |
| 42 | +### Start the Dev Container |
| 43 | + |
| 44 | +To start the dev container: |
| 45 | + |
| 46 | +1. Open VS Code |
| 47 | +2. Use the "Remote-Containers: Open Folder in Container" command |
| 48 | +3. Select the repository directory (for example `/git/graphprotocol/contracts`) |
| 49 | + |
| 50 | +When the container starts, the `project-setup.sh` script will automatically run and: |
| 51 | + |
| 52 | +- Install project dependencies using pnpm |
| 53 | +- Configure Git to use SSH signing with your forwarded SSH key |
| 54 | +- Source shell customizations if available in PATH |
| 55 | + |
| 56 | +## Environment Variables |
| 57 | + |
| 58 | +Environment variables are defined in two places: |
| 59 | + |
| 60 | +1. **docker-compose.yml**: Contains most of the environment variables for tools and caching |
| 61 | +2. **Environment File**: Personal settings are stored in `/opt/configs/graphprotocol/contracts.env` on the host |
| 62 | + |
| 63 | +### Git Configuration |
| 64 | + |
| 65 | +To enable Git commit signing, add the following settings to your environment file: |
| 66 | + |
| 67 | +```env |
| 68 | +# Git settings for commit signing |
| 69 | +GIT_USER_NAME=Your Name |
| 70 | + |
| 71 | +``` |
| 72 | + |
| 73 | +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. |
| 74 | + |
| 75 | +## Troubleshooting |
| 76 | + |
| 77 | +### Cache Issues |
| 78 | + |
| 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 `pnpm clean` to clear project-specific build artifacts |
| 83 | +3. **Clear node modules**: Delete `node_modules` and run `pnpm install` again |
| 84 | + |
| 85 | +### Git SSH Signing Issues |
| 86 | + |
| 87 | +If you encounter issues with Git SSH signing: |
| 88 | + |
| 89 | +1. **SSH Agent Forwarding**: Make sure SSH agent forwarding is properly set up in your VS Code settings |
| 90 | +2. **GitHub Configuration**: Ensure your SSH key is added to GitHub as a signing key in your account settings |
| 91 | +3. **Manual Setup**: If automatic setup fails, you can manually configure SSH signing: |
| 92 | + |
| 93 | +```bash |
| 94 | +# Check available SSH keys |
| 95 | +ssh-add -l |
| 96 | + |
| 97 | +# Configure Git to use SSH signing |
| 98 | +git config --global gpg.format ssh |
| 99 | +git config --global user.signingkey "key::ssh-ed25519 YOUR_KEY_CONTENT" |
| 100 | +git config --global gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers |
| 101 | +git config --global commit.gpgsign true |
| 102 | + |
| 103 | +# Create allowed signers file |
| 104 | +echo "[email protected] ssh-ed25519 YOUR_KEY_CONTENT" > ~/.ssh/allowed_signers |
| 105 | +``` |
| 106 | + |
| 107 | +For other issues, check the `project-setup.sh` and `setup-git-signing.sh` scripts for any errors. |
0 commit comments