Skip to content

Commit 4793069

Browse files
committed
Add entrypoint script to auto-activate venv in Docker
The entrypoint script ensures the virtual environment is properly activated for all commands, not just interactive shells. This fixes the issue where 'docker run' commands wouldn't have VIRTUAL_ENV set. The entrypoint: 1. Detects the architecture-specific venv path 2. Sources the venv's activate script 3. Executes the user's command with 'exec'
1 parent 19dda8d commit 4793069

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Dockerfile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,29 @@ RUN chmod +x /workspace/reproduce/docker/setup.sh && \
4242

4343
# Set runtime environment
4444
# Note: The actual venv path depends on architecture (e.g., .venv-linux-x86_64 or .venv-linux-aarch64)
45-
# We add both possible paths to ensure the correct one is found
4645
ENV PATH="/workspace/.venv-linux-x86_64/bin:/workspace/.venv-linux-aarch64/bin:/home/vscode/.local/bin:$PATH"
4746
ENV PYTHONPATH="/workspace/code"
4847

48+
# Create entrypoint script that activates the venv
49+
RUN echo '#!/bin/bash' > /home/vscode/entrypoint.sh && \
50+
echo 'set -e' >> /home/vscode/entrypoint.sh && \
51+
echo '' >> /home/vscode/entrypoint.sh && \
52+
echo '# Determine architecture-specific venv path' >> /home/vscode/entrypoint.sh && \
53+
echo 'ARCH=$(uname -m)' >> /home/vscode/entrypoint.sh && \
54+
echo 'VENV_PATH="/workspace/.venv-linux-$ARCH"' >> /home/vscode/entrypoint.sh && \
55+
echo '' >> /home/vscode/entrypoint.sh && \
56+
echo '# Activate venv if it exists' >> /home/vscode/entrypoint.sh && \
57+
echo 'if [ -f "$VENV_PATH/bin/activate" ]; then' >> /home/vscode/entrypoint.sh && \
58+
echo ' source "$VENV_PATH/bin/activate"' >> /home/vscode/entrypoint.sh && \
59+
echo 'fi' >> /home/vscode/entrypoint.sh && \
60+
echo '' >> /home/vscode/entrypoint.sh && \
61+
echo '# Execute the command' >> /home/vscode/entrypoint.sh && \
62+
echo 'exec "$@"' >> /home/vscode/entrypoint.sh && \
63+
chmod +x /home/vscode/entrypoint.sh
64+
4965
# Expose common ports
5066
EXPOSE 8888 8866
5167

52-
# Default command
68+
# Use entrypoint to activate venv, then run command
69+
ENTRYPOINT ["/home/vscode/entrypoint.sh"]
5370
CMD ["/bin/bash"]

0 commit comments

Comments
 (0)