Skip to content

Commit 73f38ef

Browse files
Add Dev Container
#37
1 parent cf9767b commit 73f38ef

File tree

7 files changed

+524
-1
lines changed

7 files changed

+524
-1
lines changed

.devcontainer/README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Dev Container for APIM Samples
2+
3+
This directory contains the GitHub Dev Container configuration for the APIM Samples repository, providing a complete development environment with all necessary prerequisites.
4+
5+
## 🚀 Quick Start
6+
7+
### Using GitHub Codespaces
8+
9+
1. Navigate to the repository on GitHub
10+
2. Click the green "Code" button
11+
3. Select "Codespaces" tab
12+
4. Click "Create codespace on main"
13+
5. Wait for the environment to build and initialize
14+
15+
### Using VS Code Dev Containers
16+
17+
1. Install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
18+
2. Open the repository in VS Code
19+
3. When prompted, click "Reopen in Container" or use Command Palette: "Dev Containers: Reopen in Container"
20+
4. Wait for the container to build and initialize
21+
22+
## 📦 What's Included
23+
24+
### Core Tools
25+
- **Python 3.12** - Primary development runtime
26+
- **Azure CLI** - Latest version with useful extensions pre-installed
27+
- **Git** - Version control with enhanced configuration
28+
29+
### VS Code Extensions
30+
- **Python** - Full Python development support
31+
- **Jupyter** - Complete Jupyter notebook support with renderers and tools
32+
- **Azure Bicep** - Infrastructure as Code support
33+
- **Azure CLI Tools** - Enhanced Azure development experience
34+
- **GitHub Copilot** - AI-powered coding assistance (if licensed)
35+
- **YAML & JSON** - Configuration file support
36+
37+
### Python Packages
38+
All packages from `requirements.txt` are pre-installed:
39+
- `requests` - HTTP library
40+
- `pandas` - Data manipulation
41+
- `matplotlib` - Data visualization
42+
- `pyjwt` - JWT token handling
43+
- `pytest` & `pytest-cov` - Testing framework
44+
- `azure.storage.blob` & `azure.identity` - Azure SDK components
45+
46+
### Environment Configuration
47+
- **PYTHONPATH** - Automatically configured to include shared Python modules
48+
- **Jupyter Kernel** - Custom kernel named "APIM Samples Python"
49+
- **Azure CLI** - Configured for container-friendly authentication
50+
- **Port Forwarding** - Common development ports (3000, 5000, 8000, 8080) pre-configured
51+
52+
## 🔧 Post-Setup Steps
53+
54+
After the container starts, you'll need to:
55+
56+
1. **Sign in to Azure**:
57+
```bash
58+
az login
59+
```
60+
61+
2. **Verify your Azure setup**:
62+
Execute `shared/jupyter/verify-az-account.ipynb`
63+
64+
3. **Start exploring**:
65+
- Navigate to any infrastructure folder (`infrastructure/`)
66+
- Run the `create.ipynb` notebook to set up infrastructure
67+
- Explore samples in the `samples/` directory
68+
69+
## 🏗️ Architecture
70+
71+
The dev container is built on:
72+
- **Base Image**: `mcr.microsoft.com/devcontainers/python:1-3.12-bullseye`
73+
- **Features**: Azure CLI, Common utilities with Zsh/Oh My Zsh
74+
- **Workspace**: Mounted at `/workspaces/Apim-Samples`
75+
- **User**: `vscode` with proper permissions
76+
77+
## 🔄 Azure CLI Authentication
78+
79+
The container mounts your local `~/.azure` directory to preserve authentication state between container rebuilds. This means:
80+
- Your Azure login persists across sessions
81+
- Your Azure CLI configuration is maintained
82+
- No need to repeatedly authenticate
83+
84+
## 🐛 Troubleshooting
85+
86+
### Python Path Issues
87+
If you encounter import errors:
88+
```bash
89+
python setup/setup_python_path.py --generate-env
90+
```
91+
92+
### Jupyter Kernel Not Found
93+
Restart VS Code or refresh the Jupyter kernel list:
94+
- Command Palette → "Jupyter: Refresh Kernels"
95+
96+
### Azure CLI Issues
97+
Check Azure CLI status:
98+
```bash
99+
az account show
100+
az account list
101+
```
102+
103+
### Container Rebuild
104+
If you need to rebuild the container:
105+
- Command Palette → "Dev Containers: Rebuild Container"
106+
107+
## 🔒 Security Considerations
108+
109+
- Azure credentials are mounted from your local machine
110+
- The container runs as a non-root user (`vscode`)
111+
- All dependencies are installed from official sources
112+
- Network access is controlled through VS Code's port forwarding
113+
114+
## 🤝 Contributing
115+
116+
When modifying the dev container configuration:
117+
1. Test changes locally first
118+
2. Update this README if adding new tools or changing behavior
119+
3. Consider backward compatibility for existing users
120+
4. Document any new environment variables or configuration options

