Skip to content

Conversation

@dlevy-msft-sql
Copy link
Contributor

Summary

This PR adds a comprehensive development container setup for easier onboarding and consistent development environments.

What's Included

Development Environment

  • Go 1.24 with all development tools:
    • gopls (language server)
    • delve (debugger)
    • staticcheck
    • golangci-lint
    • gotext (for translations)

SQL Server 2025

  • Developer Edition running as a sidecar container
  • Health checks ensure it's ready before dev container starts
  • Pre-configured SA password
  • Test database (SqlCmdTest) created on startup

VS Code Extensions (pre-installed)

  • Go (golang.go)
  • MSSQL (ms-mssql.mssql) - with pre-configured connection
  • Docker (ms-azuretools.vscode-docker)
  • GitHub Copilot
  • GitLens

Features

  • Docker-in-Docker for container operations (testing sqlcmd create mssql, etc.)
  • GitHub CLI pre-installed for PR management
  • Locally built sqlcmd added to PATH automatically

Environment Variables

Pre-configured so tests run immediately:

  • SQLCMDSERVER=localhost
  • SQLCMDUSER=sa
  • SQLCMDPASSWORD=SqlCmd@2025!
  • SQLCMDDATABASE=master

Helpful Aliases

Alias Command
gtest Run all tests
gbuild Build sqlcmd locally
ginstall Build and install sqlcmd to ~/bin
glint Run golangci-lint
sql Connect to SQL Server interactively
test-db Test database connection

Files Added

  • .devcontainer/Dockerfile - Go development container
  • .devcontainer/docker-compose.yml - Container orchestration
  • .devcontainer/devcontainer.json - VS Code configuration
  • .devcontainer/post-create.sh - Setup script with aliases
  • .devcontainer/mssql/setup.sql - Test database setup
  • .devcontainer/README.md - Detailed documentation
  • .dockerignore - Exclude unnecessary files from build

README Updates

  • Added "Open in Dev Containers" badge
  • Added Development section with quick start instructions

Usage

VS Code

  1. Install the Dev Containers extension
  2. Open this repo in VS Code
  3. Click "Reopen in Container"
  4. Start developing!

GitHub Codespaces

  1. Click "Code" > "Codespaces" > "Create codespace"
  2. Wait for environment to start
  3. Run gtest to verify everything works

Relation to go-mssqldb

This follows the same pattern as go-mssqldb PR #317, making it easy for contributors to work on both projects with consistent environments.

Add comprehensive development container setup for easier onboarding:

- Go 1.24 with gopls, delve, staticcheck, golangci-lint
- SQL Server 2025 (Developer Edition) as sidecar container
- Docker-in-Docker for container operations
- GitHub CLI for PR management
- Pre-configured VS Code extensions (Go, MSSQL, Docker, Copilot, GitLens)
- Environment variables pre-set for tests (SQLCMDSERVER, etc.)
- Helpful aliases (gtest, gbuild, sql, etc.)
- Locally built sqlcmd added to PATH automatically
- Detailed documentation in .devcontainer/README.md

Files added:
- .devcontainer/Dockerfile
- .devcontainer/docker-compose.yml
- .devcontainer/devcontainer.json
- .devcontainer/post-create.sh
- .devcontainer/mssql/setup.sql
- .devcontainer/README.md
- .dockerignore

Also updates main README.md with:
- 'Open in Dev Containers' badge
- Development section with quick start instructions
@dlevy-msft-sql dlevy-msft-sql self-assigned this Feb 2, 2026
@dlevy-msft-sql dlevy-msft-sql added enhancement New feature or request Size: S Small issue (less than one week effort) needs-work labels Feb 2, 2026
Copy link

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

Adds a VS Code / GitHub Codespaces devcontainer setup to make onboarding and running integration tests against a local SQL Server container easier and more consistent.

Changes:

  • Introduces a full .devcontainer/ configuration (Dockerfile, docker-compose, devcontainer.json, post-create provisioning, and SQL bootstrap script).
  • Documents devcontainer usage in both the root README and a dedicated .devcontainer/README.md.
  • Adds a root .dockerignore to reduce Docker build context noise.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
README.md Adds “Open in Dev Containers” badge and a Development section with quickstart/manual setup.
.dockerignore Defines ignore rules for Docker builds from the repo root.
.devcontainer/Dockerfile Dev image with Go toolchain + common Go dev tools and dependencies.
.devcontainer/docker-compose.yml Orchestrates devcontainer + SQL Server sidecar with healthcheck.
.devcontainer/devcontainer.json VS Code devcontainer configuration, extensions, forwarded ports, env vars, post-create command.
.devcontainer/post-create.sh Post-create setup: downloads deps, builds sqlcmd, validates build, waits for DB, runs setup.sql, adds aliases.
.devcontainer/mssql/setup.sql Creates a SqlCmdTest database and sample objects for quick testing.
.devcontainer/README.md Detailed documentation for devcontainer usage, troubleshooting, and customization.

