Skip to content

Commit 832b9bb

Browse files
Virtual environment & kernel changes
1 parent 825b45d commit 832b9bb

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

.devcontainer/Dockerfile

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,11 @@ RUN /usr/local/bin/python3.12 -m venv /tmp/venv-template && \
4747
requests setuptools pandas matplotlib pyjwt pytest pytest-cov \
4848
azure.storage.blob azure.identity jupyter ipykernel notebook
4949

50-
# Configure shell to auto-activate virtual environment
51-
RUN echo "# Auto-activate APIM Samples virtual environment" >> ~/.bashrc && \
52-
echo "if [ -f /workspaces/Apim-Samples/.venv/bin/activate ]; then" >> ~/.bashrc && \
53-
echo " source /workspaces/Apim-Samples/.venv/bin/activate" >> ~/.bashrc && \
54-
echo "fi" >> ~/.bashrc && \
55-
echo "# Auto-activate APIM Samples virtual environment" >> ~/.zshrc && \
56-
echo "if [ -f /workspaces/Apim-Samples/.venv/bin/activate ]; then" >> ~/.zshrc && \
57-
echo " source /workspaces/Apim-Samples/.venv/bin/activate" >> ~/.zshrc && \
58-
echo "fi" >> ~/.zshrc && \
50+
# Configure shell environment and helpful aliases (without auto-activating venv)
51+
RUN echo "# Add user local bin to PATH for Jupyter and other tools" >> ~/.bashrc && \
52+
echo "export PATH=\$PATH:/home/vscode/.local/bin" >> ~/.bashrc && \
53+
echo "# Add user local bin to PATH for Jupyter and other tools" >> ~/.zshrc && \
54+
echo "export PATH=\$PATH:/home/vscode/.local/bin" >> ~/.zshrc && \
5955
# Add helpful aliases
6056
echo "alias ll='ls -alF'" >> ~/.bashrc && \
6157
echo "alias la='ls -A'" >> ~/.bashrc && \
@@ -72,7 +68,8 @@ HEALTHCHECK --interval=60s --timeout=5s --start-period=10s --retries=2 \
7268
# Add labels for maintainability
7369
LABEL maintainer="APIM Samples Team" \
7470
description="Optimized dev container for Azure API Management samples with Codespaces prebuild support" \
75-
version="2.2" \
71+
version="2.3" \
7672
python.version="3.12" \
7773
debian.version="bookworm" \
78-
venv.location="/workspaces/Apim-Samples/.venv"
74+
venv.location="/workspaces/Apim-Samples/.venv" \
75+
note="VS Code Python extension handles venv activation to avoid duplicate prompts"

.devcontainer/devcontainer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110
}
111111
},
112112
"containerEnv": {
113-
"PYTHONPATH": "/workspaces/Apim-Samples/shared/python:/workspaces/Apim-Samples"
113+
"PYTHONPATH": "/workspaces/Apim-Samples/shared/python:/workspaces/Apim-Samples",
114+
"PATH": "/workspaces/Apim-Samples/.venv/bin:/home/vscode/.local/bin:${PATH}"
114115
},
115116
// Container lifecycle commands for optimal Codespaces prebuild performance: https://containers.dev/implementors/features/#lifecycle-hooks
116117
// 1. onCreateCommand: Runs only once during initial prebuild - creates venv
@@ -122,7 +123,7 @@
122123
],
123124
"updateContentCommand": [
124125
"bash", "-c",
125-
"echo '📦 Installing/updating Python packages from requirements.txt...' && source /workspaces/Apim-Samples/.venv/bin/activate && pip install -r requirements.txt && pip install pytest pytest-cov coverage ipykernel && echo '✅ Python packages installed/updated' && python setup/setup_python_path.py --generate-env && echo '✅ Environment configuration updated' && echo '🔧 Registering Jupyter kernel...' && python -m ipykernel install --user --name=apim-samples --display-name='APIM Samples Python 3.12' && echo '✅ Jupyter kernel registered' && echo '⚙️ Configuring Azure CLI...' && az config set core.login_experience_v2=off 2>/dev/null || true && az extension add --name containerapp --only-show-errors 2>/dev/null || true && az extension add --name front-door --only-show-errors 2>/dev/null || true && echo '✅ Azure CLI configured for Codespaces'"
126+
"echo '📦 Installing/updating Python packages from requirements.txt...' && source /workspaces/Apim-Samples/.venv/bin/activate && pip install -r requirements.txt && pip install pytest pytest-cov coverage ipykernel && echo '✅ Python packages installed/updated' && python setup/setup_python_path.py --generate-env && echo '✅ Environment configuration updated' && echo '🔧 Registering Jupyter kernel...' && python -m ipykernel install --user --name=apim-samples --display-name='APIM Samples Python 3.12' --python=$(which python) && jupyter kernelspec list | grep apim-samples && echo '✅ Jupyter kernel registered successfully' && echo '⚙️ Configuring Azure CLI...' && az config set core.login_experience_v2=off 2>/dev/null || true && az extension add --name containerapp --only-show-errors 2>/dev/null || true && az extension add --name front-door --only-show-errors 2>/dev/null || true && echo '✅ Azure CLI configured for Codespaces'"
126127
],
127128
"postStartCommand": [
128129
"bash", "-c",

.devcontainer/post-start-setup.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ echo "==========================================================================
1212
echo " 🚀 APIM SAMPLES - INSTANT VERIFICATION "
1313
echo "============================================================================"
1414
echo ""
15-
echo "⚡ All heavy setup completed during prebuild - verifying environment..."
15+
echo "⚡ All heavy setup was completed during prebuild - verifying environment..."
1616
echo ""
1717

1818
# ------------------------------
@@ -55,8 +55,14 @@ if jupyter kernelspec list 2>/dev/null | grep -q "apim-samples"; then
5555
echo " ✅ Jupyter kernel"
5656
else
5757
echo " ⚠️ Jupyter kernel missing (fallback registration...)"
58-
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python 3.12" >/dev/null 2>&1
59-
echo " ✅ Jupyter kernel registered"
58+
# Ensure we're using the right virtual environment
59+
source /workspaces/Apim-Samples/.venv/bin/activate 2>/dev/null || true
60+
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python 3.12" --python="$(which python)" >/dev/null 2>&1
61+
if jupyter kernelspec list 2>/dev/null | grep -q "apim-samples"; then
62+
echo " ✅ Jupyter kernel registered"
63+
else
64+
echo " ⚠️ Jupyter kernel registration failed - using default kernel"
65+
fi
6066
fi
6167

6268
# Calculate total duration

0 commit comments

Comments
 (0)