Skip to content

Commit e6f43c5

Browse files
fix: address Copilot review feedback
- 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)
1 parent 1722239 commit e6f43c5

5 files changed

Lines changed: 86 additions & 27 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,27 @@ FROM mcr.microsoft.com/devcontainers/go:1-1.24-bookworm
33

44
# Install additional OS packages
55
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
6-
&& apt-get install -y curl libkrb5-dev \
6+
&& apt-get install -y curl libkrb5-dev gnupg2 \
77
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
88

9+
# Install Microsoft ODBC driver and mssql-tools18 (legacy ODBC sqlcmd/bcp for compatibility testing)
10+
RUN curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg \
11+
&& curl -fsSL https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list \
12+
&& apt-get update \
13+
&& ACCEPT_EULA=Y apt-get install -y msodbcsql18 mssql-tools18 unixodbc-dev \
14+
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
15+
ENV PATH="/opt/mssql-tools18/bin:${PATH}"
16+
917
# Install golangci-lint for code quality
10-
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v1.64.8
18+
# Download from specific release tag instead of master branch for supply chain security
19+
ARG GOLANGCI_LINT_VERSION=v1.64.8
20+
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/${GOLANGCI_LINT_VERSION}/install.sh | sh -s -- -b /usr/local/bin ${GOLANGCI_LINT_VERSION}
1121

12-
# Install additional Go tools
13-
RUN go install golang.org/x/tools/gopls@latest \
14-
&& go install github.com/go-delve/delve/cmd/dlv@latest \
15-
&& go install honnef.co/go/tools/cmd/staticcheck@latest \
16-
&& go install golang.org/x/text/cmd/gotext@latest
22+
# Install additional Go tools (pinned versions for reproducibility)
23+
RUN go install golang.org/x/tools/gopls@v0.18.1 \
24+
&& go install github.com/go-delve/delve/cmd/dlv@v1.24.1 \
25+
&& go install honnef.co/go/tools/cmd/staticcheck@v0.6.1 \
26+
&& go install golang.org/x/text/cmd/gotext@v0.22.0
1727

1828
# Create bin directory for local sqlcmd builds
1929
RUN mkdir -p /home/vscode/bin && chown vscode:vscode /home/vscode/bin

.devcontainer/README.md

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ After the container starts, these aliases are available:
6464
| `glint` | Run golangci-lint |
6565
| `ggen` | Run go generate (for translations) |
6666
| `test-db` | Test database connection |
67-
| `sql` | Connect to SQL Server interactively |
67+
| `sql` | Connect to SQL Server (go-sqlcmd) |
68+
| `sql-legacy` | Connect using legacy ODBC sqlcmd |
6869
| `rebuild` | Rebuild sqlcmd |
6970

7071
## SQL Server Connection
@@ -78,23 +79,58 @@ The SQL Server instance is accessible at:
7879

7980
### Using the Built-in sqlcmd
8081

81-
The container builds sqlcmd from source and adds it to your PATH:
82+
The container has **two versions** of sqlcmd available:
83+
84+
1. **go-sqlcmd** (this project) - the modern Go-based sqlcmd, built from source at `~/bin/sqlcmd`
85+
2. **Legacy ODBC sqlcmd** - the classic version from mssql-tools18 at `/opt/mssql-tools18/bin/sqlcmd`
86+
87+
Since go-sqlcmd is first in PATH, the `sqlcmd` command runs the modern version. Use the aliases or full paths to choose which version:
8288

