Skip to content

Commit 6739154

Browse files
authored
refactor: Dev Container (devcontainer) to standardize paths to /workspace (for pytest compatibility) (#3870)
Signed-off-by: Keiven Chang <[email protected]>
1 parent 6e213d9 commit 6739154

File tree

7 files changed

+95
-89
lines changed

7 files changed

+95
-89
lines changed

.devcontainer/devcontainer.json.j2

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// Disable automatic copying of .gitconfig to avoid errors
3030
"dev.containers.copyGitConfig": false,
3131
"terminal.integrated.defaultProfile.linux": "bash",
32-
"terminal.integrated.cwd": "/home/ubuntu/dynamo",
32+
"terminal.integrated.cwd": "/workspace",
3333

3434
"python.defaultInterpreterPath": "/opt/dynamo/venv/bin/python",
3535
"python.linting.enabled": true,
@@ -38,7 +38,7 @@
3838
"rust-analyzer.checkOnSave.command": "clippy",
3939
"rust-analyzer.checkOnSave.enable": true,
4040
"rust-analyzer.cargo.buildScripts.enable": true,
41-
"rust-analyzer.cargo.targetDir": "/home/ubuntu/dynamo/.build/target",
41+
"rust-analyzer.cargo.targetDir": "/workspace/target",
4242
"rust-analyzer.procMacro.enable": true,
4343
"rust-analyzer.completion.autoimport.enable": true,
4444

@@ -56,16 +56,10 @@
5656
}
5757
}
5858
},
59-
"workspaceFolder": "/home/ubuntu/dynamo",
60-
"workspaceMount": "source=${localWorkspaceFolder},target=/home/ubuntu/dynamo,type=bind,consistency=cached",
59+
"workspaceFolder": "/workspace",
60+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
6161
"userEnvProbe": "interactiveShell",
62-
"postCreateCommand": "/bin/bash /home/ubuntu/dynamo/.devcontainer/post-create.sh", // Runs cargo build and pip installs packages
63-
"containerEnv": {
64-
"DYNAMO_HOME": "/home/ubuntu/dynamo",
65-
"CARGO_HOME": "/home/ubuntu/dynamo/.build/.cargo",
66-
"RUSTUP_HOME": "/home/ubuntu/dynamo/.build/.rustup",
67-
"CARGO_TARGET_DIR": "/home/ubuntu/dynamo/.build/target"
68-
},
62+
"postCreateCommand": "/bin/bash /workspace/.devcontainer/post-create.sh", // Runs cargo build and pip installs packages
6963
"remoteEnv": {
7064
// Optional convenience tokens passed from host. SSH agent is forwarded via your IDE setting, not here by default.
7165
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}",

.devcontainer/post-create.sh

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
set -eu
66

7-
# Set DYNAMO_HOME if not already set
8-
export DYNAMO_HOME=${DYNAMO_HOME:-/home/ubuntu/dynamo}
7+
# Use WORKSPACE_DIR if set (should be set by Dockerfile.local_dev)
8+
# Otherwise, use /workspace as fallback
9+
WORKSPACE_DIR="${WORKSPACE_DIR:-/workspace}"
910

1011
# Ensure we're not running as root
1112
if [ "$(id -u)" -eq 0 ]; then
@@ -53,11 +54,12 @@ show_and_run() {
5354
set -x
5455

5556
# Pre-commit hooks
56-
cd $DYNAMO_HOME && pre-commit install && retry pre-commit install-hooks
57+
cd $WORKSPACE_DIR && pre-commit install && retry pre-commit install-hooks
5758
pre-commit run --all-files || true # don't fail the build if pre-commit hooks fail
5859

59-
# Set build directory
60-
export CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-$DYNAMO_HOME/.build/target}
60+
# Use CARGO_TARGET_DIR from environment (should be set by Dockerfile.local_dev)
61+
# Fallback to $WORKSPACE_DIR/target if not set
62+
export CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-$WORKSPACE_DIR/target}
6163
mkdir -p $CARGO_TARGET_DIR
6264

6365
uv pip uninstall --yes ai-dynamo ai-dynamo-runtime 2>/dev/null || true
@@ -78,27 +80,16 @@ cargo build --locked --profile dev --features dynamo-llm/block-manager
7880
# fi
7981

8082
# install ai-dynamo-runtime
81-
(cd $DYNAMO_HOME/lib/bindings/python && retry maturin develop)
83+
(cd $WORKSPACE_DIR/lib/bindings/python && retry maturin develop)
8284

8385
# install ai-dynamo
84-
cd $DYNAMO_HOME && retry env DYNAMO_BIN_PATH=$CARGO_TARGET_DIR/debug uv pip install -e .
86+
cd $WORKSPACE_DIR && retry env DYNAMO_BIN_PATH=$CARGO_TARGET_DIR/debug uv pip install -e .
8587