.devcontainer/devcontainer.json

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"name": "APIM Samples Development Environment",
3+
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
4+
5+
"features": {
6+
"ghcr.io/devcontainers/features/azure-cli:1": {
7+
"version": "latest"
8+
},
9+
"ghcr.io/devcontainers/features/common-utils:2": {
10+
"installZsh": true,
11+
"configureZshAsDefaultShell": true,
12+
"installOhMyZsh": true,
13+
"upgradePackages": true,
14+
"username": "vscode",
15+
"uid": "1000",
16+
"gid": "1000"
17+
},
18+
"ghcr.io/devcontainers/features/git:1": {
19+
"version": "latest",
20+
"ppa": true
21+
}
22+
},
23+
24+
"customizations": {
25+
"vscode": {
26+
"extensions": [
27+
"ms-python.python",
28+
"ms-python.debugpy",
29+
"ms-toolsai.jupyter",
30+
"ms-toolsai.jupyter-keymap",
31+
"ms-toolsai.jupyter-renderers",
32+
"ms-toolsai.vscode-jupyter-cell-tags",
33+
"ms-toolsai.vscode-jupyter-slideshow",
34+
"ms-azuretools.vscode-bicep",
35+
"ms-vscode.azurecli",
36+
"ms-azure-devops.azure-pipelines",
37+
"GitHub.copilot",
38+
"GitHub.copilot-chat",
39+
"redhat.vscode-yaml",
40+
"ms-vscode.vscode-json"
41+
],
42+
"settings": {
43+
"python.defaultInterpreterPath": "/usr/local/bin/python",
44+
"python.linting.enabled": true,
45+
"python.linting.pylintEnabled": true,
46+
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
47+
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
48+
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
49+
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
50+
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
51+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
52+
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
53+
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
54+
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
55+
"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest",
56+
"jupyter.askForKernelRestart": false,
57+
"jupyter.interactiveWindow.textEditor.executeSelection": true,
58+
"files.associations": {
59+
"*.bicep": "bicep"
60+
}
61+
}
62+
}
63+
},
64+
65+
"containerEnv": {
66+
"PYTHONPATH": "/workspaces/Apim-Samples/shared/python"
67+
},
68+
69+
"postCreateCommand": "bash .devcontainer/setup.sh",
70+
71+
"forwardPorts": [
72+
8000,
73+
8080,
74+
5000,
75+
3000
76+
],
77+
78+
"portsAttributes": {
79+
"8000": {
80+
"label": "Python Development Server",
81+
"onAutoForward": "notify"
82+
},
83+
"8080": {
84+
"label": "Alternative HTTP Server",
85+
"onAutoForward": "notify"
86+
},
87+
"5000": {
88+
"label": "Flask Development Server",
89+
"onAutoForward": "notify"
90+
},
91+
"3000": {
92+
"label": "Node.js Development Server",
93+
"onAutoForward": "notify"
94+
}
95+
},
96+
97+
"remoteUser": "vscode",
98+
"workspaceFolder": "/workspaces/Apim-Samples",
99+
100+
"mounts": [
101+
"source=${localEnv:HOME}/.azure,target=/home/vscode/.azure,type=bind,consistency=cached"
102+
]
103+
}