8389
```bash
84-
# Using the alias
85-
sql
90+
# go-sqlcmd (this project) - default in PATH
91+
sql # alias for go-sqlcmd with connection args
92+
sqlcmd -S localhost -U sa -P "$SQLCMDPASSWORD" -C
8693

87-
# Or explicitly
88-
~/bin/sqlcmd -S localhost -U sa -P "SqlCmd@2025!" -C
94+
# Legacy ODBC sqlcmd (for compatibility testing)
95+
sql-legacy # alias for legacy sqlcmd with connection args
96+
/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$SQLCMDPASSWORD" -C
8997

90-
# Run a query
98+
# Run a query with go-sqlcmd
9199
sql -Q "SELECT @@VERSION"
100+
101+
# Compare behavior between versions
102+
sql -Q "SELECT 1 AS test"
103+
sql-legacy -Q "SELECT 1 AS test"
92104
```
93105

94106
### VS Code SQL Extension
95107

96108
The MSSQL extension is pre-configured with a connection profile named **"sqlcmd-container"**. Click the SQL Server icon in the Activity Bar to connect.
97109

110+
### Connecting from Host Machine Tools
111+
112+
The SQL Server port (1433) is forwarded to your host machine, so you can connect using tools installed locally:
113+
114+
#### Azure Data Studio
115+
116+
1. Open Azure Data Studio on your host machine
117+
2. Create a new connection:
118+
- Server: `localhost,1433`
119+
- Authentication: SQL Login
120+
- User: `sa`
121+
- Password: `SqlCmd@2025!`
122+
- Trust server certificate: Yes
123+
124+
#### SQL Server Management Studio (Windows)
125+
126+
1. Open SSMS on your Windows host
127+
2. Connect to Server:
128+
- Server name: `localhost,1433`
129+
- Authentication: SQL Server Authentication
130+
- Login: `sa`
131+
- Password: `SqlCmd@2025!`
132+
- Check "Trust server certificate"
133+
98134
## Environment Variables
99135

100136
The following environment variables are set automatically:
@@ -141,7 +177,7 @@ ginstall
141177

142178
### Adding SQL Setup Scripts
143179

144-
Place `.sql` files in `.devcontainer/mssql/` to have them executed when the container starts.
180+
The `setup.sql` script in `.devcontainer/mssql/` is executed automatically when the container starts. To run additional SQL scripts, either add them to `setup.sql` or update `post-create.sh` to execute them explicitly.
145181

146182
### Modifying the SA Password
147183

.devcontainer/docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ services:
2020
restart: unless-stopped
2121
environment:
2222
ACCEPT_EULA: "Y"
23+
SA_PASSWORD: "SqlCmd@2025!"
2324
MSSQL_SA_PASSWORD: "SqlCmd@2025!"
2425
MSSQL_PID: "Developer"
2526
volumes:
2627
- mssql-data:/var/opt/mssql
2728
healthcheck:
28-
test: /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "SqlCmd@2025!" -C -Q "SELECT 1" || exit 1
29+
test: ["CMD-SHELL", "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P \"$$SA_PASSWORD\" -C -Q \"SELECT 1\" || exit 1"]
2930
interval: 10s
3031
timeout: 5s
3132
retries: 15

.devcontainer/post-create.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ set -e
33

44
echo "=== go-sqlcmd Development Container Setup ==="
55

6-
# Get workspace folder name
7-
WORKSPACE_FOLDER=$(basename "$PWD")
8-
96
# Download Go dependencies
107
echo "📦 Downloading Go dependencies..."
118
go mod download
@@ -23,28 +20,39 @@ go build ./...
2320
echo "🔄 Verifying SQL Server connection..."
2421
max_attempts=30
2522
attempt=1
23+
sql_ready=false
2624
while [ $attempt -le $max_attempts ]; do
2725
if ~/bin/sqlcmd -S localhost -U sa -P "${SQLCMDPASSWORD}" -C -Q "SELECT 1" > /dev/null 2>&1; then
2826
echo "✅ SQL Server is ready!"
27+
sql_ready=true
2928
break
3029
fi
3130
echo " Waiting for SQL Server... (attempt $attempt/$max_attempts)"
3231
sleep 2
3332
attempt=$((attempt + 1))
3433
done
3534

