-
Notifications
You must be signed in to change notification settings - Fork 36
CHORE: Create devcontainer for repo #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+363
−0
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a93e2ff
Dev Container setup
2383b7b
REFACTOR: Simplify post-create script by removing redundant activatio…
1f50584
Update .dockerignore
saurabh500 6f79cd2
Update .devcontainer/Dockerfile
saurabh500 1e4c8cc
Update .dockerignore
saurabh500 92b1c1f
Update .dockerignore
saurabh500 78d129f
Update .dockerignore
saurabh500 b5e940a
Update .devcontainer/devcontainer.json
saurabh500 306ae47
Update .devcontainer/devcontainer.json
saurabh500 386b81b
Apply suggestions from code review
saurabh500 9dd343b
Merge branch 'main' into devcontainer
bewithgaurav 19f635e
Merge branch 'main' into devcontainer
bewithgaurav 6427ac6
Merge branch 'main' into devcontainer
saurabh500 f534e5c
CHORE: Upgrade to Python 3.14, fix duplicate ODBC, modernize settings
dlevy-msft-sql 4ad071d
Merge branch 'main' into devcontainer
dlevy-msft-sql 651f576
Merge branch 'main' into devcontainer
bewithgaurav 37ecdff
fix(devcontainer): add unixodbc-dev, move Python setup to post-create…
bewithgaurav 33f3611
fix(devcontainer): improve shell aliases and connection string setup
bewithgaurav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Use Python 3.14 with Debian Bookworm as the base image | ||
| FROM mcr.microsoft.com/devcontainers/python:3.14-bookworm | ||
|
|
||
| # Set environment variables | ||
| ENV DEBIAN_FRONTEND=noninteractive | ||
| ENV PYTHONPATH=/workspaces/mssql-python | ||
| ENV CMAKE_BUILD_TYPE=Debug | ||
|
|
||
| # Set timezone (configurable via build arg) | ||
| ARG TZ=UTC | ||
| ENV TZ=$TZ | ||
| RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \ | ||
| && echo $TZ > /etc/timezone | ||
|
|
||
| # Install all system dependencies in one layer | ||
| RUN apt-get update && apt-get install -y \ | ||
| # Build tools | ||
| build-essential \ | ||
| cmake \ | ||
| pkg-config \ | ||
| ninja-build \ | ||
| python3-dev \ | ||
| pybind11-dev \ | ||
| # ODBC prerequisites (unixodbc-dev provides sql.h headers for compilation) | ||
| unixodbc-dev \ | ||
| gnupg \ | ||
| software-properties-common \ | ||
| # Utilities | ||
| curl \ | ||
| wget \ | ||
| git \ | ||
| vim \ | ||
| nano \ | ||
| htop \ | ||
| tree \ | ||
| jq \ | ||
| # Clean up | ||
| && apt-get clean \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Install Microsoft ODBC Driver for SQL Server | ||
| RUN curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg \ | ||
| && echo "deb [arch=arm64,amd64 signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" > /etc/apt/sources.list.d/mssql-release.list \ | ||
| && apt-get update \ | ||
| && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \ | ||
bewithgaurav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| && ACCEPT_EULA=Y apt-get install -y mssql-tools18 \ | ||
| && apt-get clean \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Add mssql-tools to PATH | ||
| ENV PATH="$PATH:/opt/mssql-tools18/bin" | ||
|
|
||
| # Set the default user to vscode (created by the base image) | ||
| USER vscode | ||
|
|
||
| # Set the working directory | ||
| WORKDIR /workspaces/mssql-python | ||
|
|
||
| # Default command | ||
| CMD ["/bin/bash"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| { | ||
| "name": "MSSQL Python Driver", | ||
| "build": { | ||
| "dockerfile": "Dockerfile", | ||
| "context": "." | ||
| }, | ||
| "customizations": { | ||
| "vscode": { | ||
| "settings": { | ||
| "python.defaultInterpreterPath": "/usr/local/bin/python", | ||
| "python.terminal.activateEnvironment": false, | ||
| "editor.formatOnSave": true, | ||
| "[python]": { | ||
| "editor.defaultFormatter": "ms-python.black-formatter" | ||
| }, | ||
| "cmake.configureOnOpen": false, | ||
| "cmake.configureOnEdit": false, | ||
| "cmake.automaticReconfigure": false, | ||
| "files.exclude": { | ||
| "**/__pycache__": true, | ||
| "**/*.pyc": true, | ||
| "**/.pytest_cache": true, | ||
| "**/build": true | ||
| } | ||
| }, | ||
| "extensions": [ | ||
| "ms-python.python", | ||
| "ms-python.vscode-pylance", | ||
| "ms-python.pylint", | ||
| "ms-python.black-formatter", | ||
| "ms-toolsai.jupyter", | ||
| "ms-vscode.cmake-tools", | ||
| "ms-vscode.cpptools", | ||
| "ms-vscode.cpptools-extension-pack", | ||
| "github.copilot", | ||
| "github.copilot-chat", | ||
| "ms-vscode.test-adapter-converter", | ||
| "littlefoxteam.vscode-python-test-adapter", | ||
| "ms-azuretools.vscode-docker", | ||
| "ms-mssql.mssql" | ||
| ] | ||
| } | ||
| }, | ||
| "features": { | ||
| "ghcr.io/devcontainers/features/git:1": {}, | ||
| "ghcr.io/devcontainers/features/github-cli:1": {}, | ||
| "ghcr.io/devcontainers/features/docker-in-docker:2": {}, | ||
| "ghcr.io/devcontainers/features/common-utils:2": { | ||
| "installZsh": true, | ||
| "configureZshAsDefaultShell": true, | ||
| "installOhMyZsh": true, | ||
| "upgradePackages": true, | ||
| "username": "vscode", | ||
| "userUid": "automatic", | ||
| "userGid": "automatic" | ||
| } | ||
| }, | ||
| "forwardPorts": [1433], | ||
| "portsAttributes": { | ||
| "1433": { | ||
| "label": "SQL Server", | ||
| "onAutoForward": "notify" | ||
| } | ||
| }, | ||
| "postCreateCommand": "bash .devcontainer/post-create.sh", | ||
| "remoteUser": "vscode", | ||
| "containerEnv": { | ||
| "PYTHONPATH": "/workspaces/mssql-python", | ||
| "CMAKE_BUILD_TYPE": "Debug" | ||
| }, | ||
| "workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/mssql-python,type=bind,consistency=cached", | ||
| "workspaceFolder": "/workspaces/mssql-python" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Post-create script for MSSQL Python Driver devcontainer | ||
| set -e | ||
|
|
||
| echo "🚀 Setting up MSSQL Python Driver development environment..." | ||
|
|
||
| # Install Python packages from requirements.txt | ||
| echo "📦 Installing Python packages..." | ||
| pip install --upgrade pip setuptools wheel | ||
| pip install -r requirements.txt | ||
|
|
||
| # Create symlink for 'python' command (build.sh expects it) | ||
| echo "🔗 Creating python symlink..." | ||
| sudo ln -sf $(which python3) /usr/local/bin/python | ||
|
|
||
| # Set up useful shell aliases (for both bash and zsh) | ||
| echo "⚡ Setting up aliases..." | ||
| cat > ~/.shell_aliases << 'EOF' | ||
| # MSSQL Python Driver development aliases | ||
| alias build='cd /workspaces/mssql-python/mssql_python/pybind && ./build.sh && cd /workspaces/mssql-python' | ||
| alias test='python -m pytest -v' | ||
| EOF | ||
|
|
||
| # Ensure aliases are sourced in both shells | ||
| grep -qxF 'source ~/.shell_aliases' ~/.bashrc 2>/dev/null || echo 'source ~/.shell_aliases' >> ~/.bashrc | ||
| grep -qxF 'source ~/.shell_aliases' ~/.zshrc 2>/dev/null || echo 'source ~/.shell_aliases' >> ~/.zshrc | ||
|
|
||
| # Verify environment | ||
| echo "" | ||
| echo "🔍 Verifying environment..." | ||
| python --version | ||
| pip --version | ||
| cmake --version | ||
| if command -v sqlcmd &> /dev/null; then | ||
| echo "✅ sqlcmd available" | ||
| else | ||
| echo "❌ sqlcmd not found" | ||
| fi | ||
|
|
||
| # Build the C++ extension | ||
| echo "" | ||
| echo "🔨 Building C++ extension..." | ||
| if cd mssql_python/pybind && ./build.sh && cd ../..; then | ||
| echo "✅ C++ extension built successfully" | ||
| else | ||
| echo "❌ C++ extension build failed!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Generate random password for SQL Server | ||
| echo "" | ||
| echo "Generating SQL Server password..." | ||
| SA_PASSWORD="$(openssl rand -base64 16 | tr -dc 'A-Za-z0-9' | head -c 16)Aa1!" | ||
| echo "$SA_PASSWORD" > /tmp/.sqlserver_sa_password | ||
| chmod 600 /tmp/.sqlserver_sa_password | ||
|
|
||
| # Start SQL Server container (use Azure SQL Edge for ARM64 compatibility) | ||
| # This is optional - if Docker-in-Docker fails, the devcontainer still works | ||
| echo "" | ||
| echo "Starting SQL Server container (optional)..." | ||
|
|
||
| ARCH=$(uname -m) | ||
| if [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then | ||
| echo "Detected ARM64 - using Azure SQL Edge..." | ||
| docker run -e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$SA_PASSWORD" \ | ||
| -p 1433:1433 --name sqlserver \ | ||
| -d mcr.microsoft.com/azure-sql-edge:latest && SQL_STARTED=true || SQL_STARTED=false | ||
| else | ||
| echo "Detected x86_64 - using SQL Server 2025..." | ||
| docker run -e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$SA_PASSWORD" \ | ||
| -p 1433:1433 --name sqlserver \ | ||
| -d mcr.microsoft.com/mssql/server:2025-latest && SQL_STARTED=true || SQL_STARTED=false | ||
| fi | ||
|
|
||
| if [ "$SQL_STARTED" = "true" ]; then | ||
| echo "Waiting for SQL Server to start..." | ||
| sleep 15 | ||
| else | ||
| echo "WARNING: SQL Server container failed to start (Docker issue)" | ||
| echo " You can start it manually later with:" | ||
| echo " docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=YourPassword123!' -p 1433:1433 --name sqlserver -d mcr.microsoft.com/azure-sql-edge:latest" | ||
| fi | ||
|
|
||
| # Set DB_CONNECTION_STRING environment variable (persist across all terminals) | ||
| DB_CONNECTION_STRING="Server=localhost,1433;Database=master;UID=sa;PWD=$SA_PASSWORD;TrustServerCertificate=Yes;Encrypt=Yes" | ||
|
||
|
|
||
| # Write to /etc/environment for system-wide persistence | ||
| echo "DB_CONNECTION_STRING=\"$DB_CONNECTION_STRING\"" | sudo tee -a /etc/environment > /dev/null | ||
|
|
||
| # Also add to shell rc files for immediate availability in new terminals | ||
| echo "export DB_CONNECTION_STRING=\"$DB_CONNECTION_STRING\"" >> ~/.bashrc | ||
| echo "export DB_CONNECTION_STRING=\"$DB_CONNECTION_STRING\"" >> ~/.zshrc | ||
|
|
||
| # Export for current session | ||
| export DB_CONNECTION_STRING | ||
|
|
||
| # Display completion message and next steps | ||
| echo "" | ||
| echo "==============================================" | ||
| echo "🎉 Dev environment setup complete!" | ||
| echo "==============================================" | ||
| echo "" | ||
| echo "📦 What's ready:" | ||
| echo " ✅ C++ extension built" | ||
| echo " ✅ SQL Server running (localhost:1433)" | ||
|
||
| echo " ✅ DB_CONNECTION_STRING set in environment" | ||
| echo "" | ||
| echo "🚀 Quick start - just type these commands:" | ||
| echo " python main.py → Test the connection" | ||
| echo " test → Run all pytest tests" | ||
| echo " build → Rebuild C++ extension" | ||
| echo "" | ||
| echo "==============================================" | ||
| echo "" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| # Git | ||
| .git | ||
| .gitignore | ||
| .gitattributes | ||
|
|
||
| # Python | ||
| __pycache__ | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| .Python | ||
| env | ||
| pip-log.txt | ||
| pip-delete-this-directory.txt | ||
| .tox | ||
| .coverage | ||
| .coverage.* | ||
| .cache | ||
| nosetests.xml | ||
| coverage.xml | ||
| *.cover | ||
| *.log | ||
| .mypy_cache | ||
| .pytest_cache | ||
| .hypothesis | ||
|
|
||
| # Distribution / packaging | ||
| build/ | ||
| develop-eggs/ | ||
| dist/ | ||
| downloads/ | ||
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
bewithgaurav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
| var/ | ||
| wheels/ | ||
| *.egg-info/ | ||
| .installed.cfg | ||
| *.egg | ||
|
|
||
| # PyInstaller | ||
| *.manifest | ||
| *.spec | ||
|
|
||
| # Installer logs | ||
| pip-log.txt | ||
saurabh500 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Unit test / coverage reports | ||
| htmlcov/ | ||
| .coverage | ||
saurabh500 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .coverage.* | ||
saurabh500 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| nosetests.xml | ||
| coverage.xml | ||
| *.cover | ||
| .hypothesis/ | ||
|
|
||
| # Translations | ||
| *.mo | ||
| *.pot | ||
|
|
||
| # Documentation | ||
| docs/_build/ | ||
|
|
||
| # PyBuilder | ||
| target/ | ||
|
|
||
| # IDEs | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| .DS_Store? | ||
| ._* | ||
| .Spotlight-V100 | ||
| .Trashes | ||
| ehthumbs.db | ||
| Thumbs.db | ||
|
|
||
| # Temporary files | ||
| *.tmp | ||
| *.temp | ||
| *.log | ||
saurabh500 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Node.js (if any) | ||
| node_modules/ | ||
| npm-debug.log* | ||
|
|
||
| # CMake | ||
| CMakeCache.txt | ||
| CMakeFiles/ | ||
| cmake_install.cmake | ||
| Makefile | ||
| *.cmake | ||
|
|
||
| # Build artifacts | ||
| *.so | ||
bewithgaurav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| *.dll | ||
| *.dylib | ||
| *.pdb | ||
| *.obj | ||
| *.exe | ||
|
|
||
| # Test results | ||
| test-results/ | ||
| .pytest_cache/ | ||
saurabh500 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Azure DevOps | ||
| .azure/ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.