.devcontainer/setup.ps1

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# PowerShell Setup Script for APIM Samples Dev Container
2+
# This script mirrors the functionality of setup.sh for Windows environments
3+
4+
# ------------------------------
5+
# DEVCONTAINER SETUP SCRIPT
6+
# ------------------------------
7+
8+
Write-Host "🚀 Setting up APIM Samples development environment..." -ForegroundColor Green
9+
10+
# ------------------------------
11+
# PYTHON ENVIRONMENT SETUP
12+
# ------------------------------
13+
14+
Write-Host "📦 Installing Python dependencies..." -ForegroundColor Yellow
15+
python -m pip install --upgrade pip
16+
pip install -r requirements.txt
17+
18+
# Ensure pytest and coverage tools are available
19+
pip install pytest pytest-cov coverage
20+
21+
Write-Host "🔧 Setting up Python path configuration..." -ForegroundColor Yellow
22+
python setup/setup_python_path.py --generate-env
23+
24+
# ------------------------------
25+
# AZURE CLI SETUP
26+
# ------------------------------
27+
28+
Write-Host "☁️ Configuring Azure CLI..." -ForegroundColor Yellow
29+
# Set Azure CLI to use device code flow by default in codespaces/containers
30+
try {
31+
az config set core.login_experience_v2=off 2>$null
32+
} catch {
33+
# Ignore errors if config setting fails
34+
}
35+
36+
# Install additional Azure CLI extensions that might be useful
37+
Write-Host "📥 Installing Azure CLI extensions..." -ForegroundColor Yellow
38+
try {
39+
az extension add --name containerapp --only-show-errors 2>$null
40+
az extension add --name front-door --only-show-errors 2>$null
41+
} catch {
42+
Write-Host "⚠️ Some Azure CLI extensions could not be installed" -ForegroundColor Yellow
43+
}
44+
45+
# ------------------------------
46+
# JUPYTER SETUP
47+
# ------------------------------
48+
49+
Write-Host "📓 Setting up Jupyter environment..." -ForegroundColor Yellow
50+
# Install Jupyter kernel
51+
python -m ipykernel install --user --name=apim-samples --display-name="APIM Samples Python"
52+
53+
# ------------------------------
54+
# WORKSPACE CONFIGURATION
55+
# ------------------------------
56+
57+
Write-Host "🛠️ Configuring workspace settings..." -ForegroundColor Yellow
58+
59+
# Create .vscode directory if it doesn't exist
60+
if (-not (Test-Path ".vscode")) {
61+
New-Item -ItemType Directory -Path ".vscode" -Force
62+
}
63+
64+
# Create settings.json for the workspace
65+
$settingsJson = @'
66+
{
67+
"python.terminal.activateEnvironment": true,
68+
"python.defaultInterpreterPath": "python",
69+
"jupyter.kernels.filter": [
70+
{
71+
"path": "python",
72+
"type": "pythonEnvironment"
73+
}
74+
],
75+
"files.associations": {
76+
"*.bicep": "bicep"
77+
},
78+
"python.envFile": "${workspaceFolder}/.env"
79+
}
80+
'@
81+
82+
$settingsJson | Out-File -FilePath ".vscode/settings.json" -Encoding UTF8
83+
84+
# ------------------------------
85+
# FINAL VERIFICATION
86+
# ------------------------------
87+
88+
Write-Host "✅ Verifying installation..." -ForegroundColor Green
89+
90+
Write-Host "Python version:" -ForegroundColor Cyan
91+
python --version
92+
93+
Write-Host "Azure CLI version:" -ForegroundColor Cyan
94+
$azVersion = az --version | Select-Object -First 1
95+
Write-Host $azVersion
96+
97+
Write-Host "Pip packages installed:" -ForegroundColor Cyan
98+
pip list | Select-String -Pattern "(requests|pandas|matplotlib|pytest|azure|jwt)"
99+
100+
Write-Host "🎉 Development environment setup complete!" -ForegroundColor Green
101+
Write-Host ""
102+
Write-Host "📋 Next steps:" -ForegroundColor Yellow
103+
Write-Host "1. Sign in to Azure: az login"
104+
Write-Host "2. Execute shared/jupyter/verify-az-account.ipynb to verify your Azure setup"
105+
Write-Host "3. Navigate to any infrastructure folder and run the create.ipynb notebook"
106+
Write-Host "4. Explore the samples in the samples/ directory"
107+
Write-Host ""
108+
Write-Host "💡 Tip: The Python path has been configured to include shared/python modules automatically." -ForegroundColor Cyan

0 commit comments

Comments
 (0)