36-
if [ $attempt -gt $max_attempts ]; then
35+
if [ "$sql_ready" = false ]; then
3736
echo "⚠️ Warning: Could not verify SQL Server connection. Tests may fail."
3837
fi
3938

40-
# Run initial setup SQL if it exists
39+
# Run initial setup SQL if it exists and SQL Server is ready
4140
if [ -f ".devcontainer/mssql/setup.sql" ]; then
42-
echo "📋 Running setup.sql..."
43-
~/bin/sqlcmd -S localhost -U sa -P "${SQLCMDPASSWORD}" -C -i .devcontainer/mssql/setup.sql
41+
if [ "$sql_ready" = true ]; then
42+
echo "📋 Running setup.sql..."
43+
~/bin/sqlcmd -S localhost -U sa -P "${SQLCMDPASSWORD}" -C -i .devcontainer/mssql/setup.sql
44+
else
45+
echo "⚠️ Skipping setup.sql because SQL Server connection could not be verified."
46+
fi
4447
fi
4548

46-
# Create useful aliases
49+
# Create useful aliases (idempotent - remove existing block first)
4750
echo "🔧 Setting up helpful aliases..."
51+
ALIAS_MARKER="# go-sqlcmd development aliases"
52+
if grep -q "$ALIAS_MARKER" ~/.bashrc 2>/dev/null; then
53+
# Remove existing alias block (from marker to next blank line or EOF)
54+
sed -i "/$ALIAS_MARKER/,/^$/d" ~/.bashrc
55+
fi
4856
cat >> ~/.bashrc << 'EOF'
4957
5058
# go-sqlcmd development aliases
@@ -61,6 +69,9 @@ alias ggen='go generate ./...'
6169
# sqlcmd shortcut - uses the locally built version
6270
alias sql='~/bin/sqlcmd -S localhost -U sa -P "$SQLCMDPASSWORD" -C'
6371
72+
# Legacy ODBC sqlcmd for compatibility testing
73+
alias sql-legacy='/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$SQLCMDPASSWORD" -C'
74+
6475
# Quick test connection
6576
alias test-db='~/bin/sqlcmd -S localhost -U sa -P "$SQLCMDPASSWORD" -C -Q "SELECT @@VERSION"'
6677
@@ -83,15 +94,16 @@ echo " gvet - Run go vet"
8394
echo " glint - Run golangci-lint"
8495
echo " ggen - Run go generate (for translations)"
8596
echo " test-db - Test database connection"
86-
echo " sql - Connect to SQL Server interactively"
97+
echo " sql - Connect to SQL Server (go-sqlcmd)"
98+
echo " sql-legacy - Connect using legacy ODBC sqlcmd"
8799
echo " rebuild - Rebuild sqlcmd"
88100
echo ""
89101
echo "🔧 Your locally built sqlcmd is at ~/bin/sqlcmd and in PATH"
90102
echo ""
91103
echo "🔗 SQL Server Connection:"
92104
echo " Server: localhost,1433"
93105
echo " User: sa"
94-
echo " Password: SqlCmd@2025!"
106+
echo " Password: (from SQLCMDPASSWORD environment variable)"
95107
echo " Database: master (or SqlCmdTest)"
96108
echo ""
97109
echo "🧪 Environment variables are pre-configured for tests."

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ sqlcmd.exe: error: sqlcmd.exe: '-w 4': Der Wert muss größer als 8 und kleiner
313313

314314
### Quick Start with Dev Containers
315315

316-
The easiest way to develop and test sqlcmd is using the included [Dev Container](.devcontainer/README.md), which works with:
316+
The easiest way to develop and test sqlcmd is to use the included [Dev Container](.devcontainer/README.md), which works with:
317317

318318
- **VS Code**: Install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers), open this repo, and click "Reopen in Container"
319319
- **GitHub Codespaces**: Click the "Code" button on GitHub and select "Create codespace"

0 commit comments

Comments
 (0)