chore: configure devcontainer
This commit is contained in:
parent
1f64f8a176
commit
fc9fd5a6c3
6 changed files with 136 additions and 3 deletions
29
.devcontainer/Dockerfile
Normal file
29
.devcontainer/Dockerfile
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
FROM mcr.microsoft.com/devcontainers/python:3.12
|
||||
|
||||
# Install uv for dependency management
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||
|
||||
# Install system dependencies for JAX, OpenGL, and Mujoco
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libgl1 \
|
||||
libosmesa6-dev \
|
||||
libglew-dev \
|
||||
libglfw3 \
|
||||
patchelf \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set environment variables for hardware acceleration and rendering
|
||||
ENV LD_LIBRARY_PATH=/usr/lib/nvidia
|
||||
ENV NVIDIA_VISIBLE_DEVICES=all
|
||||
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,graphics
|
||||
|
||||
# Set the standardized workspace path
|
||||
ENV WORKSPACE_PATH=/workspaces/project
|
||||
ENV PATH="$WORKSPACE_PATH/.venv/bin:$PATH"
|
||||
|
||||
# Ensure the workspace directory exists and is owned by the vscode user
|
||||
# This prevents permission errors when the postCreateCommand runs uv sync
|
||||
RUN mkdir -p $WORKSPACE_PATH && chown vscode:vscode $WORKSPACE_PATH
|
||||
|
||||
USER vscode
|
||||
WORKDIR $WORKSPACE_PATH
|
||||
47
.devcontainer/devcontainer.json
Normal file
47
.devcontainer/devcontainer.json
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"name": "Brittle Star JAX/CUDA",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
"context": ".."
|
||||
},
|
||||
// Standardize workspace folder to /workspaces/project for IDE parity
|
||||
"workspaceFolder": "/workspaces/project",
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-python.python",
|
||||
"charliermarsh.ruff",
|
||||
"ms-python.vscode-pylance",
|
||||
"ms-toolsai.jupyter"
|
||||
],
|
||||
"settings": {
|
||||
"python.defaultInterpreterPath": "/workspaces/project/.venv/bin/python",
|
||||
"python.analysis.localRoot": "/workspaces/project",
|
||||
"python.analysis.extraPaths": [
|
||||
"/workspaces/project/.venv/lib/python3.12/site-packages"
|
||||
]
|
||||
}
|
||||
},
|
||||
"jetbrains": {
|
||||
"plugins": [
|
||||
"Pythonid",
|
||||
"fleet.python",
|
||||
"com.koxudaxi.ruff"
|
||||
]
|
||||
}
|
||||
},
|
||||
"remoteUser": "vscode",
|
||||
"runArgs": [
|
||||
"--gpus",
|
||||
"all"
|
||||
],
|
||||
// Ensure the .venv persists using a named volume for performance and parity
|
||||
"mounts": [
|
||||
"source=brittle_star-venv,target=/workspaces/project/.venv,type=volume"
|
||||
],
|
||||
// Invoke the hardware-aware sync script
|
||||
"postCreateCommand": "bash .devcontainer/post-create.sh",
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/common-utils:1": {}
|
||||
}
|
||||
}
|
||||
15
.devcontainer/post-create.sh
Normal file
15
.devcontainer/post-create.sh
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Detect if a GPU is available via nvidia-smi.
|
||||
# This works for Linux hosts and Windows (WSL2) with NVIDIA Container Toolkit.
|
||||
# On Mac (Apple Silicon) or systems without NVIDIA GPUs, this will skip the 'cuda' extra.
|
||||
if command -v nvidia-smi &> /dev/null && nvidia-smi &> /dev/null; then
|
||||
echo "GPU detected. Syncing with 'cuda' extra..."
|
||||
uv sync --frozen --extra cuda
|
||||
else
|
||||
echo "No GPU detected or nvidia-smi failed. Syncing without 'cuda' extra..."
|
||||
uv sync --frozen
|
||||
fi
|
||||
|
||||
echo "Environment synced successfully."
|
||||
Reference in a new issue