Skip to content

Commit fea36ce

Browse files
committed
perf: Switch to Alpine Linux and simplify to PDM-only setup
**Major changes:** - Use Alpine Linux base image (much smaller and faster) - Create proper vscode user (non-root) - Install only minimal dependencies (bash, git, build-base, python3, nodejs, jq) - PDM manages entire Python environment (venv auto-created) - Auto-activate PDM venv in .bashrc **Benefits:** - Smaller image size (~100MB vs ~1GB) - Faster container startup - Simpler dependency management (PDM handles everything) - User runs 'chipflow' directly (no 'pdm run' needed) **Updates:** - VS Code tasks: 'chipflow sim build' instead of 'pdm chipflow sim build' - Launch configs: direct chipflow commands - Venv persisted in volume for fast restarts The venv is auto-activated on shell start, so users can run chipflow commands directly without manual activation.
1 parent 25a57a4 commit fea36ce

6 files changed

Lines changed: 57 additions & 81 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
1-
FROM mcr.microsoft.com/devcontainers/python:1-3.11-bookworm
1+
FROM mcr.microsoft.com/devcontainers/base-alpine:latest
22

3-
# Install system dependencies in the image build (cached in prebuild)
4-
RUN apt-get update && apt-get install -y \
5-
build-essential \
3+
# Install minimal dependencies - PDM will handle Python environment
4+
RUN apk add --no-cache \
5+
bash \
6+
git \
67
curl \
7-
wget \
8-
make \
9-
cmake \
10-
pkg-config \
11-
libffi-dev \
12-
libssl-dev \
13-
zlib1g-dev \
14-
libbz2-dev \
15-
libreadline-dev \
16-
libsqlite3-dev \
17-
libncurses5-dev \
18-
libgdbm-dev \
19-
libnss3-dev \
20-
liblzma-dev \
8+
build-base \
9+
python3 \
10+
python3-dev \
11+
py3-pip \
12+
nodejs \
13+
npm \
2114
jq \
22-
&& apt-get clean && rm -rf /var/lib/apt/lists/*
15+
sudo \
16+
shadow
2317

24-
# Install ripgrep and fd
25-
RUN curl -sSLO https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep_13.0.0_amd64.deb && \
26-
curl -sSLO https://github.com/sharkdp/fd/releases/download/v8.7.0/fd_8.7.0_amd64.deb && \
27-
dpkg -i ripgrep_13.0.0_amd64.deb fd_8.7.0_amd64.deb && \
28-
rm -f *.deb
18+
# Create vscode user with sudo access
19+
RUN addgroup -g 1000 vscode && \
20+
adduser -D -u 1000 -G vscode -s /bin/bash vscode && \
21+
echo "vscode ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/vscode && \
22+
chmod 0440 /etc/sudoers.d/vscode
2923

30-
# Install PDM globally in the image
31-
RUN curl -sSL https://pdm-project.org/install-pdm.py | python3 - && \
32-
echo 'export PATH="/root/.local/bin:$PATH"' >> /etc/bash.bashrc
33-
34-
# Switch to vscode user and install PDM for them too
24+
# Switch to vscode user
3525
USER vscode
26+
WORKDIR /home/vscode
27+
28+
# Install PDM for vscode user
3629
RUN curl -sSL https://pdm-project.org/install-pdm.py | python3 - && \
37-
echo 'export PATH="/home/vscode/.local/bin:$PATH"' >> ~/.bashrc
30+
echo 'export PATH="/home/vscode/.local/bin:$PATH"' >> ~/.bashrc && \
31+
echo 'eval "$(pdm venv activate in-project 2>/dev/null || true)"' >> ~/.bashrc
3832

39-
USER root
33+
# Set PDM to use in-project venv by default
34+
ENV PDM_VENV_IN_PROJECT=1
35+
ENV PATH="/home/vscode/.local/bin:$PATH"

.devcontainer/devcontainer.json

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@
44
"dockerfile": "Dockerfile"
55
},
66

7-
// Features to install (optimized)
7+
// Features to install
88
"features": {
9-
"ghcr.io/devcontainers/features/git:1": {},
10-
"ghcr.io/devcontainers/features/github-cli:1": {},
11-
"ghcr.io/devcontainers/features/node:1": {
12-
"version": "20",
13-
"nvmVersion": "latest"
14-
},
15-
"ghcr.io/devcontainers/features/common-utils:2": {
16-
"installZsh": false,
17-
"installOhMyZsh": false,
18-
"upgradePackages": false
19-
}
9+
"ghcr.io/devcontainers/features/github-cli:1": {}
2010
},
2111

2212
// Configure tool-specific properties
@@ -59,13 +49,14 @@
5949
// Container optimizations
6050
"containerEnv": {
6151
"PYTHONUNBUFFERED": "1",
62-
"PYTHONDONTWRITEBYTECODE": "1"
52+
"PYTHONDONTWRITEBYTECODE": "1",
53+
"PDM_VENV_IN_PROJECT": "1"
6354
},
6455

65-
// Mount optimizations
56+
// Mount optimizations - persist venv and extensions
6657
"mounts": [
6758
"source=chipflow-vscode-extensions,target=/home/vscode/.vscode-server/extensions,type=volume",
68-
"source=chipflow-node-modules,target=${containerWorkspaceFolder}/node_modules,type=volume"
59+
"source=chipflow-venv,target=${containerWorkspaceFolder}/.venv,type=volume"
6960
],
7061

7162
// Set container user

.devcontainer/install-deps.sh

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,21 @@ set -e
44

55
echo "📦 Installing ChipFlow dependencies (runs during prebuild)..."
66

7-
# Ensure PDM is in PATH
8-
export PATH="/home/vscode/.local/bin:$PATH"
9-
107
# Verify PDM is available
11-
if ! command -v pdm &> /dev/null; then
12-
echo "⚠️ PDM not found, attempting to install..."
13-
curl -sSL https://pdm-project.org/install-pdm.py | python3 -
14-
export PATH="/home/vscode/.local/bin:$PATH"
15-
fi
16-
178
pdm --version
189

1910
# Install project dependencies if pyproject.toml exists
2011
if [ -f "pyproject.toml" ]; then
21-
echo "📚 Installing Python dependencies with PDM..."
12+
echo "📚 Installing Python dependencies with PDM (creates venv)..."
2213
pdm install --dev
23-
echo "✅ Dependencies installed successfully"
14+
echo "✅ Dependencies installed in $(pdm venv list)"
2415
else
2516
echo "⚠️ No pyproject.toml found, skipping dependency installation"
2617
fi
2718

2819
# Set up git configuration (minimal)
2920
git config --global init.defaultBranch main
3021
git config --global pull.rebase false
22+
git config --global --add safe.directory '*'
3123

3224
echo "✅ Prebuild setup complete!"

.devcontainer/post-create.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ set -e
44

55
echo "🚀 ChipFlow codespace starting..."
66

7-
# Ensure PDM is in PATH
7+
# Ensure PDM is in PATH and venv auto-activation is configured
88
export PATH="/home/vscode/.local/bin:$PATH"
9+
eval "$(pdm venv activate in-project 2>/dev/null || true)"
910

1011
# Check if design configuration was passed from configurator
1112
if [ -n "$CHIPFLOW_DESIGN_CONFIG" ]; then
@@ -72,19 +73,15 @@ else
7273
echo "ℹ️ No design configuration provided - using template defaults"
7374
fi
7475

75-
# Create activation script
76-
cat > activate_env.sh << 'EOF'
77-
#!/bin/bash
78-
eval $(pdm info --env)
79-
echo "✅ ChipFlow environment activated!"
80-
echo "📋 Run 'pdm run --list' to see available commands"
81-
EOF
82-
chmod +x activate_env.sh
83-
8476
echo ""
8577
echo "🎉 ChipFlow codespace is ready!"
8678
echo ""
79+
if [ -f ".venv/bin/activate" ]; then
80+
echo "✅ PDM virtual environment is active"
81+
echo ""
82+
fi
8783
echo "Quick commands:"
8884
echo " • F5 or Cmd/Ctrl+Shift+B - Build and run simulation"
89-
echo " • pdm chipflow --help - ChipFlow CLI help"
85+
echo " • chipflow --help - ChipFlow CLI help"
86+
echo " • pdm run --list - See all available commands"
9087
echo ""

.vscode/launch.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "ChipFlow: Build and Run Simulation",
66
"type": "node-terminal",
77
"request": "launch",
8-
"command": "pdm chipflow sim build && pdm chipflow sim run",
8+
"command": "chipflow sim build && chipflow sim run",
99
"cwd": "${workspaceFolder}",
1010
"presentation": {
1111
"hidden": false,
@@ -17,7 +17,7 @@
1717
"name": "ChipFlow: Run Simulation (skip build)",
1818
"type": "node-terminal",
1919
"request": "launch",
20-
"command": "pdm chipflow sim run",
20+
"command": "chipflow sim run",
2121
"cwd": "${workspaceFolder}",
2222
"presentation": {
2323
"hidden": false,
@@ -29,7 +29,7 @@
2929
"name": "ChipFlow: Build Simulation Only",
3030
"type": "node-terminal",
3131
"request": "launch",
32-
"command": "pdm chipflow sim build",
32+
"command": "chipflow sim build",
3333
"cwd": "${workspaceFolder}",
3434
"presentation": {
3535
"hidden": false,
@@ -41,7 +41,7 @@
4141
"name": "ChipFlow: Generate Verilog",
4242
"type": "node-terminal",
4343
"request": "launch",
44-
"command": "pdm chipflow build",
44+
"command": "chipflow build",
4545
"cwd": "${workspaceFolder}",
4646
"presentation": {
4747
"hidden": false,

.vscode/tasks.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
{
55
"label": "ChipFlow: Build Simulation",
66
"type": "shell",
7-
"command": "pdm",
8-
"args": ["chipflow", "sim", "build"],
7+
"command": "chipflow",
8+
"args": ["sim", "build"],
99
"group": {
1010
"kind": "build",
1111
"isDefault": true
@@ -17,13 +17,13 @@
1717
"clear": false
1818
},
1919
"problemMatcher": [],
20-
"detail": "Build the ChipFlow simulation (pdm chipflow sim build)"
20+
"detail": "Build the ChipFlow simulation"
2121
},
2222
{
2323
"label": "ChipFlow: Run Simulation",
2424
"type": "shell",
25-
"command": "pdm",
26-
"args": ["chipflow", "sim", "run"],
25+
"command": "chipflow",
26+
"args": ["sim", "run"],
2727
"group": {
2828
"kind": "test",
2929
"isDefault": true
@@ -35,7 +35,7 @@
3535
"clear": false
3636
},
3737
"problemMatcher": [],
38-
"detail": "Run the ChipFlow simulation (pdm chipflow sim run)",
38+
"detail": "Run the ChipFlow simulation",
3939
"dependsOn": ["ChipFlow: Build Simulation"]
4040
},
4141
{
@@ -53,8 +53,8 @@
5353
{
5454
"label": "ChipFlow: Generate Verilog",
5555
"type": "shell",
56-
"command": "pdm",
57-
"args": ["chipflow", "build"],
56+
"command": "chipflow",
57+
"args": ["build"],
5858
"group": "build",
5959
"presentation": {
6060
"reveal": "always",
@@ -63,7 +63,7 @@
6363
"clear": false
6464
},
6565
"problemMatcher": [],
66-
"detail": "Generate Verilog from design (pdm chipflow build)"
66+
"detail": "Generate Verilog from design"
6767
},
6868
{
6969
"label": "ChipFlow: Clean",

0 commit comments

Comments
 (0)