Skip to content

Commit eefc9d6

Browse files
fix: apply lessons learned from go-mssqldb PR #317
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
1 parent af11705 commit eefc9d6

5 files changed

Lines changed: 36 additions & 4 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# go-sqlcmd Development Container
2-
FROM mcr.microsoft.com/devcontainers/go:1-1.24-bookworm
2+
FROM mcr.microsoft.com/devcontainers/go:1.24-bookworm
33

44
# Install additional OS packages
55
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \

.devcontainer/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ 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:

.devcontainer/mssql/setup.sql

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,23 @@ END
1313
GO
1414

1515
-- Enable contained database authentication for testing
16-
EXEC sp_configure 'contained database authentication', 1;
17-
RECONFIGURE;
16+
-- Use TRY/CATCH in case this fails on certain SQL Server configurations
17+
BEGIN TRY
18+
EXEC sp_configure 'contained database authentication', 1;
19+
RECONFIGURE;
20+
END TRY
21+
BEGIN CATCH
22+
PRINT 'Note: Could not enable contained database authentication (may already be enabled or not supported)';
23+
END CATCH;
1824
GO
1925

2026
-- Make SqlCmdTest a contained database for testing
21-
ALTER DATABASE SqlCmdTest SET CONTAINMENT = PARTIAL;
27+
BEGIN TRY
28+
ALTER DATABASE SqlCmdTest SET CONTAINMENT = PARTIAL;
29+
END TRY
30+
BEGIN CATCH
31+
PRINT 'Note: Could not set database containment (may not be supported)';
32+
END CATCH;
2233
GO
2334

2435
USE SqlCmdTest;

.devcontainer/post-create.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ set -e
33

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

6+
# Dynamic workspace detection with fallback
7+
if [ -n "${WORKSPACE_FOLDER}" ] && [ -d "${WORKSPACE_FOLDER}" ]; then
8+
cd "${WORKSPACE_FOLDER}"
9+
elif [ -d "/workspaces/go-sqlcmd" ]; then
10+
cd /workspaces/go-sqlcmd
11+
else
12+
# Find workspace by looking for go.mod
13+
workspace_go_mod="$(find /workspaces -maxdepth 2 -name 'go.mod' -type f -print -quit 2>/dev/null)"
14+
if [ -n "$workspace_go_mod" ]; then
15+
cd "$(dirname "$workspace_go_mod")"
16+
else
17+
echo "Error: Could not determine workspace directory" >&2
18+
exit 1
19+
fi
20+
fi
21+
echo "📁 Working in: $(pwd)"
22+
623
# Download Go dependencies
724
echo "📦 Downloading Go dependencies..."
825
go mod download

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ CHANGELOG*
6060
.pipelines/
6161
appveyor.yml
6262

63+
# Dev container configuration (not needed in image build)
64+
.devcontainer/
65+
6366
# Test output and temporary files
6467
*.log
6568
*.tmp

0 commit comments

Comments
 (0)