Skip to content

Commit 1149cc8

Browse files
committed
Support installation of SQL Express 2017
1 parent f53591f commit 1149cc8

File tree

4 files changed

+128
-24
lines changed

4 files changed

+128
-24
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ jobs:
1414
matrix:
1515
os:
1616
# ignore ARM64 flavours
17-
- macos-12-large
18-
- macos-13-large
19-
- macos-14-large
2017
- ubuntu-20.04
2118
- ubuntu-22.04
2219
- ubuntu-24.04
2320
- windows-2019
2421
- windows-2022
22+
version:
23+
- 2017
24+
exclude:
25+
- os: ubuntu-24.04
26+
version: 2017
2527

2628
runs-on: ${{ matrix.os }}
2729
steps:
@@ -36,9 +38,13 @@ jobs:
3638
- name: Run Action
3739
uses: ./action
3840
with:
39-
components: sqlcmd
41+
components: sqlcmd,sqlengine
42+
sa-password: "bHuZH81%cGC6"
43+
version: ${{ matrix.version }}
4044

4145
- name: Run tests
4246
run: |
4347
action/test.ps1
4448
shell: pwsh
49+
env:
50+
SA_PASSWORD: "bHuZH81%cGC6"

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@ inputs:
77
components:
88
description: "The components to install"
99
required: true
10+
sa-password:
11+
description: "The SA password for the SQL instance"
12+
required: true
13+
version:
14+
description: "The version of the SQL instance"
15+
required: true
1016
runs:
1117
using: "composite"
1218
steps:
1319
- shell: pwsh
1420
run: |
1521
$params = @{
1622
Components = ("${{ inputs.components }}" -split ",").Trim()
23+
SaPassword = "${{ inputs.sa-password }}"
24+
Version = "${{ inputs.version }}"
1725
}
1826
1927
${{ github.action_path }}/install.ps1 @params
28+
env:
29+
HOMEBREW_NO_AUTO_UPDATE: "1"

install.ps1

Lines changed: 103 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,113 @@
11
param (
2-
[ValidateSet("sqlcmd")]
3-
[string[]]$Components
2+
[ValidateSet("sqlcmd", "sqlengine")]
3+
[string[]]$Components,
4+
[string]$SaPassword,
5+
[ValidateSet("2017")]
6+
[string]$Version
47
)
58

