Add Dockerfile and update devcontainer configuration for Python envir…#704
Add Dockerfile and update devcontainer configuration for Python envir…#704SteveCInVA wants to merge 1 commit intoDevelopmentfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the devcontainer and Azure deployment hooks to use a repo-local virtual environment (.venv) for Python dependency installation, and adds a small docs improvement for Bicep-based deployment setup.
Changes:
- Switch devcontainer from a prebuilt Python image to a custom Dockerfile, and create/install dependencies into
.venv. - Update
deployers/azure.yamlto create a.venvand run postconfig using the venv interpreter. - Add an
az loginstep to the Bicep deployment README.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
deployers/bicep/README.md |
Adds an az login step before azd auth login (contains a small typo). |
deployers/azure.yaml |
Creates a Python venv for deployment-time scripting and runs postconfig.py from it. |
.devcontainer/devcontainer.json |
Switches devcontainer to build from local Dockerfile and installs dependencies into .venv. |
.devcontainer/Dockerfile |
New Dockerfile that installs xz-utils on top of a base Ubuntu devcontainers image. |
Comments suppressed due to low confidence (1)
.devcontainer/devcontainer.json:19
- The base image in the custom devcontainer Dockerfile is
devcontainers/base:ubuntu, so you rely entirely on thepythonfeature for installing Python. If you need a specific Python version (3.11 perVARIANT), pin it in the feature config; otherwise developers may end up with a different default Python version than intended.
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest"
},
"ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/devcontainers-extra/features/black:2": {},
|
|
||
| `azd config set cloud.name AzureCloud` - If you work with other Azure clouds, you may need to update your cloud like `azd config set cloud.name AzureUSGovernment` - more information here - [Use Azure Developer CLI in sovereign clouds | Microsoft Learn](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/sovereign-clouds) | ||
|
|
||
| `az login` - this will open a browser window shta the user with Owner level permissions to the target subscription will need to authenticate with. |
There was a problem hiding this comment.
Typo in the az login description: "shta" should be "that" (and the sentence could be tightened for clarity).
| `az login` - this will open a browser window shta the user with Owner level permissions to the target subscription will need to authenticate with. | |
| `az login` - opens a browser window where a user with Owner level permissions to the target subscription must authenticate. |
| "build": { | ||
| "dockerfile": "Dockerfile", | ||
| "args": { | ||
| "VARIANT": "3.11" | ||
| } | ||
| }, |
There was a problem hiding this comment.
VARIANT build arg is set here but the .devcontainer/Dockerfile never declares/uses ARG VARIANT, so this currently has no effect (and doesn't actually pin the Python version). Either use a Python base image keyed off VARIANT, or remove this arg and configure the Python feature version explicitly.
| @@ -0,0 +1,3 @@ | |||
| FROM mcr.microsoft.com/devcontainers/base:ubuntu | |||
| # Install the xz-utils package | |||
| RUN apt-get update && apt-get install -y xz-utils No newline at end of file | |||
There was a problem hiding this comment.
Consider cleaning up apt metadata to keep the devcontainer image smaller and more reproducible (e.g., --no-install-recommends and removing /var/lib/apt/lists/* after install).
| RUN apt-get update && apt-get install -y xz-utils | |
| RUN apt-get update \ | |
| && apt-get install -y --no-install-recommends xz-utils \ | |
| && rm -rf /var/lib/apt/lists/* |
| echo "" | ||
| echo "[3/4] Running post-deployment configuration..." | ||
| if python3 ./bicep/postconfig.py; then | ||
| if .venv/bin/python3 ./bicep/postconfig.py; then |
There was a problem hiding this comment.
For consistency/portability, prefer invoking the venv interpreter as .venv/bin/python (not python3). Some venvs only guarantee python exists, and your devcontainer config also points VS Code at .venv/bin/python.
| if .venv/bin/python3 ./bicep/postconfig.py; then | |
| if .venv/bin/python ./bicep/postconfig.py; then |
| if python3 -m venv .venv && .venv/bin/pip install -r ./bicep/requirements.txt > /dev/null 2>&1; then | ||
| echo "✓ Dependencies installed successfully" | ||
| else | ||
| echo "✗ ERROR: Failed to install Python dependencies" >&2 |
There was a problem hiding this comment.
This redirects all output (including venv creation failures) to /dev/null, which will make deployment failures harder to diagnose now that python3 -m venv is part of the command chain. Consider only silencing successful pip install output and printing captured stderr/stdout on failure.
| if python3 -m venv .venv && .venv/bin/pip install -r ./bicep/requirements.txt > /dev/null 2>&1; then | |
| echo "✓ Dependencies installed successfully" | |
| else | |
| echo "✗ ERROR: Failed to install Python dependencies" >&2 | |
| if python3 -m venv .venv; then | |
| if pip_output=$(.venv/bin/pip install -r ./bicep/requirements.txt 2>&1); then | |
| echo "✓ Dependencies installed successfully" | |
| else | |
| echo "$pip_output" >&2 | |
| echo "✗ ERROR: Failed to install Python dependencies" >&2 | |
| exit 1 | |
| fi | |
| else | |
| echo "✗ ERROR: Failed to create Python virtual environment" >&2 |
This pull request updates the development container and deployment scripts to improve Python environment management and dependency installation. The main changes include switching to a custom Dockerfile for the dev container, ensuring dependencies are installed in a virtual environment, and updating post-deployment commands to consistently use the virtual environment's Python interpreter.
Development environment improvements:
.devcontainer/Dockerfile), which now installs thexz-utilspackage. [1] [2].venv) for dependency management. ThepostCreateCommandnow creates a virtual environment and installs requirements into it, and VS Code is configured to use the virtual environment's Python interpreter by default (.devcontainer/devcontainer.json). [1] [2] [3]Deployment script improvements:
deployers/azure.yaml). [1] [2]Documentation:
az loginbefore authenticating withazd(deployers/bicep/README.md)