Skip to content

Add Dockerfile and update devcontainer configuration for Python envir…#704

Open
SteveCInVA wants to merge 1 commit intoDevelopmentfrom
sc-DevContainerFix
Open

Add Dockerfile and update devcontainer configuration for Python envir…#704
SteveCInVA wants to merge 1 commit intoDevelopmentfrom
sc-DevContainerFix

Conversation

@SteveCInVA
Copy link
Collaborator

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:

  • Switched the dev container setup from using a prebuilt Python image to building from a custom Dockerfile (.devcontainer/Dockerfile), which now installs the xz-utils package. [1] [2]
  • Updated the devcontainer configuration to build with a specific Python version, and set up the Python virtual environment (.venv) for dependency management. The postCreateCommand now 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:

  • Modified the Azure deployment hook to install Python dependencies into a virtual environment instead of user space, and ensured post-deployment scripts are run using the virtual environment's Python interpreter (deployers/azure.yaml). [1] [2]

Documentation:

  • Added a step to the Bicep deployment README instructing users to run az login before authenticating with azd (deployers/bicep/README.md)

Copilot AI review requested due to automatic review settings February 10, 2026 12:38
@SteveCInVA SteveCInVA added the bug Something isn't working label Feb 10, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.yaml to create a .venv and run postconfig using the venv interpreter.
  • Add an az login step 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 the python feature for installing Python. If you need a specific Python version (3.11 per VARIANT), 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.
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the az login description: "shta" should be "that" (and the sentence could be tightened for clarity).

Suggested change
`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.

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +12
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "3.11"
}
},
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@@ -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
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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/*

Copilot uses AI. Check for mistakes.
echo ""
echo "[3/4] Running post-deployment configuration..."
if python3 ./bicep/postconfig.py; then
if .venv/bin/python3 ./bicep/postconfig.py; then
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if .venv/bin/python3 ./bicep/postconfig.py; then
if .venv/bin/python ./bicep/postconfig.py; then

Copilot uses AI. Check for mistakes.
Comment on lines +66 to 69
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
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant