Unverified Commit e3068d61 authored by Keiven C's avatar Keiven C Committed by GitHub
Browse files

refactor: post-create.sh DYNAMO_HOME refactor that works with the devcontainer.json … (#3167)


Signed-off-by: default avatarKeiven Chang <keivenchang@users.noreply.github.com>
parent 031590fc
......@@ -4,6 +4,9 @@
set -eu
# Set DYNAMO_HOME if not already set
export DYNAMO_HOME=${DYNAMO_HOME:-/home/ubuntu/dynamo}
# Ensure we're not running as root
if [ "$(id -u)" -eq 0 ]; then
echo "❌ ERROR: This script should not be run as root!"
......@@ -40,14 +43,21 @@ retry() {
return 0
}
show_and_run() {
# Run commands with debug output shown
set -x
"$@"
{ set +x; } 2>/dev/null
}
set -x
# Pre-commit hooks
cd $HOME/dynamo && pre-commit install && retry pre-commit install-hooks
cd $DYNAMO_HOME && pre-commit install && retry pre-commit install-hooks
pre-commit run --all-files || true # don't fail the build if pre-commit hooks fail
# Set build directory
export CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-$HOME/dynamo/.build/target}
export CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-$DYNAMO_HOME/.build/target}
mkdir -p $CARGO_TARGET_DIR
uv pip uninstall --yes ai-dynamo ai-dynamo-runtime 2>/dev/null || true
......@@ -67,29 +77,46 @@ cargo build --locked --profile dev --features mistralrs
# echo "maturin is already installed"
# fi
(cd $HOME/dynamo/lib/bindings/python && retry maturin develop)
(cd $DYNAMO_HOME/lib/bindings/python && retry maturin develop)
# installs overall python packages, grabs binaries from .build/target/debug
cd $HOME/dynamo && retry env DYNAMO_BIN_PATH=$CARGO_TARGET_DIR/debug uv pip install -e .
# Extract the PYTHONPATH line from README.md
PYTHONPATH_LINE=$(grep "^export PYTHONPATH=" $DYNAMO_HOME/README.md | head -n1)
if [ -n "$PYTHONPATH_LINE" ]; then
# Remove the ${PYTHONPATH}: prefix if it exists, then replace $(pwd) with the actual path
MODIFIED_LINE=$(echo "$PYTHONPATH_LINE" | sed 's/\${PYTHONPATH}://g' | sed "s|\$(pwd)|$DYNAMO_HOME|g")
eval "$MODIFIED_LINE"
# Also add to .bashrc for persistence (with expanded path)
cd $DYNAMO_HOME && retry env DYNAMO_BIN_PATH=$CARGO_TARGET_DIR/debug uv pip install -e .
echo -e "\n" >> ~/.bashrc
echo "# === This section is generated by the post-create.sh script ===" >> ~/.bashrc
{ set +x; } 2>/dev/null
# Check if PYTHONPATH is already set in environment
if [ -n "$PYTHONPATH" ]; then
# PYTHONPATH exists, replace /workspace with $DYNAMO_HOME
export PYTHONPATH=$(echo "$PYTHONPATH" | sed "s|/workspace|$DYNAMO_HOME|g")
# Also add to .bashrc for persistence
if ! grep -q "export PYTHONPATH=" ~/.bashrc; then
# MODIFIED_LINE already has $DYNAMO_HOME expanded to /home/ubuntu/dynamo
echo "$MODIFIED_LINE" >> ~/.bashrc
echo "# PYTHONPATH modified from /workspace to use DYNAMO_HOME" >> ~/.bashrc
show_and_run echo "export PYTHONPATH=\"$PYTHONPATH\"" >> ~/.bashrc
fi
else
# Back-up version if README.md changed. This is the version from 2025-08-19
export PYTHONPATH=$DYNAMO_HOME/components/frontend/src:$DYNAMO_HOME/components/planner/src:$DYNAMO_HOME/components/backends/vllm/src:$DYNAMO_HOME/components/backends/sglang/src:$DYNAMO_HOME/components/backends/trtllm/src:$DYNAMO_HOME/components/backends/llama_cpp/src:$DYNAMO_HOME/components/backends/mocker/src
# PYTHONPATH not set, extract from README.md or use backup
PYTHONPATH_LINE=$(grep "^export PYTHONPATH=" $DYNAMO_HOME/README.md | head -n1)
if [ -n "$PYTHONPATH_LINE" ]; then
# Remove the ${PYTHONPATH}: prefix if it exists, then replace $(pwd) with the actual path
MODIFIED_LINE=$(echo "$PYTHONPATH_LINE" | sed 's/\${PYTHONPATH}://g' | sed "s|\$(pwd)|$DYNAMO_HOME|g")
eval "$MODIFIED_LINE"
# Also add to .bashrc for persistence (with expanded path)
if ! grep -q "export PYTHONPATH=" ~/.bashrc; then
# MODIFIED_LINE already has $DYNAMO_HOME expanded to /home/ubuntu/dynamo
echo "# PYTHONPATH is derived from the README.md" >> ~/.bashrc
show_and_run echo "$MODIFIED_LINE" >> ~/.bashrc
fi
else
# Back-up version. Make sure to sync this with the README.md's PYTHONPATH. This is the version from 2025-08-19
show_and_run export PYTHONPATH=$DYNAMO_HOME/components/frontend/src:$DYNAMO_HOME/components/planner/src:$DYNAMO_HOME/components/backends/vllm/src:$DYNAMO_HOME/components/backends/sglang/src:$DYNAMO_HOME/components/backends/trtllm/src:$DYNAMO_HOME/components/backends/llama_cpp/src:$DYNAMO_HOME/components/backends/mocker/src
fi
fi
if ! grep -q "export GPG_TTY=" ~/.bashrc; then
echo "export GPG_TTY=$(tty)" >> ~/.bashrc
show_and_run echo 'export GPG_TTY=$(tty)' >> ~/.bashrc
fi
# Unset empty tokens/variables to avoid issues with authentication and SSH
......@@ -100,10 +127,6 @@ if ! grep -q "# Unset empty tokens" ~/.bashrc; then
echo '[ -z "$SSH_AUTH_SOCK" ] && unset SSH_AUTH_SOCK' >> ~/.bashrc
fi
$HOME/dynamo/deploy/dynamo_check.py
{ set +x; } 2>/dev/null
# Check SSH agent forwarding status
if [ -n "$SSH_AUTH_SOCK" ]; then
if ssh-add -l > /dev/null 2>&1; then
......@@ -116,6 +139,8 @@ else
echo "⚠️ SSH agent forwarding not configured - SSH_AUTH_SOCK is not set"
fi
show_and_run $DYNAMO_HOME/deploy/dynamo_check.py
cat <<EOF
✅ SUCCESS: Built cargo project, installed Python bindings, configured pre-commit hooks
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment