Skip to content

feat: add devcontainer #10429

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

Merged
merged 2 commits into from
May 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .devcontainer/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
FROM ubuntu:22.04

ARG USERNAME=foundry
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG PYTHON_VERSION=3.11
ARG NODE_MAJOR=20
ARG VYPER_VERSION=0.4.0

ENV DEBIAN_FRONTEND=noninteractive
ENV CARGO_TERM_COLOR=always \
RUST_BACKTRACE=full

WORKDIR /workspace

RUN apt-get update && apt-get install -y --no-install-recommends \
# Build tools
build-essential \
clang \
lld \
pkg-config \
# Network/SSL
curl \
ca-certificates \
gnupg \
libssl-dev \
# Version control & utils
git \
sudo \
unzip \
# Python
python${PYTHON_VERSION} \
python3-pip \
python${PYTHON_VERSION}-venv \
# Add Node.js repo
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
# Update again after adding repo and install Node.js
&& apt-get update && apt-get install -y --no-install-recommends \
nodejs \
# Clean up apt cache
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Ensure python points to the installed python version
RUN ln -sf /usr/bin/python${PYTHON_VERSION} /usr/bin/python && \
ln -sf /usr/bin/python${PYTHON_VERSION} /usr/bin/python3

# Create non-root user with sudo privileges
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \
# Setup sudo without password prompt
&& echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
# Add user to the sudo group (standard practice)
&& usermod -aG sudo $USERNAME

# Switch to the non-root user
USER $USERNAME
WORKDIR /home/$USERNAME

# --- User-specific installations ---

# Install Bun
ENV BUN_INSTALL="/home/$USERNAME/.bun"
ENV PATH="$BUN_INSTALL/bin:$PATH"
RUN curl -fsSL https://bun.sh/install | bash

# Install Rust & cargo-nextest
ENV CARGO_HOME="/home/$USERNAME/.cargo"
ENV RUSTUP_HOME="/home/$USERNAME/.rustup"
ENV PATH="$CARGO_HOME/bin:$PATH"
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& cargo install cargo-nextest --locked

# Install Vyper using pip
# Ensure pip user install directory is in PATH
ENV PYTHONUSERBASE="/home/$USERNAME/.local"
ENV PATH="$PYTHONUSERBASE/bin:$PATH"
RUN pip3 install --user vyper==${VYPER_VERSION}

# Switch back to the main workspace directory
WORKDIR /workspace

49 changes: 49 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// For format details, see https://aka.ms/devcontainer.json.
{
"name": "Foundry Development",
"build": {
"context": "..",
"dockerfile": "Dockerfile.dev"
},

"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": true,
"installOhMyZsh": true,
"upgradePackages": true
}
},

"forwardPorts": [],

"postCreateCommand": "rustup default stable && rustup update",

"customizations": {
"vscode": {
"extensions": [
"rust-lang.rust-analyzer",
"serayuzgur.crates",
"tamasfe.even-better-toml",
"ms-python.python",
"dbaeumer.vscode-eslint",
"oven.bun-vscode"
],
"settings": {
"rust-analyzer.checkOnSave": true,
"rust-analyzer.cargo.features": "all"
}
}
},

"remoteUser": "foundry",

"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",

"workspaceFolder": "/workspace",

"mounts": [
"source=${localEnv:HOME}/.cargo/registry,target=/home/foundry/.cargo/registry,type=bind,consistency=cached",
"source=${localEnv:HOME}/.cargo/git,target=/home/foundry/.cargo/git,type=bind,consistency=cached"
]
}
1 change: 1 addition & 0 deletions .github/workflows/nextest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
with:
python-version: 3.11
- name: Install Vyper
# Also update vyper version in .devcontainer/Dockerfile.dev
run: pip --version && pip install vyper==0.4.0

- name: Forge RPC cache
Expand Down
Loading