Skip to content

Conversation

@saurabh500
Copy link
Contributor

@saurabh500 saurabh500 commented Jul 19, 2025

Devcontainer: Production-Ready Setup for mssql-python Development

Summary

Refactored the devcontainer with battle-tested improvements from local development use. This provides a complete, zero-config development environment for GitHub Codespaces and local devcontainers.

What's New

🏗️ Build & Setup

  • Auto-builds C++ extension during container setup (fails fast if broken)
  • Added unixodbc-dev package - fixes sql.h not found compilation errors
  • Disabled CMake auto-configure to prevent duplicate/conflicting builds
  • Moved Python package installation from Dockerfile to post-create for faster image rebuilds

🖥️ ARM64 Support

  • Detects architecture automatically
  • Uses Azure SQL Edge on ARM64 (Apple Silicon, ARM Codespaces)
  • Uses SQL Server 2025 on x86_64

🔌 SQL Server Auto-Setup

  • Starts SQL Server container via Docker-in-Docker
  • Generates random secure SA password
  • Sets DB_CONNECTION_STRING environment variable (persisted to /etc/environment, .bashrc, .zshrc)
  • Non-fatal if Docker fails - devcontainer still works for builds/tests against remote servers

⚡ Developer Experience

  • Shell aliases work in both bash and zsh:
    • build - Rebuild C++ extension
    • test - Run pytest
  • Clean completion message with quick-start commands

Quick Start

  1. Open in Codespaces / "Reopen in Container"
  2. Wait for setup (~4-5 mins)
  3. python main.py - test connection
  4. test - run all tests

Testing

  • Tested on macOS ARM64 (Apple Silicon)
  • Tested in GitHub Codespaces

Fixes #146

Copilot AI review requested due to automatic review settings July 19, 2025 06:41
@saurabh500
Copy link
Contributor Author

@microsoft-github-policy-service agree company="Microsoft"

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 pull request establishes a comprehensive Docker-based development environment for the MSSQL Python Driver project using VS Code devcontainer technology. The setup enables developers to quickly spin up a consistent development environment with all necessary dependencies pre-configured.

  • Creates a complete devcontainer configuration with Python 3.10, Microsoft ODBC drivers, and development tools
  • Implements automated environment setup through post-creation scripts and Docker configuration
  • Adds Docker build optimization through comprehensive file exclusion patterns

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 13 comments.

File Description
.dockerignore Excludes build artifacts, caches, and IDE files from Docker context
.devcontainer/Dockerfile Defines container with Python 3.10, MSSQL drivers, and development tools
.devcontainer/devcontainer.json Configures VS Code settings, extensions, and container features
.devcontainer/post-create.sh Automates post-container setup including dependencies and virtual environment

@saurabh500 saurabh500 changed the title Create devcontainer for repo CHORE: Create devcontainer for repo Jul 19, 2025
saurabh500 and others added 7 commits July 18, 2025 23:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Collaborator

@bewithgaurav bewithgaurav left a comment

Choose a reason for hiding this comment

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

some refactoring & optimization comments

# Upgrade pip and install common Python development tools
RUN python -m pip install --upgrade pip setuptools wheel \
&& pip install \
black \
Copy link
Collaborator

Choose a reason for hiding this comment

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

we have the minimum requirements available in requirements.txt - as seen in post-create script we're using pip install -r requirements.txt already. we can skip this here/there probably.

@dlevy-msft-sql
Copy link
Contributor

@saurabh500 bumping this because it would be nice to have. Are we close on this PR or is it better to start fresh since it has been a while?

@github-actions
Copy link

github-actions bot commented Jan 19, 2026

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

76%


📈 Total Lines Covered: 5472 out of 7137
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

No lines with coverage information in this diff.


📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.logger_bridge.hpp: 58.8%
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.row.py: 66.2%
mssql_python.pybind.ddbc_bindings.cpp: 69.3%
mssql_python.pybind.ddbc_bindings.h: 69.7%
mssql_python.pybind.connection.connection.cpp: 75.3%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 79.6%
mssql_python.connection.py: 84.1%
mssql_python.cursor.py: 84.7%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

dlevy-msft-sql
dlevy-msft-sql previously approved these changes Feb 3, 2026
@bewithgaurav
Copy link
Collaborator

bewithgaurav commented Feb 4, 2026

I've been using an ubuntu devcontainer for mssql-python since some time now, and have some more improvements to this that we can add here
I'll resolve the comments and add some modifications to this so we can merge this off

cc: @saurabh500

…, ARM64 support

- Add unixodbc-dev package for ODBC headers (fixes sql.h not found)
- Move Python package installation from Dockerfile to post-create.sh
- Add ARM64 support: use Azure SQL Edge instead of SQL Server 2025
- Make SQL Server container startup non-fatal (optional)
- Fix false success reporting when build fails
- Disable CMake auto-configure to prevent duplicate builds
- Generate random SA password and store connection string
@saurabh500
Copy link
Contributor Author

@bewithgaurav all yours. I haven't had the bandwidth to pick this up.
Since you have been active in this area, you will do better at driving this.

- Add aliases for both bash and zsh
- Persist DB_CONNECTION_STRING to /etc/environment and shell rc files
- Improve completion message with quick start commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request pr-size: medium Moderate update size under development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dev container spec for the repo

3 participants