Skip to content

Commit f0fef6a

Browse files
authored
Switch macOS to test against local server (#2750)
1 parent 198b906 commit f0fef6a

File tree

7 files changed

+203
-102
lines changed

7 files changed

+203
-102
lines changed

eng/pipelines/common/templates/jobs/ci-run-tests-job.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ jobs:
9292
- ${{ if ne(parameters.prebuildSteps, '') }}:
9393
- ${{ parameters.prebuildSteps }} # extra steps to run before the build like downloading sni and the required configuration
9494

95+
- powershell: |
96+
$guid = [guid]::NewGuid().ToString()
97+
Write-Host "##vso[task.setvariable variable=password;issecret=true]$guid"
98+
displayName: 'Generate Password'
99+
100+
- powershell: |
101+
Write-Host "Password: $(password)" # prints *** to logs when set
102+
103+
$variableValue = "$(password)"
104+
if (-not [string]::IsNullOrEmpty($variableValue)) {
105+
Write-Output "The password exists with a value."
106+
} else {
107+
Write-Output "The password does not exist or is empty."
108+
}
109+
displayName: 'Verify Password'
110+
95111
- ${{ if ne(parameters.configProperties, '{}') }}:
96112
- template: ../steps/update-config-file-step.yml@self # update config.json file
97113
parameters:
@@ -178,8 +194,6 @@ jobs:
178194
user: ${{ parameters.configProperties.user }}
179195
${{ if parameters.configProperties.saUser }}:
180196
saUser: ${{ parameters.configProperties.saUser }}
181-
${{ if parameters.configProperties.password }}:
182-
password: ${{ parameters.configProperties.password }}
183197
${{ if parameters.configProperties.SQLRootPath }}:
184198
SQLRootPath: ${{ parameters.configProperties.SQLRootPath }}
185199
${{ if parameters.configProperties.x64AliasRegistryPath }}:

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ parameters:
77
- name: password
88
type: string
99
default: $(password)
10-
10+
1111
- name: condition
1212
type: string
1313
default: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))
@@ -18,11 +18,9 @@ steps:
1818
sudo systemctl stop mssql-server
1919
2020
# Password for the SA user (required)
21+
2122
MSSQL_SA_PW=${{parameters.password }}
22-
if [ "$MSSQL_SA_PW" = "generated_placeholder" ]; then
23-
exit 0
24-
fi
25-
23+
2624
# Product ID of the version of SQL server you're installing
2725
# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key
2826
MSSQL_PID='enterprise'
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#################################################################################
2+
# Licensed to the .NET Foundation under one or more agreements. #
3+
# The .NET Foundation licenses this file to you under the MIT license. #
4+
# See the LICENSE file in the project root for more information. #
5+
#################################################################################
6+
parameters:
7+
- name: password
8+
type: string
9+
default: $(password)
10+
11+
- name: condition
12+
type: string
13+
default: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'))
14+
15+
steps:
16+
# Linux only steps
17+
- bash: |
18+
# The "user" pipeline variable conflicts with homebrew, causing errors during install. Set it back to the pipeline user.
19+
USER=`whoami`
20+
SQLCMD_ERRORS=$(Agent.TempDirectory)/sqlcmd_err.log
21+
echo $SQLCMD_ERRORS
22+
23+
brew install colima
24+
brew install --cask docker
25+
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
26+
brew update
27+
HOMEBREW_ACCEPT_EULA=Y brew install mssql-tools18
28+
colima start --arch x86_64
29+
docker --version
30+
docker pull mcr.microsoft.com/mssql/server:2022-latest
31+
32+
# Password for the SA user (required)
33+
MSSQL_SA_PW=${{parameters.password }}
34+
35+
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:2022-latest
36+
37+
sleep 5
38+
39+
docker ps -a
40+
41+
# Connect to server and get the version:
42+
counter=1
43+
errstatus=1
44+
while [ $counter -le 20 ] && [ $errstatus = 1 ]
45+
do
46+
echo Waiting for SQL Server to start...
47+
sleep 3
48+
sqlcmd -S 0.0.0.0 -No -U sa -P $MSSQL_SA_PW -Q "SELECT @@VERSION" 2>$SQLCMD_ERRORS
49+
errstatus=$?
50+
((counter++))
51+
done
52+
53+
# Display error if connection failed:
54+
if [ $errstatus = 1 ]
55+
then
56+
echo Cannot connect to SQL Server, installation aborted
57+
cat $SQLCMD_ERRORS
58+
rm -f $SQLCMD_ERRORS
59+
exit $errstatus
60+
else
61+
rm -f $SQLCMD_ERRORS
62+
fi
63+
64+
echo "Use sqlcmd to show which IP addresses are being listened on..."
65+
echo 0.0.0.0
66+
sqlcmd -S 0.0.0.0 -No -U sa -P $MSSQL_SA_PW -Q "SELECT @@VERSION" -l 2
67+
echo 127.0.0.1
68+
sqlcmd -S 127.0.0.1 -No -U sa -P $MSSQL_SA_PW -Q "SELECT @@VERSION" -l 2
69+
echo ::1
70+
sqlcmd -S ::1 -No -U sa -P $MSSQL_SA_PW -Q "SELECT @@VERSION" -l 2
71+
echo localhost
72+
sqlcmd -S localhost -No -U sa -P $MSSQL_SA_PW -Q "SELECT @@VERSION" -l 2
73+
echo "(sqlcmd default / not specified)"
74+
sqlcmd -No -U sa -P $MSSQL_SA_PW -Q "SELECT @@VERSION" -l 2
75+
76+
echo "Configuring Dedicated Administer Connections to allow remote connections..."
77+
sqlcmd -S 0.0.0.0 -No -U sa -P $MSSQL_SA_PW -Q "sp_configure 'remote admin connections', 1; RECONFIGURE;"
78+
if [ $? = 1 ]
79+
then
80+
echo "Error configuring DAC for remote access."
81+
exit $errstatus
82+
else
83+
echo "Configuration complete."
84+
fi
85+
86+
displayName: 'Configure SQL Server [macOS]'
87+
condition: ${{parameters.condition }}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ steps:
9393
parameters:
9494
password: ${{parameters.password}}
9595

96+
- ${{ elseif eq(parameters.operatingSystem, 'Mac') }}:
97+
# macOS only steps
98+
- template: configure-sql-server-macos-step.yml@self
99+
parameters:
100+
password: ${{parameters.password}}
101+
96102
# Common steps
97103
- task: DotNetCoreCLI@2
98104
displayName: 'Build Ext Utilities'

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ steps:
101101

102102
- powershell: |
103103
$password = "${{parameters.password }}"
104-
if ( "generated_placeholder" -eq $password )
105-
{
106-
$password = [guid]::NewGuid().ToString()
107-
}
108-
104+
109105
$machineName = $env:COMPUTERNAME
110106
111107
if ("${{parameters.instanceName }}" -ne "MSSQLSERVER"){

0 commit comments

Comments
 (0)