6-
if ("sqlcmd" -in $Components) {
7-
if ($IsMacOS) {
8-
Write-Output "Installing sqlcmd tools"
9-
brew install sqlcmd
9+
function Wait-ForContainer {
10+
$checkInterval = 5
11+
$containerName = "sql"
12+
$timeout = 120
13+
14+
$startTime = Get-Date
15+
Write-Host "Waiting for the container '$containerName' to be healthy..."
16+
17+
while ($true) {
18+
# Get the container's health status
19+
$healthStatus = (docker inspect --format='{{.State.Health.Status}}' $containerName) 2>&1
20+
21+
if ($healthStatus -eq "healthy") {
22+
Write-Host "Container '$containerName' is healthy."
23+
break
24+
}
25+
elseif ((Get-Date) -gt $startTime.AddSeconds($timeout)) {
26+
Write-Host "Timed out waiting for container '$containerName' to be healthy."
27+
& docker logs sql
28+
exit 1
29+
}
30+
31+
# Wait for the check interval before checking again
32+
Start-Sleep -Seconds $checkInterval
1033
}
34+
}
35+
36+
# figure out if we are running Ubuntu 24.04, as we need to implement a couple of custom behaviours for it
37+
$IsUbuntu2404 = $false
38+
if ($IsLinux) {
39+
$osRelease = Get-Content -Path "/etc/os-release" | Out-String
40+
$osRelease -match 'VERSION_ID="(\d+\.\d+)"' | Out-Null
41+
$IsUbuntu2404 = $matches[1] -eq "24.04"
42+
}
1143

44+
if ("sqlengine" -in $Components) {
1245
if ($IsLinux) {
13-
$osRelease = Get-Content -Path "/etc/os-release" | Out-String
14-
$osRelease -match 'VERSION_ID="(\d+\.\d+)"' | Out-Null
15-
$version = $matches[1]
16-
17-
if ($version -eq "24.04") {
18-
# for maintenance reasons, sqlcmd has been removed from the runner image
19-
# but a dedicated build is also not yet available, so we are using the Ubuntu 22.04 build
20-
Write-Output "Installing sqlcmd tools"
21-
22-
$DownloadPath = "/tmp/sqlcmd.deb"
23-
Invoke-WebRequest "https://packages.microsoft.com/ubuntu/22.04/prod/pool/main/s/sqlcmd/sqlcmd_1.5.0-1_jammy_all.deb" -OutFile $DownloadPath
24-
& sudo dpkg -i $DownloadPath
25-
Remove-Item $DownloadPath
46+
# the Ubuntu 24.04 image uses a kernel version which does not work with the current 2017 version.
47+
# see https://github.com/microsoft/mssql-docker/issues/868
48+
49+
# but also manual installation is difficult since MSSQL has been released for Ubuntu 18.04 only
50+
# you could backport all of this somehow, but 2017 is EOL soon anyhow
51+
# $ apt install --fix-broken -y ./mssql-server_14.0.3465.1-1_amd64.deb
52+
# Reading package lists... Done
53+
# Building dependency tree... Done
54+
# Reading state information... Done
55+
# Correcting dependencies... Done
56+
# Note, selecting 'mssql-server' instead of './mssql-server_14.0.3465.1-1_amd64.deb'
57+
# mssql-server is already the newest version (14.0.3465.1-1).
58+
# Some packages could not be installed. This may mean that you have
59+
# requested an impossible situation or if you are using the unstable
60+
# distribution that some required packages have not yet been created
61+
# or been moved out of Incoming.
62+
# The following information may help to resolve the situation:
63+
64+
# The following packages have unmet dependencies:
65+
# mssql-server : Depends: libjemalloc1 but it is not installable
66+
# Depends: libssl1.0.0 but it is not installable
67+
# Depends: python (>= 2.7.0) but it is not installable
68+
# Depends: libldap-2.4-2 but it is not installable
69+
# E: Unable to correct problems, you have held broken packages.
70+
if ($IsUbuntu2404) {
71+
Write-Error "MSSQL 2017 is not available on Ubuntu 24.04."
72+
Write-Error "See more information at https://github.com/microsoft/mssql-docker/issues/868"
73+
exit 1
2674
}
75+
76+
Write-Output "Starting a Docker Container"
77+
Invoke-Expression "docker run --name=`"sql`" -e `"ACCEPT_EULA=Y`"-e `"SA_PASSWORD=$SaPassword`" -e `"MSSQL_PID=Express`" --health-cmd=`"/opt/mssql-tools/bin/sqlcmd -C -S localhost -U sa -P '$SaPassword' -Q 'SELECT 1' -b -o /dev/null`" --health-start-period=`"10s`" --health-retries=3 --health-interval=`"10s`" -p 1433:1433 -d `"mcr.microsoft.com/mssql/server:$Version-latest`""
78+
Wait-ForContainer
79+
}
80+
81+
if ($IsWindows) {
82+
Write-Output "Downloading and installing SQL Server"
83+
New-Item -ItemType Directory -Path "C:\Downloads"
84+
85+
Invoke-WebRequest "https://download.microsoft.com/download/E/F/2/EF23C21D-7860-4F05-88CE-39AA114B014B/SQLEXPR_x64_ENU.exe" -OutFile "C:\Downloads\mssql.exe"
86+
Start-Process -Wait -FilePath "C:\Downloads\mssql.exe" -ArgumentList /qs, /x:"C:\Downloads\setup"
87+
C:\Downloads\setup\setup.exe /q /ACTION=Install /INSTANCENAME=SQLEXPRESS /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT='NT AUTHORITY\System' /SQLSYSADMINACCOUNTS='BUILTIN\ADMINISTRATORS' /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS
88+
89+
Write-Host "Configuring SQL Express ..."
90+
stop-service MSSQL`$SQLEXPRESS
91+
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value ''
92+
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433
93+
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\' -name LoginMode -value 2
94+
95+
Write-Host "Starting SQL Express ..."
96+
start-service MSSQL`$SQLEXPRESS
97+
& sqlcmd -Q "ALTER LOGIN sa with password='$SaPassword'; ALTER LOGIN sa ENABLE;"
98+
}
99+
}
100+
101+
if ("sqlcmd" -in $Components) {
102+
if ($IsUbuntu2404) {
103+
# for maintenance reasons, sqlcmd has been removed from the Ubuntu 24.04 runner image
104+
# but a dedicated build is also not yet available, so we are using the Ubuntu 22.04 build
105+
Write-Output "Installing sqlcmd tools"
106+
107+
$DownloadPath = "/tmp/sqlcmd.deb"
108+
Invoke-WebRequest "https://packages.microsoft.com/ubuntu/22.04/prod/pool/main/s/sqlcmd/sqlcmd_1.5.0-1_jammy_all.deb" -OutFile $DownloadPath
109+
& sudo dpkg -i $DownloadPath
110+
Remove-Item $DownloadPath
27111
}
28112

29113
# Linux and Windows runner already contain sqlclient tools

test.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
if (Get-Command sqlcmd -ErrorAction SilentlyContinue) {
22
Write-Output "sqlcmd command exists."
3-
} else {
3+
}
4+
else {
45
Write-Output "sqlcmd command does not exist."
56
exit 1
67
}
8+
9+
Write-Output "Checking if SQL Server is available ..."
10+
& sqlcmd -S 127.0.0.1 -U sa -P $env:SA_PASSWORD -Q "SELECT 1"

0 commit comments

Comments
 (0)