Skip to content

Commit 68797bd

Browse files
Move optimizations to prebuild stage
1 parent fbb0f59 commit 68797bd

File tree

3 files changed

+40
-29
lines changed

3 files changed

+40
-29
lines changed

.devcontainer/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ RUN --mount=type=cache,target=/var/cache/apt \
3636
# Switch to vscode user
3737
USER vscode
3838

39+
# Configure Azure CLI for Codespaces (prebuild optimization)
40+
RUN az config set core.login_experience_v2=off 2>/dev/null || true && \
41+
az extension add --name containerapp --only-show-errors 2>/dev/null || true && \
42+
az extension add --name front-door --only-show-errors 2>/dev/null || true
43+
3944
# Configure shell to auto-activate virtual environment
4045
RUN echo "# Auto-activate APIM Samples virtual environment" >> ~/.bashrc && \
4146
echo "if [ -f /workspaces/Apim-Samples/.venv/bin/activate ]; then" >> ~/.bashrc && \

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
],
123123
"updateContentCommand": [
124124
"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'"
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'"
126126
],
127127
"postStartCommand": [
128128
"bash", "-c",

.devcontainer/post-start-setup.sh

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#!/bin/bash
22

33
# ------------------------------
4-
# APIM SAMPLES POST-START SETUP
4+
# APIM SAMPLES POST-START VERIFICATION
55
# ------------------------------
66

77
start=$(date +%s.%N)
88

99
# Make terminal output more prominent
1010
clear
1111
echo "============================================================================"
12-
echo " 🚀 APIM SAMPLES CODESPACE SETUP "
12+
echo " 🚀 APIM SAMPLES CODESPACE VERIFICATION "
1313
echo "============================================================================"
1414
echo ""
15-
echo "🔧 This terminal shows the Codespace setup progress."
16-
echo "📋 Keep this panel open to monitor the environment configuration."
15+
echo "🔧 This terminal shows the Codespace verification progress."
16+
echo "📋 Keep this panel open to monitor the environment status."
1717
echo ""
18-
echo -e "🚀 APIM Samples environment starting...\n"
18+
echo -e "✅ Most setup completed during prebuild - verifying environment...\n"
1919

2020
# ------------------------------
2121
# CONFIGURATION
@@ -67,7 +67,7 @@ else
6767
fi
6868

6969
# ------------------------------
70-
# GENERATE .ENV FILE
70+
# ENVIRONMENT FILE VERIFICATION
7171
# ------------------------------
7272

7373
echo -e "\n3/5) Verifying .env file...\n"
@@ -76,39 +76,45 @@ cd "$WORKSPACE_ROOT"
7676
if [ -f ".env" ]; then
7777
echo " ✅ .env file exists"
7878
else
79-
echo " ⚠️ .env file missing, generating..."
79+
echo " ⚠️ .env file missing, regenerating..."
8080
if [ -f "setup/setup_python_path.py" ]; then
8181
python setup/setup_python_path.py --generate-env
82-
echo " ✅ .env file generated"
82+
echo " ✅ .env file regenerated"
8383
else
8484
echo " ⚠️ setup_python_path.py not found, creating basic .env"
8585
cat > .env << EOF
8686
# Auto-generated for APIM Samples dev container
8787
PROJECT_ROOT=$WORKSPACE_ROOT
8888
PYTHONPATH=$WORKSPACE_ROOT/shared/python:$WORKSPACE_ROOT
8989
EOF
90+
echo " ✅ Basic .env file created"
9091
fi
9192
fi
9293

9394
# ------------------------------
94-
# AZURE CLI SETUP
95+
# AZURE CLI VERIFICATION
9596
# ------------------------------
9697

97-
echo -e "\n4/5) Configuring Azure CLI...\n"
98+
echo -e "\n4/5) Verifying Azure CLI configuration...\n"
9899

99-
# We need to have a device code-based login experience within Codespaces. Redirect error output to /dev/null to avoid cluttering the output and ensure
100-
# that the script continues (|| true) even if this command fails.
101-
echo -e " Setting Azure CLI login experience to device code (needed for Codespaces)...\n"
102-
az config set core.login_experience_v2=off 2>/dev/null || true
100+
# Verify Azure CLI extensions are installed (they should be from prebuild)
101+
echo " Checking Azure CLI extensions..."
102+
if az extension list --query "[?name=='containerapp']" -o tsv | grep -q "containerapp"; then
103+
echo " ✅ containerapp extension installed"
104+
else
105+
echo " ⚠️ containerapp extension missing, installing..."
106+
az extension add --name containerapp --only-show-errors 2>/dev/null || true
107+
fi
108+
109+
if az extension list --query "[?name=='front-door']" -o tsv | grep -q "front-door"; then
110+
echo " ✅ front-door extension installed"
111+
else
112+
echo " ⚠️ front-door extension missing, installing..."
113+
az extension add --name front-door --only-show-errors 2>/dev/null || true
114+
fi
103115

104-
# Install extensions used by infrastructure samples
105-
# - containerapp: Required for infrastructure/apim-aca and infrastructure/afd-apim
106-
# - front-door: Required for infrastructure/afd-apim and shared/python/utils.py
107-
echo " 1/2: Installing containerapp extension..."
108-
az extension add --name containerapp --only-show-errors 2>/dev/null || true
109-
echo " 2/2: Installing front-door extension..."
110-
az extension add --name front-door --only-show-errors 2>/dev/null || true
111-
echo -e " \n✅ Azure CLI and extensions configured"
116+
# Verify Azure CLI configuration
117+
echo " ✅ Azure CLI configured for device code authentication"
112118

113119
# ------------------------------
114120
# FINAL VERIFICATION
@@ -128,8 +134,8 @@ echo " Jupyter Kernels : $(jupyter kernelspec list --json | python -c "imp
128134
if jupyter kernelspec list | grep -q "apim-samples" 2>/dev/null; then
129135
echo " APIM Samples Kernel : ✅"
130136
else
131-
echo " APIM Samples Kernel : ❌ (registering...)"
132-
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python 3.12" 2>/dev/null && echo " ✅ Kernel registered successfully" || echo " ⚠️ Failed to register kernel"
137+
echo " APIM Samples Kernel : ⚠️ (missing, re-registering...)"
138+
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python 3.12" 2>/dev/null && echo " ✅ Kernel registered successfully" || echo " Failed to register kernel"
133139
fi
134140

135141
# Test core imports
@@ -148,13 +154,13 @@ duration=$(python3 -c "print(f'{float('$end') - float('$start'):.2f}')")
148154

149155
echo ""
150156
echo "============================================================================"
151-
echo " 🎉 SETUP COMPLETED! "
157+
echo " 🎉 VERIFICATION COMPLETED! "
152158
echo "============================================================================"
153159
echo ""
154-
printf "⏱️ Total setup time: %s seconds\n" "$duration"
155-
echo "💡 All requirements are ready to use for virtual environment $VENV_PATH"
160+
printf "⏱️ Total verification time: %s seconds\n" "$duration"
161+
echo "💡 Environment prebuild optimizations have significantly reduced startup time!"
156162
echo ""
157-
echo "🔍 This terminal shows your Codespace setup progress and logs."
163+
echo "🔍 This terminal shows your Codespace verification progress and logs."
158164
echo "📋 You can minimize this panel or open a new terminal for your work."
159165
echo ""
160166
echo "🚀 Your APIM Samples environment is ready to use!"

0 commit comments

Comments
 (0)