|
| 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. |
0 commit comments