8688
{ set +x; } 2>/dev/null
8789

8890
echo -e "\n" >> ~/.bashrc
8991
echo "# === This section is generated by the post-create.sh script ===" >> ~/.bashrc
9092

91-
# Check if PYTHONPATH is already set in environment
92-
if [ -n "${PYTHONPATH:-}" ]; then
93-
# PYTHONPATH exists, replace /workspace with $DYNAMO_HOME
94-
export PYTHONPATH=$(echo "$PYTHONPATH" | sed "s|/workspace|$DYNAMO_HOME|g")
95-
# Also add to .bashrc for persistence
96-
if ! grep -q "export PYTHONPATH=" ~/.bashrc; then
97-
echo "# PYTHONPATH modified from /workspace to use DYNAMO_HOME" >> ~/.bashrc
98-
show_and_run echo "export PYTHONPATH=\"$PYTHONPATH\"" >> ~/.bashrc
99-
fi
100-
fi
101-
10293
if ! grep -q "export GPG_TTY=" ~/.bashrc; then
10394
show_and_run echo 'export GPG_TTY=$(tty)' >> ~/.bashrc
10495
fi
@@ -123,7 +114,7 @@ else
123114
echo "⚠️ SSH agent forwarding not configured - SSH_AUTH_SOCK is not set"
124115
fi
125116

126-
show_and_run $DYNAMO_HOME/deploy/sanity_check.py
117+
show_and_run $WORKSPACE_DIR/deploy/sanity_check.py
127118

128119
cat <<EOF
129120

.devcontainer/sglang/devcontainer.json

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// Disable automatic copying of .gitconfig to avoid errors
3333
"dev.containers.copyGitConfig": false,
3434
"terminal.integrated.defaultProfile.linux": "bash",
35-
"terminal.integrated.cwd": "/home/ubuntu/dynamo",
35+
"terminal.integrated.cwd": "/workspace",
3636

3737
"python.defaultInterpreterPath": "/opt/dynamo/venv/bin/python",
3838
"python.linting.enabled": true,
@@ -41,7 +41,7 @@
4141
"rust-analyzer.checkOnSave.command": "clippy",
4242
"rust-analyzer.checkOnSave.enable": true,
4343
"rust-analyzer.cargo.buildScripts.enable": true,
44-
"rust-analyzer.cargo.targetDir": "/home/ubuntu/dynamo/.build/target",
44+
"rust-analyzer.cargo.targetDir": "/workspace/target",
4545
"rust-analyzer.procMacro.enable": true,
4646
"rust-analyzer.completion.autoimport.enable": true,
4747

@@ -59,16 +59,10 @@
5959
}
6060
}
6161
},
62-
"workspaceFolder": "/home/ubuntu/dynamo",
63-
"workspaceMount": "source=${localWorkspaceFolder},target=/home/ubuntu/dynamo,type=bind,consistency=cached",
62+
"workspaceFolder": "/workspace",
63+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
6464
"userEnvProbe": "interactiveShell",
65-
"postCreateCommand": "/bin/bash /home/ubuntu/dynamo/.devcontainer/post-create.sh", // Runs cargo build and pip installs packages
66-
"containerEnv": {
67-
"DYNAMO_HOME": "/home/ubuntu/dynamo",
68-
"CARGO_HOME": "/home/ubuntu/dynamo/.build/.cargo",
69-
"RUSTUP_HOME": "/home/ubuntu/dynamo/.build/.rustup",
70-
"CARGO_TARGET_DIR": "/home/ubuntu/dynamo/.build/target"
71-
},
65+
"postCreateCommand": "/bin/bash /workspace/.devcontainer/post-create.sh", // Runs cargo build and pip installs packages
7266
"remoteEnv": {
7367
// Optional convenience tokens passed from host. SSH agent is forwarded via your IDE setting, not here by default.
7468
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}",

.devcontainer/trtllm/devcontainer.json

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// Disable automatic copying of .gitconfig to avoid errors
3333
"dev.containers.copyGitConfig": false,
3434
"terminal.integrated.defaultProfile.linux": "bash",
35-
"terminal.integrated.cwd": "/home/ubuntu/dynamo",
35+
"terminal.integrated.cwd": "/workspace",
3636

3737
"python.defaultInterpreterPath": "/opt/dynamo/venv/bin/python",
3838
"python.linting.enabled": true,
@@ -41,7 +41,7 @@
4141
"rust-analyzer.checkOnSave.command": "clippy",
4242
"rust-analyzer.checkOnSave.enable": true,
4343
"rust-analyzer.cargo.buildScripts.enable": true,
44-
"rust-analyzer.cargo.targetDir": "/home/ubuntu/dynamo/.build/target",
44+
"rust-analyzer.cargo.targetDir": "/workspace/target",
4545
"rust-analyzer.procMacro.enable": true,
4646
"rust-analyzer.completion.autoimport.enable": true,
4747