- Fix grammar: 'is using' -> 'is to use' in README.md
- Remove unused WORKSPACE_FOLDER variable from post-create.sh
- Make bashrc alias updates idempotent (remove existing block first)
- Only run setup.sql if SQL Server connection succeeded
- Don't print SA password to terminal (reference env var instead)
- Use SA_PASSWORD in addition to MSSQL_SA_PASSWORD for CI consistency
- Use environment variable reference in healthcheck
- Pin Go tools to specific versions for reproducibility:
  - gopls@v0.18.1, dlv@v1.24.1, staticcheck@v0.6.1, gotext@v0.22.0
- Improve golangci-lint install security by using versioned tag URL
- Fix docs to match actual behavior (only setup.sql is executed)
- Install legacy ODBC sqlcmd (mssql-tools18) for compatibility testing
- Add sql-legacy alias to easily compare behavior between versions
- Document connecting from host tools (Azure Data Studio, SSMS)
Copy link

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Download pre-built binary directly from GitHub releases instead of
piping install script to sh. This addresses supply chain security
concerns about executing remote scripts.

The image tag 1-1.24-bookworm is valid - the first '1' is the
devcontainer definition version, second '1.24' is the Go version.
The markdown tables render correctly (Copilot false positive).
Copy link

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

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

Security improvements:
- Add SHA256 checksum verification for golangci-lint v1.64.8
  (b6270687afb143d019f387c791cd2a6f1cb383be9b3124d241ca11bd3ce2e54e)

Password handling:
- Consolidate to single env var (MSSQL_SA_PASSWORD only)
- Use MSSQL_SA_PASSWORD in healthcheck for consistency
- Set savePassword: false in mssql.connections (prompts on first use)

Tool management:
- Disable go.toolsManagement.autoUpdate to preserve pinned versions

Documentation:
- Clarify CI comparison (same env var names, not identical config)
- Update password change instructions to be clearer
Dockerfile:
- Fix image tag format: 1.24-bookworm (not 1-1.24-bookworm)

docker-compose.yml:
- Add both SA_PASSWORD and MSSQL_SA_PASSWORD for CI compatibility
  (different SQL Server images use different env vars)

post-create.sh:
- Add dynamic workspace detection with robust fallback
- Handles different clone names (go-sqlcmd, fork names, etc.)

setup.sql:
- Add TRY/CATCH error handling for contained database operations
- Prevents script failure on unsupported SQL Server configurations

.dockerignore:
- Add .devcontainer/ to reduce build context size

Reference: microsoft/go-mssqldb#317
Copy link

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Addresses review #3737525469:

1. README badge: Changed from hardcoded repo URL to link to devcontainer
   docs, so forks don't redirect to upstream repo

2. Aliases: Use dedicated ~/.bash_aliases file instead of modifying
   ~/.bashrc with sed, avoiding potential accidental content deletion

3. Volume mount: Fixed from ../.. to ../workspaces/go-sqlcmd to only
   mount the repo root, not parent directories that could expose secrets

4. MSSQL connection: Removed hardcoded password from mssql.connections
   config. Users will be prompted to enter password on first connect.

5. Password handling: Added environment variable substitution support:
   - docker-compose.yml: Uses SQLCMDPASSWORD env var with default
   - devcontainer.json: Uses localEnv with fallback to default
   - Added comments explaining this is dev-only, not production secrets
   - Updated README to clarify password is available via env var
Update README to mention that both SA_PASSWORD and MSSQL_SA_PASSWORD
must be updated in docker-compose.yml when changing the password,
matching the fix applied to go-mssqldb PR microsoft#317.
Copy link

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

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

Addresses review #3737557661:

1. Password note wording: Fixed misleading claim that password is not
   stored in committed files. Now clarifies it's a dev-only default
   checked into repo for convenience.

2. MSSQL profile name: Updated docs to match devcontainer.json profile
   name 'sqlcmd-container (use SQLCMDPASSWORD env var)'

3. workspaceFolder mismatch: Changed from variable-based path to
   fixed '/workspaces/go-sqlcmd' to match docker-compose.yml mount

4. go.testEnvVars password: Now uses env:SQLCMDPASSWORD instead of
   hardcoded value, so VS Code tests use same password as container

5. ARM64 architecture support: Added architecture detection for
   golangci-lint with separate SHA256 checksums for amd64/arm64

6. Alias management: Now uses ~/.bash_aliases.d/ directory instead
   of overwriting ~/.bash_aliases, preserving user's custom aliases
Copy link

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Copy link

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request in-review Size: S Small issue (less than one week effort)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant