|
1 | 1 | param (
|
2 |
| - [ValidateSet("sqlcmd")] |
3 |
| - [string[]]$Components |
| 2 | + [ValidateSet("sqlcmd", "sqlengine")] |
| 3 | + [string[]]$Components, |
| 4 | + [string]$SaPassword, |
| 5 | + [ValidateSet("2017")] |
| 6 | + [string]$Version |
4 | 7 | )
|
5 | 8 |
|
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 |
10 | 33 | }
|
| 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 | +} |
11 | 43 |
|
| 44 | +if ("sqlengine" -in $Components) { |
12 | 45 | 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 |
26 | 74 | }
|
| 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 |
27 | 111 | }
|
28 | 112 |
|
29 | 113 | # Linux and Windows runner already contain sqlclient tools
|
|
0 commit comments