Try to get the bootstrap to run on Windows runner

This commit is contained in:
Shane Lee 2024-03-28 09:36:22 -06:00
parent 0c8f4470bc
commit e8e28c0a4d
No known key found for this signature in database
GPG key ID: 9B77EE3C5C0D9F63
3 changed files with 95 additions and 32 deletions

View file

@ -565,7 +565,7 @@
- add apt-transport-https for ubuntu. (epcim) #896 - add apt-transport-https for ubuntu. (epcim) #896
- Fix expanding shell script position parameters with nounset enabled. (vutny) #895 - Fix expanding shell script position parameters with nounset enabled. (vutny) #895
- RFC: Add tests for bootstrap-salt.ps1. (themalkolm) #893 - RFC: Add tests for bootstrap-salt.ps1. (themalkolm) #893
- Keep original name of salt executable executable. (themalkolm) #857 - Keep original name of salt executable. (themalkolm) #857
# v2016.06.27: # v2016.06.27:

View file

@ -14,21 +14,21 @@
install the latest version of Salt install the latest version of Salt
.EXAMPLE .EXAMPLE
./bootstrap-salt.ps1 -version 3006.7 ./bootstrap-salt.ps1 -Version 3006.7
Specifies a particular version of the installer. Specifies a particular version of the installer.
.EXAMPLE .EXAMPLE
./bootstrap-salt.ps1 -runservice false ./bootstrap-salt.ps1 -RunService false
Specifies the salt-minion service to stop and be set to manual. Useful for Specifies the salt-minion service to stop and be set to manual. Useful for
testing locally from the command line with the --local switch testing locally from the command line with the --local switch
.EXAMPLE .EXAMPLE
./bootstrap-salt.ps1 -minion minion-box -master master-box ./bootstrap-salt.ps1 -Minion minion-box -Master master-box
Specifies the minion and master ids in the minion config. Defaults to the Specifies the minion and master ids in the minion config. Defaults to the
installer values of host name for the minion id and "salt" for the master. installer values of host name for the minion id and "salt" for the master.
.EXAMPLE .EXAMPLE
./bootstrap-salt.ps1 -minion minion-box -master master-box -version 3006.7 -runservice false ./bootstrap-salt.ps1 -Minion minion-box -Master master-box -Version 3006.7 -RunService false
Specifies all the optional parameters in no particular order. Specifies all the optional parameters in no particular order.
.NOTES .NOTES
@ -243,6 +243,7 @@ function Get-FileHash {
} }
} catch { } catch {
Write-Verbose "Error hashing: $Path" Write-Verbose "Error hashing: $Path"
Write-Verbose "ERROR: $_"
return @{} return @{}
} finally { } finally {
if ($null -ne $data) { if ($null -ne $data) {
@ -404,24 +405,30 @@ $saltSha512= ""
$saltFileUrl = "" $saltFileUrl = ""
# Look for a repo.json file # Look for a repo.json file
try { try {
Write-Verbose "Looking for $RepoUrl/repo.json"
$response = Invoke-WebRequest "$RepoUrl/repo.json" ` $response = Invoke-WebRequest "$RepoUrl/repo.json" `
-DisableKeepAlive ` -DisableKeepAlive `
-UseBasicParsing ` -UseBasicParsing `
-Method Head -Method Head
if ( $response.StatusCode -eq "200" ) { if ( $response.StatusCode -eq "200" ) {
Write-Verbose "Found $RepoUrl/repo.json"
# This URL contains a repo.json file, let's use it # This URL contains a repo.json file, let's use it
$use_repo_json = $true $use_repo_json = $true
} else { } else {
# Write-Verbose "Did not find $RepoUrl/repo.json"
# No repo.json file found at the default location
$use_repo_json = $false $use_repo_json = $false
} }
} catch { } catch {
Write-Verbose "There was an error looking up $RepoUrl/repo.json"
Write-Verbose "ERROR: $_"
$use_repo_json = $false $use_repo_json = $false
} }
if ( $use_repo_json ) { if ( $use_repo_json ) {
# We will use the json file to get the name of the installer # We will use the json file to get the name of the installer
$enc = [System.Text.Encoding]::UTF8 $enc = [System.Text.Encoding]::UTF8
try { try {
Write-Verbose "Downloading $RepoUrl/repo.json"
$response = Invoke-WebRequest -Uri "$RepoUrl/repo.json" -UseBasicParsing $response = Invoke-WebRequest -Uri "$RepoUrl/repo.json" -UseBasicParsing
if ($response.Content.GetType().Name -eq "Byte[]") { if ($response.Content.GetType().Name -eq "Byte[]") {
$psobj = $enc.GetString($response.Content) | ConvertFrom-Json $psobj = $enc.GetString($response.Content) | ConvertFrom-Json
@ -431,14 +438,16 @@ if ( $use_repo_json ) {
$hash = Convert-PSObjectToHashtable $psobj $hash = Convert-PSObjectToHashtable $psobj
} catch { } catch {
Write-Verbose "repo.json not found at: $RepoUrl" Write-Verbose "repo.json not found at: $RepoUrl"
Write-Host "ERROR: $_"
$hash = @{} $hash = @{}
} }
$searchVersion = $Version.ToLower() $searchVersion = $Version.ToLower()
if ( $hash.Contains($searchVersion)) { if ( $hash.Contains($searchVersion)) {
Write-Verbose "Found $searchVersion in $RepoUrl/repo.json"
foreach ($item in $hash.($searchVersion).Keys) { foreach ($item in $hash.($searchVersion).Keys) {
if ( $item.EndsWith(".exe") ) { if ( $item.ToLower().EndsWith(".exe") ) {
if ( $item.Contains($arch) ) { if ( $item.ToLower().Contains($arch.ToLower()) ) {
$saltFileName = $hash.($searchVersion).($item).name $saltFileName = $hash.($searchVersion).($item).name
$saltVersion = $hash.($searchVersion).($item).version $saltVersion = $hash.($searchVersion).($item).version
$saltSha512 = $hash.($searchVersion).($item).SHA512 $saltSha512 = $hash.($searchVersion).($item).SHA512
@ -447,6 +456,7 @@ if ( $use_repo_json ) {
} }
} else { } else {
try { try {
Write-Verbose "Searching for $searchVersion in $RepoUrl/minor/repo.json"
$response = Invoke-WebRequest -Uri "$RepoUrl/minor/repo.json" -UseBasicParsing $response = Invoke-WebRequest -Uri "$RepoUrl/minor/repo.json" -UseBasicParsing
if ($response.Content.GetType().Name -eq "Byte[]") { if ($response.Content.GetType().Name -eq "Byte[]") {
$psobj = $enc.GetString($response.Content) | ConvertFrom-Json $psobj = $enc.GetString($response.Content) | ConvertFrom-Json
@ -455,13 +465,15 @@ if ( $use_repo_json ) {
} }
$hash = Convert-PSObjectToHashtable $psobj $hash = Convert-PSObjectToHashtable $psobj
} catch { } catch {
Write-Verbose "repo.json not found at: $RepoUrl" Write-Verbose "repo.json not found at: $RepoUrl/minor/repo.json"
Write-Verbose "ERROR: $_"
$hash = @{} $hash = @{}
} }
if ( $hash.Contains($searchVersion)) { if ( $hash.Contains($searchVersion)) {
Write-Verbose "Found $searchVersion in $RepoUrl/minor/repo.json"
foreach ($item in $hash.($searchVersion).Keys) { foreach ($item in $hash.($searchVersion).Keys) {
if ( $item.EndsWith(".exe") ) { if ( $item.ToLower().EndsWith(".exe") ) {
if ( $item.Contains($arch) ) { if ( $item.ToLower().Contains($arch.ToLower()) ) {
$saltFileName = $hash.($searchVersion).($item).name $saltFileName = $hash.($searchVersion).($item).name
$saltVersion = $hash.($searchVersion).($item).version $saltVersion = $hash.($searchVersion).($item).version
$saltSha512 = $hash.($searchVersion).($item).SHA512 $saltSha512 = $hash.($searchVersion).($item).SHA512
@ -469,25 +481,59 @@ if ( $use_repo_json ) {
} }
} }
} else { } else {
Write-Host "Version not found in $RepoUrl/repo.json" Write-Verbose "Version not found in $RepoUrl/minor/repo.json"
exit 1
} }
} }
if ( $saltFileName -and $saltVersion -and $saltSha512 ) { }
if ( $RepoUrl.Contains("minor") ) {
$saltFileUrl = @($RepoUrl, $saltVersion, $saltFileName) -join "/" if ( $saltFileName -and $saltVersion -and $saltSha512 ) {
} else { Write-Verbose "Found Name, Version, and Sha"
$saltFileUrl = @($RepoUrl, "minor", $saltVersion, $saltFileName) -join "/"
}
} else {
Write-Host "Failed to get Name, Version, and Sha"
exit 1
}
} else { } else {
# We will guess the name of the installer # We will guess the name of the installer
Write-Verbose "Failed to get Name, Version, and Sha from repo.json"
Write-Verbose "We'll try to find the file in standard paths"
$saltFileName = "Salt-Minion-$Version-Py3-$arch-Setup.exe" $saltFileName = "Salt-Minion-$Version-Py3-$arch-Setup.exe"
$saltVersion = $Version $saltVersion = $Version
$saltFileUrl = "$RepoUrl/$saltFileName" }
Write-Verbose "Creating list of urls using the following:"
Write-Verbose "RepoUrl: $RepoUrl"
Write-Verbose "Version: $saltVersion"
Write-Verbose "File Name: $saltFileName"
$urls = $(@($RepoUrl, $saltVersion, $saltFileName) -join "/"),
$(@($RepoUrl, "minor", $saltVersion, $saltFileName) -join "/"),
$(@($RepoUrl, $saltFileName) -join "/"),
$(@($oldRepoUrl, $saltFileName) -join "/")
$saltFileUrl = $null
foreach ($url in $urls) {
try {
Write-Verbose "Looking for installer at: $url"
$response = Invoke-WebRequest "$url" `
-DisableKeepAlive `
-UseBasicParsing `
-Method Head
if ( $response.StatusCode -eq "200" ) {
Write-Verbose "Found installer"
# This URL contains a repo.json file, let's use it
$saltFileUrl = $url
break
} else {
Write-Verbose "Installer not found: $url"
}
} catch {
Write-Verbose "ERROR: $url"
}
}
if ( !$saltFileUrl ) {
Write-Host "Could not find an installer:"
Write-Verbose "Here are the urls searched:"
foreach ($url in $urls) {
Write-Verbose $url
}
exit 1
} }
@ -503,9 +549,15 @@ Write-Host " - master: $Master"
Write-Host " - minion id: $Minion" Write-Host " - minion id: $Minion"
Write-Host " - start service: $RunService" Write-Host " - start service: $RunService"
Write-Host "-------------------------------------------------------------------------------" -ForegroundColor Yellow Write-Host "-------------------------------------------------------------------------------" -ForegroundColor Yellow
Write-Host "Downloading Installer: " -NoNewline
$webclient = New-Object System.Net.WebClient
$localFile = "$env:TEMP\$saltFileName" $localFile = "$env:TEMP\$saltFileName"
Write-Host "Downloading Installer: " -NoNewline
Write-Verbose ""
Write-Verbose "Salt File URL: $saltFileUrl"
Write-Verbose "Local File: $localFile"
$webclient = New-Object System.Net.WebClient
$webclient.DownloadFile($saltFileUrl, $localFile) $webclient.DownloadFile($saltFileUrl, $localFile)
if ( Test-Path -Path $localFile ) { if ( Test-Path -Path $localFile ) {
@ -517,6 +569,9 @@ if ( Test-Path -Path $localFile ) {
if ( $saltSha512 ) { if ( $saltSha512 ) {
$localSha512 = (Get-FileHash -Path $localFile -Algorithm SHA512).Hash $localSha512 = (Get-FileHash -Path $localFile -Algorithm SHA512).Hash
Write-Host "Comparing Hash: " -NoNewline Write-Host "Comparing Hash: " -NoNewline
Write-Verbose ""
Write-Verbose "Local Hash: $localSha512"
Write-Verbose "Remote Hash: $saltSha512"
if ( $localSha512 -eq $saltSha512 ) { if ( $localSha512 -eq $saltSha512 ) {
Write-Host "Success" -ForegroundColor Green Write-Host "Success" -ForegroundColor Green
} else { } else {
@ -539,14 +594,19 @@ if($Master -ne "not-specified") {$parameters = "$parameters /master=$Master"}
#=============================================================================== #===============================================================================
# Install minion silently # Install minion silently
#=============================================================================== #===============================================================================
Write-Host "Installing Salt Minion: " -NoNewline Write-Host "Installing Salt Minion (5 min timeout): " -NoNewline
Write-Verbose ""
Write-Verbose "Local File: $localFile"
Write-Verbose "Parameters: $parameters"
$process = Start-Process $localFile ` $process = Start-Process $localFile `
-WorkingDirectory $(Split-Path $test -Parent) ` -WorkingDirectory $(Split-Path $localFile -Parent) `
-ArgumentList "/S /start-service=0 $parameters" ` -ArgumentList "/S /start-service=0 $parameters" `
-NoNewWindow -PassThru -NoNewWindow -PassThru
# Sometimes the installer hangs... we'll wait 60s and then kill it # Sometimes the installer hangs... we'll wait 5 minutes and then kill it
$process | Wait-Process -Timeout 60 -ErrorAction SilentlyContinue Write-Verbose ""
Write-Verbose "Waiting for installer to finish"
$process | Wait-Process -Timeout 300 -ErrorAction SilentlyContinue
$process.Refresh() $process.Refresh()
if ( !$process.HasExited ) { if ( !$process.HasExited ) {
@ -568,7 +628,8 @@ if ( !$process.HasExited ) {
# installation # installation
$service = Get-Service salt-minion -ErrorAction SilentlyContinue $service = Get-Service salt-minion -ErrorAction SilentlyContinue
$tries = 0 $tries = 0
$max_tries = 5 # We'll try for 10 seconds $max_tries = 15 # We'll try for 30 seconds
Write-Verbose "Checking that the service is installed"
while ( ! $service ) { while ( ! $service ) {
# We'll keep trying to get a service object until we're successful, or we # We'll keep trying to get a service object until we're successful, or we
# reach max_tries # reach max_tries
@ -594,6 +655,7 @@ Write-Host "Success" -ForegroundColor Green
if( $RunService ) { if( $RunService ) {
# Start the service # Start the service
Write-Host "Starting Service: " -NoNewline Write-Host "Starting Service: " -NoNewline
Write-Verbose ""
$tries = 0 $tries = 0
# We'll try for 2 minutes, sometimes the minion takes that long to start as # We'll try for 2 minutes, sometimes the minion takes that long to start as
# it compiles python code for the first time # it compiles python code for the first time
@ -603,6 +665,7 @@ if( $RunService ) {
Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue
} }
Start-Sleep -Seconds 2 Start-Sleep -Seconds 2
Write-Verbose "Checking the service status"
$service.Refresh() $service.Refresh()
if ( $service.Status -eq "Running" ) { if ( $service.Status -eq "Running" ) {
Write-Host "Success" -ForegroundColor Green Write-Host "Success" -ForegroundColor Green

View file

@ -9,7 +9,7 @@ driver:
provisioner: provisioner:
salt_bootstrap_url: D:/a/salt-bootstrap/salt-bootstrap/bootstrap-salt.ps1 salt_bootstrap_url: D:/a/salt-bootstrap/salt-bootstrap/bootstrap-salt.ps1
salt_bootstrap_options: -Version %s salt_bootstrap_options: -Version %s -Verbose
init_environment: '' init_environment: ''
platforms: platforms: