|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# ------------------------------ |
| 4 | +# PREBUILD OPTIMIZED SETUP |
| 5 | +# ------------------------------ |
| 6 | + |
| 7 | +set -e |
| 8 | + |
| 9 | +echo "🔧 Running prebuild-optimized setup..." |
| 10 | + |
| 11 | +# ------------------------------ |
| 12 | +# PYTHON ENVIRONMENT SETUP |
| 13 | +# ------------------------------ |
| 14 | + |
| 15 | +echo "📦 Installing Python dependencies..." |
| 16 | +pip install --upgrade pip |
| 17 | +pip install -r requirements.txt |
| 18 | + |
| 19 | +# Ensure pytest and coverage tools are available |
| 20 | +pip install pytest pytest-cov coverage |
| 21 | + |
| 22 | +echo "🔧 Setting up Python path configuration..." |
| 23 | +python setup/setup_python_path.py --generate-env |
| 24 | + |
| 25 | +# ------------------------------ |
| 26 | +# AZURE CLI SETUP |
| 27 | +# ------------------------------ |
| 28 | + |
| 29 | +echo "☁️ Configuring Azure CLI..." |
| 30 | +# Set Azure CLI to use device code flow by default in codespaces/containers |
| 31 | +az config set core.login_experience_v2=off 2>/dev/null || true |
| 32 | + |
| 33 | +# Install additional Azure CLI extensions that might be useful |
| 34 | +echo "📥 Installing Azure CLI extensions..." |
| 35 | +az extension add --name containerapp --only-show-errors 2>/dev/null || true |
| 36 | +az extension add --name front-door --only-show-errors 2>/dev/null || true |
| 37 | + |
| 38 | +# ------------------------------ |
| 39 | +# JUPYTER SETUP |
| 40 | +# ------------------------------ |
| 41 | + |
| 42 | +echo "📓 Setting up Jupyter environment..." |
| 43 | +# Install Jupyter kernel (with error handling) |
| 44 | +if python -c "import ipykernel" 2>/dev/null; then |
| 45 | + python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python" || echo "⚠️ Warning: Failed to install Jupyter kernel, but continuing..." |
| 46 | +else |
| 47 | + echo "⚠️ Warning: ipykernel not found. Installing it now..." |
| 48 | + pip install ipykernel |
| 49 | + python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python" || echo "⚠️ Warning: Failed to install Jupyter kernel, but continuing..." |
| 50 | +fi |
| 51 | + |
| 52 | +# ------------------------------ |
| 53 | +# WORKSPACE CONFIGURATION |
| 54 | +# ------------------------------ |
| 55 | + |
| 56 | +echo "🛠️ Configuring workspace settings..." |
| 57 | + |
| 58 | +# Create .vscode directory if it doesn't exist |
| 59 | +mkdir -p .vscode |
| 60 | + |
| 61 | +# Create settings.json for the workspace |
| 62 | +cat > .vscode/settings.json << 'EOF' |
| 63 | +{ |
| 64 | + "python.terminal.activateEnvironment": true, |
| 65 | + "python.defaultInterpreterPath": "/usr/local/bin/python", |
| 66 | + "python.analysis.extraPaths": [ |
| 67 | + "/workspaces/Apim-Samples/shared/python" |
| 68 | + ], |
| 69 | + "jupyter.kernels.filter": [ |
| 70 | + { |
| 71 | + "path": "/usr/local/bin/python", |
| 72 | + "type": "pythonEnvironment" |
| 73 | + } |
| 74 | + ], |
| 75 | + "files.associations": { |
| 76 | + "*.bicep": "bicep" |
| 77 | + }, |
| 78 | + "python.envFile": "${workspaceFolder}/.env" |
| 79 | +} |
| 80 | +EOF |
| 81 | + |
| 82 | +# ------------------------------ |
| 83 | +# PREBUILD COMPLETION MARKER |
| 84 | +# ------------------------------ |
| 85 | + |
| 86 | +echo "✅ Creating prebuild completion marker..." |
| 87 | +echo "$(date): Prebuild setup completed" > .devcontainer/.prebuild-complete |
| 88 | + |
| 89 | +echo "🎉 Prebuild setup complete!" |
| 90 | + |
| 91 | +echo "✅ Verifying installation..." |
| 92 | +echo "Python version: $(python --version)" |
| 93 | +echo "Azure CLI version: $(az --version | head -1)" |
| 94 | +echo "Pip packages installed:" |
| 95 | +pip list | grep -E "(requests|pandas|matplotlib|pytest|azure|jwt|jupyter|ipykernel)" || true |
| 96 | + |
| 97 | +echo "📋 Prebuild optimization complete!" |
0 commit comments