这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
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
100 changes: 72 additions & 28 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,77 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/go/.devcontainer/base.Dockerfile

# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon): 1, 1.16, 1.17, 1-bullseye, 1.16-bullseye, 1.17-bullseye, 1-buster, 1.16-buster, 1.17-buster
ARG VARIANT="1.18-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT}

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
# Chromium for running Turbopack benchmarks
chromium \
# Used for plotters graph visualizations in turbopack benchmarks
libfontconfig1-dev

# Add hyperfine, a useful benchmarking tool
RUN dpkgArch="$(dpkg --print-architecture)"; \
wget "https://github.com/sharkdp/hyperfine/releases/download/v1.12.0/hyperfine_1.12.0_${dpkgArch}.deb" && dpkg -i "hyperfine_1.12.0_${dpkgArch}.deb"

#
# Everything below is run as the vscode user. If superuser permissions are necessary,
# run it before this. Otherwise, prefer running as the vscode user.
#
# Use the official Microsoft devcontainers Ubuntu base image
FROM mcr.microsoft.com/devcontainers/base:ubuntu-22.04

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Update package list and install dependencies
RUN apt-get update && apt-get install -y \
# Basic build tools
build-essential \
curl \
wget \
git \
pkg-config \
libssl-dev \
# LLD linker (required for Linux as mentioned in CONTRIBUTING.md)
lld \
# Protocol Buffers compiler
protobuf-compiler \
# Cap'n Proto
capnproto \
libcapnp-dev \
# Test dependencies (jq and zstd)
jq \
zstd \
# Additional useful tools
htop \
vim \
nano \
unzip \
&& rm -rf /var/lib/apt/lists/*

# Install Node.js v22 using NodeSource repository (as root)
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
&& apt-get install -y nodejs

# Switch to vscode user for the rest of the setup
USER vscode

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then umask 0002 && sh -c ". /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION}" 2>&1; fi
# Install pnpm with the specific version from package.json
RUN curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=8.14.0 sh -

RUN sh -c ". /usr/local/share/nvm/nvm.sh && npm install -g vercel yarn yalc pnpm nodemon" 2>&1
# Add pnpm to PATH
ENV PATH="/home/vscode/.local/share/pnpm:$PATH"

# The installer from https://rustup.rs/ homepage, with the following changes:
# * `-y` to accept without interactivity
# * `--default-toolchain none` to avoid installing stable rust. Our specific toolchain is installed post-create.
# Install Rust using rustup
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none

# Add Rust to PATH
ENV PATH="/home/vscode/.cargo/bin:$PATH"

# Install the specific Rust toolchain (nightly-2025-06-20) with required components
RUN /home/vscode/.cargo/bin/rustup toolchain install nightly-2025-06-20 --component rustfmt,clippy

# Set the default toolchain to match rust-toolchain.toml
RUN /home/vscode/.cargo/bin/rustup default nightly-2025-06-20

# Install llvm-tools-preview for coverage reporting
RUN /home/vscode/.cargo/bin/rustup component add llvm-tools-preview

# Install cargo-llvm-cov for coverage
RUN /home/vscode/.cargo/bin/cargo install cargo-llvm-cov

# Install other useful cargo tools
RUN /home/vscode/.cargo/bin/cargo install cargo-watch cargo-edit

# Create a custom cargo coverage command alias
RUN echo 'alias cargo-coverage="cargo llvm-cov --html --open"' >> /home/vscode/.bashrc

# Verify installations
RUN node --version && npm --version && pnpm --version
RUN /home/vscode/.cargo/bin/rustc --version && /home/vscode/.cargo/bin/cargo --version
RUN protoc --version && capnp --version
RUN jq --version && zstd --version

# Switch back to noninteractive to avoid warnings
ENV DEBIAN_FRONTEND=noninteractive
87 changes: 87 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Development Container Configuration

This directory contains the development container configuration for Turborepo. The devcontainer provides a fully configured development environment with all required dependencies.

## What's Included

### Core Dependencies
- **Rust**: Nightly toolchain (nightly-2025-06-20) with rustfmt, clippy, and llvm-tools-preview
- **Node.js**: Version 22.x (as specified in package.json engines)
- **pnpm**: Version 8.14.0 (as specified in package.json packageManager)

### Build Tools
- **protoc**: Protocol Buffers compiler
- **capnp**: Cap'n Proto serialization framework
- **LLD**: LLVM linker (required for Linux builds)

### Development Tools
- **jq**: JSON processor (required for tests)
- **zstd**: Compression library (required for tests)
- **cargo-llvm-cov**: Coverage reporting tool
- **cargo-watch**: File watcher for Cargo
- **cargo-edit**: Cargo subcommands for dependency management

### VS Code Extensions
- Rust Analyzer with optimized settings
- ESLint and Prettier for JavaScript/TypeScript
- Tailwind CSS IntelliSense
- GitLens and GitHub integration
- Markdown support
- And more development productivity tools

## Quick Start

1. Open the repository in VS Code
2. When prompted, click "Reopen in Container" or run "Dev Containers: Reopen in Container"
3. Wait for the container to build and the post-create script to run
4. Start developing!

## Post-Create Setup

The `post-create.sh` script automatically:
- Installs Node.js dependencies with `pnpm install`
- Verifies Rust toolchain installation
- Builds the project with `cargo build`
- Displays helpful quick-start commands

## Useful Commands

After the container is ready, you can use:

```bash
# Rust development
cargo build # Build the project
cargo test # Run unit tests
cargo coverage # Run tests with coverage
cargo fmt # Format Rust code
cargo clippy # Run linter

# Node.js development
pnpm install # Install dependencies
pnpm build # Build all packages
pnpm test # Run integration tests

# Combined workflows
pnpm -- turbo run build # Build all packages using Turbo
pnpm -- turbo run test # Run all tests using Turbo
```

## Configuration Notes

- The container runs as the `vscode` user for security
- Docker-in-Docker is enabled for containerized workflows
- Git and GitHub CLI are pre-installed
- The Rust toolchain matches the `rust-toolchain.toml` specification
- Node.js version matches the `engines` field in `package.json`
- All dependencies align with requirements in `CONTRIBUTING.md`

## Troubleshooting

If you encounter issues:

1. **Container build fails**: Check that Docker has sufficient resources allocated
2. **Rust toolchain issues**: The post-create script will verify the installation
3. **Node.js dependency issues**: Try running `pnpm install --frozen-lockfile`
4. **Permission issues**: All operations should work as the `vscode` user

For more detailed information, see the main [CONTRIBUTING.md](../CONTRIBUTING.md) file.
96 changes: 53 additions & 43 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,62 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/go
{
"name": "turbo (go, node, rust)",
"name": "Turborepo Development Environment",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Update the VARIANT arg to pick a version of Go: 1, 1.18, 1.17
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon.
"VARIANT": "1.18-bullseye",
// Options
"NODE_VERSION": "lts/*"
}
"dockerfile": "Dockerfile"
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"bradlc.vscode-tailwindcss",
"christian-kohler.npm-intellisense",
"dbaeumer.vscode-eslint",
"eamodio.gitlens",
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode",
"github.copilot",
"github.vscode-pull-request-github",
"golang.go",
"heybourn.headwind",
"rust-lang.rust-analyzer",
"silvenon.mdx",
"windmilleng.vscode-go-autotest",
"yzhang.markdown-all-in-one"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "cargo --version",
// Invoking `cargo` will eagerly install the toolchain specified in rust-toolchain file

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"customizations": {
"vscode": {
"extensions": [
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"serayuzgur.crates",
"vadimcn.vscode-lldb",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"bradlc.vscode-tailwindcss",
"christian-kohler.npm-intellisense",
"eamodio.gitlens",
"EditorConfig.EditorConfig",
"github.copilot",
"github.vscode-pull-request-github",
"heybourn.headwind",
"silvenon.mdx",
"yzhang.markdown-all-in-one"
],
"settings": {
"rust-analyzer.server.path": "rust-analyzer",
"rust-analyzer.cargo.buildScripts.enable": true,
"rust-analyzer.procMacro.enable": true,
"rust-analyzer.cargo.loadOutDirsFromCheck": true,
"rust-analyzer.checkOnSave.command": "clippy",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
}
}
},
"features": {
"docker-in-docker": "latest",
"git": "latest",
"github-cli": "latest"
}
}
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"postCreateCommand": ".devcontainer/post-create.sh",
"remoteUser": "vscode"
}
31 changes: 31 additions & 0 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -e

echo "🚀 Setting up Turborepo development environment..."

# Ensure we're in the workspace directory
cd /workspaces/turborepo 2>/dev/null || cd /workspace 2>/dev/null || cd "$(pwd)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cd /workspaces/turborepo 2>/dev/null || cd /workspace 2>/dev/null || cd "$(pwd)"
cd /workspaces/turborepo 2>/dev/null || cd /workspace 2>/dev/null || { echo "Error: Could not find workspace directory"; exit 1; }

The directory fallback logic cd "$(pwd)" doesn't actually change directories - it just changes to the current directory you're already in.

View Details

Analysis

Ineffective directory fallback in .devcontainer/post-create.sh fails silently

What fails: Line 7's fallback cd "$(pwd)" does nothing since $(pwd) expands to the current directory. If neither /workspaces/turborepo nor /workspace exist, the script continues in the wrong directory, causing pnpm install and cargo build to fail with confusing errors.

How to reproduce:

cd /tmp
# Run the original fallback chain
cd /workspaces/turborepo 2>/dev/null || cd /workspace 2>/dev/null || cd "$(pwd)"
echo "Directory: $(pwd)"  # Still in /tmp

Result: Script stays in /tmp, then pnpm install fails with "No package.json found" instead of a clear workspace directory error.

Expected: Should fail fast with clear error message per Dev Container specification - postCreateCommand runs in workspaceFolder by default, but defensive cd check should provide meaningful error when directories don't exist.

Fix: Replace cd "$(pwd)" with proper error handling: { echo "Error: Could not find workspace directory"; exit 1; }


echo "📦 Installing Node.js dependencies..."
# Install dependencies using pnpm
pnpm install

echo "🦀 Verifying Rust installation..."
# Verify Rust toolchain matches rust-toolchain.toml
rustc --version
cargo --version

# Install dependencies and build the project to verify everything works
echo "🔨 Building Turborepo..."
cargo build

echo "✅ Turborepo development environment is ready!"
echo ""
echo "📋 Quick start commands:"
echo " cargo build - Build the Rust binary"
echo " cargo test - Run unit tests"
echo " cargo coverage - Run tests with coverage"
echo " pnpm test - Run integration tests"
echo " pnpm build - Build all packages"
echo ""
echo "🔍 For more commands, see CONTRIBUTING.md"
Loading