@@ -59,16 +59,10 @@
5959
}
6060
}
6161
},
62-
"workspaceFolder": "/home/ubuntu/dynamo",
63-
"workspaceMount": "source=${localWorkspaceFolder},target=/home/ubuntu/dynamo,type=bind,consistency=cached",
62+
"workspaceFolder": "/workspace",
63+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
6464
"userEnvProbe": "interactiveShell",
65-
"postCreateCommand": "/bin/bash /home/ubuntu/dynamo/.devcontainer/post-create.sh", // Runs cargo build and pip installs packages
66-
"containerEnv": {
67-
"DYNAMO_HOME": "/home/ubuntu/dynamo",
68-
"CARGO_HOME": "/home/ubuntu/dynamo/.build/.cargo",
69-
"RUSTUP_HOME": "/home/ubuntu/dynamo/.build/.rustup",
70-
"CARGO_TARGET_DIR": "/home/ubuntu/dynamo/.build/target"
71-
},
65+
"postCreateCommand": "/bin/bash /workspace/.devcontainer/post-create.sh", // Runs cargo build and pip installs packages
7266
"remoteEnv": {
7367
// Optional convenience tokens passed from host. SSH agent is forwarded via your IDE setting, not here by default.
7468
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}",

.devcontainer/vllm/devcontainer.json

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// Disable automatic copying of .gitconfig to avoid errors
3333
"dev.containers.copyGitConfig": false,
3434
"terminal.integrated.defaultProfile.linux": "bash",
35-
"terminal.integrated.cwd": "/home/ubuntu/dynamo",
35+
"terminal.integrated.cwd": "/workspace",
3636

3737
"python.defaultInterpreterPath": "/opt/dynamo/venv/bin/python",
3838
"python.linting.enabled": true,
@@ -41,7 +41,7 @@
4141
"rust-analyzer.checkOnSave.command": "clippy",
4242
"rust-analyzer.checkOnSave.enable": true,
4343
"rust-analyzer.cargo.buildScripts.enable": true,
44-
"rust-analyzer.cargo.targetDir": "/home/ubuntu/dynamo/.build/target",
44+
"rust-analyzer.cargo.targetDir": "/workspace/target",
4545
"rust-analyzer.procMacro.enable": true,
4646
"rust-analyzer.completion.autoimport.enable": true,
4747

@@ -59,16 +59,10 @@
5959
}
6060
}
6161
},
62-
"workspaceFolder": "/home/ubuntu/dynamo",
63-
"workspaceMount": "source=${localWorkspaceFolder},target=/home/ubuntu/dynamo,type=bind,consistency=cached",
62+
"workspaceFolder": "/workspace",
63+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
6464
"userEnvProbe": "interactiveShell",
65-
"postCreateCommand": "/bin/bash /home/ubuntu/dynamo/.devcontainer/post-create.sh", // Runs cargo build and pip installs packages
66-
"containerEnv": {
67-
"DYNAMO_HOME": "/home/ubuntu/dynamo",
68-
"CARGO_HOME": "/home/ubuntu/dynamo/.build/.cargo",
69-
"RUSTUP_HOME": "/home/ubuntu/dynamo/.build/.rustup",
70-
"CARGO_TARGET_DIR": "/home/ubuntu/dynamo/.build/target"
71-
},
65+
"postCreateCommand": "/bin/bash /workspace/.devcontainer/post-create.sh", // Runs cargo build and pip installs packages
7266
"remoteEnv": {
7367
// Optional convenience tokens passed from host. SSH agent is forwarded via your IDE setting, not here by default.
7468
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}",

container/Dockerfile.local_dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ ENV WORKSPACE_DIR=${WORKSPACE_DIR}
8888
# * Contains rust toolchain binaries that must be at expected system paths
8989
# * Workspace mount point would break rustup's toolchain resolution
9090
# - PATH: Includes cargo binaries for rust tool access
91+
ENV HOME=/home/$USERNAME
9192
ENV DYNAMO_HOME=${WORKSPACE_DIR}
9293
ENV CARGO_TARGET_DIR=${WORKSPACE_DIR}/target
9394
ENV CARGO_HOME=${HOME}/.cargo
@@ -110,7 +111,6 @@ RUN rsync -a --chown=$USER_UID:$USER_GID ${VIRTUAL_ENV}/ /tmp/venv-temp/ && \
110111

111112
# At this point, we are executing as the ubuntu user
112113
USER $USERNAME
113-
ENV HOME=/home/$USERNAME
114114
WORKDIR $HOME
115115

116116
# https://code.visualstudio.com/remote/advancedcontainers/persist-bash-history

0 commit comments

Comments
 (0)