Skip to content

Commit 32610da

Browse files
authored
Use Rosetta 2 and improve robustness for macOS SQL Server CI setup (dotnet#4173)
1 parent 8ddc464 commit 32610da

1 file changed

Lines changed: 43 additions & 21 deletions

File tree

eng/pipelines/common/templates/steps/configure-sql-server-macos-step.yml

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,42 @@ steps:
2929
export PS4='+ [$(date "+%Y-%m-%d %H:%M:%S")] '
3030
set -x
3131
32-
# Install Docker and SQLCMD tools.
32+
# Install Docker CLI (not Desktop — Colima provides the daemon) and SQLCMD tools.
3333
brew install colima
34-
brew install --cask docker
34+
brew install docker
3535
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
3636
brew update
3737
HOMEBREW_ACCEPT_EULA=Y brew install mssql-tools18
38-
colima start --arch x86_64
38+
39+
# Start Colima with Virtualization.framework for x86_64 binary translation
40+
# on Apple Silicon. Rosetta/binfmt emulation is enabled by default in
41+
# Colima >= 0.8 when using --vm-type vz, which is dramatically faster than
42+
# --arch x86_64 (full QEMU VM emulation).
43+
# Requires macOS >= 13 (Ventura).
44+
colima start --vm-type vz --cpu 4 --memory 4
3945
docker --version
40-
docker pull mcr.microsoft.com/mssql/server:2025-latest
46+
docker pull --platform linux/amd64 mcr.microsoft.com/mssql/server:2025-latest
4147
4248
# Password for the SA user (required)
4349
MSSQL_SA_PW="${{ parameters.saPassword }}"
4450
45-
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=$MSSQL_SA_PW" -p 1433:1433 -p 1434:1434 --name sql1 --hostname sql1 -d mcr.microsoft.com/mssql/server:2025-latest
51+
docker run --platform linux/amd64 -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=$MSSQL_SA_PW" -p 1433:1433 -p 1434:1434 --name sql1 --hostname sql1 -d mcr.microsoft.com/mssql/server:2025-latest
4652
47-
sleep 5
53+
sleep 10
4854
4955
docker ps -a
5056
5157
# Connect to the SQL Server container and get its version.
5258
#
53-
# It can take a while for the docker container to start listening and be
54-
# ready for connections, so we will wait for up to 2 minutes, checking every
55-
# 3 seconds.
59+
# With Rosetta 2 emulation, SQL Server starts much faster than under full
60+
# QEMU emulation, but it can still take a minute or two. We allow up to
61+
# 6 minutes (72 attempts × 5 seconds) as a generous upper bound.
5662
57-
# Wait 3 seconds between attempts.
58-
delay=3
63+
# Wait 5 seconds between attempts.
64+
delay=5
5965
60-
# Try up to 40 times (2 minutes) to connect.
61-
maxAttempts=40
66+
# Try up to 72 times (~6 minutes) to connect.
67+
maxAttempts=72
6268
6369
# Attempt counter.
6470
attempt=1
@@ -71,14 +77,25 @@ steps:
7177
7278
echo "Waiting for SQL Server to start (attempt #$attempt of $maxAttempts)..."
7379
74-
sqlcmd -S 127.0.0.1 -No -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" >> $SQLCMD_ERRORS 2>&1
80+
# -C trusts the self-signed certificate inside the container.
81+
sqlcmd -S 127.0.0.1 -No -C -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" >> $SQLCMD_ERRORS 2>&1
7582
7683
# If the command was successful, then the SQL Server is ready.
7784
if [ $? -eq 0 ]; then
7885
ready=1
7986
break
8087
fi
8188
89+
# Verify the container is still running; no point retrying if it crashed.
90+
if ! docker ps --filter "name=^/sql1$" --filter "status=running" --format '{{.Names}}' | grep -Fxq 'sql1'; then
91+
echo "ERROR: sql1 container is no longer running."
92+
docker ps -a --filter "name=^/sql1$"
93+
echo "--- Container logs ---"
94+
docker logs sql1 2>&1 | tail -50
95+
rm -f $SQLCMD_ERRORS
96+
exit 1
97+
fi
98+
8299
# Increment the attempt counter.
83100
((attempt++))
84101
@@ -91,8 +108,13 @@ steps:
91108
if [ $ready -eq 0 ]
92109
then
93110
# No, so report the error(s) and exit.
94-
echo Cannot connect to SQL Server; installation aborted; errors were:
111+
echo "Cannot connect to SQL Server after $maxAttempts attempts; installation aborted."
112+
echo "--- sqlcmd errors ---"
95113
cat $SQLCMD_ERRORS
114+
echo "--- Container status ---"
115+
docker ps -a --filter "name=^/sql1$"
116+
echo "--- Container logs (last 80 lines) ---"
117+
docker logs sql1 2>&1 | tail -80
96118
rm -f $SQLCMD_ERRORS
97119
exit 1
98120
fi
@@ -101,18 +123,18 @@ steps:
101123
102124
echo "Use sqlcmd to show which IP addresses are being listened on..."
103125
echo 0.0.0.0
104-
sqlcmd -S 0.0.0.0 -No -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" -l 2
126+
sqlcmd -S 0.0.0.0 -No -C -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" -l 2
105127
echo 127.0.0.1
106-
sqlcmd -S 127.0.0.1 -No -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" -l 2
128+
sqlcmd -S 127.0.0.1 -No -C -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" -l 2
107129
echo ::1
108-
sqlcmd -S ::1 -No -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" -l 2
130+
sqlcmd -S ::1 -No -C -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" -l 2
109131
echo localhost
110-
sqlcmd -S localhost -No -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" -l 2
132+
sqlcmd -S localhost -No -C -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" -l 2
111133
echo "(sqlcmd default / not specified)"
112-
sqlcmd -No -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" -l 2
134+
sqlcmd -No -C -U sa -P "$MSSQL_SA_PW" -Q "SELECT @@VERSION" -l 2
113135
114136
echo "Configuring Dedicated Administer Connections to allow remote connections..."
115-
sqlcmd -S 127.0.0.1 -No -U sa -P "$MSSQL_SA_PW" -Q "sp_configure 'remote admin connections', 1; RECONFIGURE;"
137+
sqlcmd -S 127.0.0.1 -No -C -U sa -P "$MSSQL_SA_PW" -Q "sp_configure 'remote admin connections', 1; RECONFIGURE;"
116138
if [ $? = 1 ]
117139
then
118140
echo "Error configuring DAC for remote access."

0 commit comments

Comments
 (0)