Skip to content

Commit

Permalink
Improve Windows provisioners stability (#733)
Browse files Browse the repository at this point in the history
* Improve Install-CloudFoundryCli.ps1

* Improve Install-Go.ps1

* Improve Install-Kind.ps1

* Improve Install-MysqlCli.ps1

* Improve Install-Rust.ps1

* Improve Install-SQLPowerShellTools.ps1

* Improve Update-AndroidSDK.ps1

* Fix issue with resolve
  • Loading branch information
vmapetr authored May 5, 2020
1 parent c7bd585 commit 33f6bf1
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 87 deletions.
17 changes: 8 additions & 9 deletions images/win/scripts/Installers/Install-CloudFoundryCli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
Import-Module -Name ImageHelpers

# Download the latest cf cli exe
Invoke-WebRequest -UseBasicParsing -Uri "https://packages.cloudfoundry.org/stable?release=windows64-exe&source=github" -OutFile cf-cli.zip
$CloudFoundryCliName = "cf-cli.zip"
$CloudFoundryCliUrl = "https://packages.cloudfoundry.org/stable?release=windows64-exe&source=github"

$CloudFoundryArchPath = Start-DownloadWithRetry -Url $CloudFoundryCliUrl -Name $CloudFoundryCliName

# Create directory for cf cli
$cf_cli_path = "C:\cf-cli"
New-Item -Path $cf_cli_path -ItemType Directory -Force
$CloudFoundryCliPath = "C:\cf-cli"
New-Item -Path $CloudFoundryCliPath -ItemType Directory -Force

# Extract the zip archive
Write-Host "Extracting cf cli..."
Expand-Archive -Path cf-cli.zip -DestinationPath $cf_cli_path -Force
Expand-Archive -Path $CloudFoundryArchPath -DestinationPath $CloudFoundryCliPath -Force

# Add cf to path
Add-MachinePathItem $cf_cli_path

# Delete the cfl-cli zip archive
Write-Host "Deleting downloaded archive of cf cli"
Remove-Item cf-cli.zip
Add-MachinePathItem $CloudFoundryCliPath
28 changes: 17 additions & 11 deletions images/win/scripts/Installers/Install-Go.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
Import-Module -Name ImageHelpers -Force

$refsJson = Invoke-RestMethod "https://api.github.com/repos/golang/go/git/refs/tags"

function Install-GoVersion
{
Param
(
[String]$goVersion,
[Switch]$addToDefaultPath
[String] $goVersion,
[Switch] $addToDefaultPath
)

$latestVersionObject = $refsJson | Where-Object { $_.ref -Match "refs/tags/go$goVersion[./d]*" } | Select-Object -Last 1
Expand All @@ -20,11 +21,15 @@ function Install-GoVersion
# Download the Go zip archive.
Write-Host "Downloading Go $latestVersion..."
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -UseBasicParsing -Uri "https://dl.google.com/go/go$latestVersion.windows-amd64.zip" -OutFile go$latestVersion.windows-amd64.zip

$goArchName = "go${latestVersion}.windows-amd64.zip"
$goArchUrl = "https://dl.google.com/go/${goArchName}"

$goArchPath = Start-DownloadWithRetry -Url $goArchUrl -Name $goArchName

# Extract the zip archive. It contains a single directory named "go".
Write-Host "Extracting Go $latestVersion..."
Expand-Archive -Path go$latestVersion.windows-amd64.zip -DestinationPath "C:\" -Force
Expand-Archive -Path $goArchPath -DestinationPath "C:\" -Force

# Delete unnecessary files to conserve space
Write-Host "Cleaning directories of Go $latestVersion..."
Expand All @@ -41,10 +46,6 @@ function Install-GoVersion
$newDirName = "Go$latestVersion"
Rename-Item -path "C:\go" -newName $newDirName

# Delete the Go zip archive.
Write-Host "Deleting downloaded archive of Go $latestVersion..."
Remove-Item go$latestVersion.windows-amd64.zip

# Make this the default version of Go?
if ($addToDefaultPath)
{
Expand All @@ -63,13 +64,18 @@ function Install-GoVersion
# Install Go
$goVersionsToInstall = $env:GO_VERSIONS.split(", ", [System.StringSplitOptions]::RemoveEmptyEntries)

foreach($go in $goVersionsToInstall) {
foreach ($go in $goVersionsToInstall)
{
Write-Host "Installing Go ${go}"
if($go -eq $env:GO_DEFAULT) {
if ($go -eq $env:GO_DEFAULT)
{
$installDirectory = Install-GoVersion -goVersion $go -addToDefaultPath
} else {
}
else
{
$installDirectory = Install-GoVersion -goVersion $go
}

$envName = "GOROOT_{0}_{1}_X64" -f $go.split(".")
setx $envName "$installDirectory" /M
}
9 changes: 4 additions & 5 deletions images/win/scripts/Installers/Install-Kind.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@
$stableKindTag = "v0.7.0"
$tagToUse = $stableKindTag;
$destFilePath = "C:\ProgramData\kind"
$outFilePath = "C:\ProgramData\kind\kind.exe"

try
{
$getkindUri = "https://github.com/kubernetes-sigs/kind/releases/download/$tagToUse/kind-windows-amd64"
$kindUrl = "https://github.com/kubernetes-sigs/kind/releases/download/$tagToUse/kind-windows-amd64"

Write-Host "Downloading kind.exe..."
New-Item -Path $destFilePath -ItemType Directory -Force

Invoke-WebRequest -Uri $getkindUri -OutFile $outFilePath
$kindInstallerPath = Start-DownloadWithRetry -Url $kindUrl -Name "kind.exe" -DownloadPath $destFilePath

Write-Host "Starting Install kind.exe..."
$process = Start-Process -FilePath $outFilePath -Wait -PassThru
$process = Start-Process -FilePath $kindInstallerPath -Wait -PassThru
$exitCode = $process.ExitCode

if ($exitCode -eq 0 -or $exitCode -eq 3010)
{
Write-Host -Object 'Installation successful'
Add-MachinePathItem $destFilePath
exit $exitCode
}
else
{
Expand Down
13 changes: 5 additions & 8 deletions images/win/scripts/Installers/Install-MysqlCli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
## Desc: Install Mysql CLI
################################################################################


## Downloading mysql jar
$uri = 'https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-winx64.zip'
$mysqlPath = 'C:\mysql-5.7.21-winx64\bin'
$MysqlVersionName = "mysql-5.7.21-winx64"
$MysqlVersionUrl = "https://dev.mysql.com/get/Downloads/MySQL-5.7/${MysqlVersionName}.zip"
$MysqlPath = "C:\$MysqlVersionName\bin"

# Installing visual c++ redistibutable package.
$InstallerName = "vcredist_x64.exe"
Expand All @@ -19,13 +19,10 @@ Install-Binary -Url $InstallerURI -Name $InstallerName -ArgumentList $ArgumentLi
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor "Tls12"

# Get the latest mysql command line tools .
Invoke-WebRequest -UseBasicParsing -Uri $uri -OutFile mysql.zip
$mysqlArchPath = Start-DownloadWithRetry -Url $MysqlVersionUrl -Name "mysql.zip"

# Expand the zip
Expand-Archive -Path mysql.zip -DestinationPath "C:\" -Force

# Deleting zip folder
Remove-Item -Recurse -Force mysql.zip
Expand-Archive -Path $mysqlArchPath -DestinationPath "C:\" -Force

# Adding mysql in system environment path
Add-MachinePathItem $mysqlPath
7 changes: 2 additions & 5 deletions images/win/scripts/Installers/Install-Rust.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ $env:CARGO_HOME="C:\Rust\.cargo"

# Download the latest rustup-init.exe for Windows x64
# See https://rustup.rs/#
Invoke-WebRequest -UseBasicParsing -Uri "https://win.rustup.rs/x86_64" -OutFile rustup-init.exe
$rustupPath = Start-DownloadWithRetry -Url "https://win.rustup.rs/x86_64" -Name "rustup-init.exe"

# Install Rust by running rustup-init.exe (disabling the confirmation prompt with -y)
.\rustup-init.exe -y --default-toolchain=stable --profile=minimal

# Delete rustup-init.exe when it's no longer needed
Remove-Item -Path .\rustup-init.exe
& $rustupPath -y --default-toolchain=stable --profile=minimal

# Add Rust binaries to the path
Add-MachinePathItem "$env:CARGO_HOME\bin"
Expand Down
58 changes: 11 additions & 47 deletions images/win/scripts/Installers/Install-SQLPowerShellTools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,21 @@

Import-Module -Name ImageHelpers -Force

Function InstallMSI
{
Param
(
[String]$MsiUrl,
[String]$MsiName
)

$exitCode = -1

try
{
Write-Host "Downloading $MsiName..."
$FilePath = "${env:Temp}\$MsiName"

Invoke-WebRequest -Uri $MsiUrl -OutFile $FilePath

$Arguments = ('/i', $FilePath, '/QN', '/norestart' )

Write-Host "Starting Install $MsiName..."
$process = Start-Process -FilePath msiexec.exe -ArgumentList $Arguments -Wait -PassThru
$exitCode = $process.ExitCode

if ($exitCode -eq 0 -or $exitCode -eq 3010)
{
Write-Host -Object 'Installation successful'
return $exitCode
}
else
{
Write-Host -Object "Non zero exit code returned by the installation process : $exitCode."
exit $exitCode
}
}
catch
{
Write-Host -Object "Failed to install the MSI $MsiName"
Write-Host -Object $_.Exception.Message
exit -1
}
}
$BaseUrl = "https://download.microsoft.com/download/8/7/2/872BCECA-C849-4B40-8EBE-21D48CDF1456/ENU/x64"

# install required MSIs
$SQLSysClrTypesExitCode = InstallMSI -MsiUrl "https://download.microsoft.com/download/8/7/2/872BCECA-C849-4B40-8EBE-21D48CDF1456/ENU/x64/SQLSysClrTypes.msi" -MsiName "SQLSysClrTypes.msi"
$SQLSysClrTypesName = "SQLSysClrTypes.msi"
$SQLSysClrTypesUrl = "${BaseUrl}/${SQLSysClrTypesName}"
Install-Binary -Url $SQLSysClrTypesUrl -Name $SQLSysClrTypesName

$SharedManagementObjectsExitCode = InstallMSI -MsiUrl "https://download.microsoft.com/download/8/7/2/872BCECA-C849-4B40-8EBE-21D48CDF1456/ENU/x64/SharedManagementObjects.msi" -MsiName "SharedManagementObjects.msi"
$SharedManagementObjectsName = "SharedManagementObjects.msi"
$SharedManagementObjectsUrl = "${BaseUrl}/${SharedManagementObjectsName}"
Install-Binary -Url $SharedManagementObjectsUrl -Name $SharedManagementObjectsName

$PowerShellToolsExitCode = InstallMSI -MsiUrl "https://download.microsoft.com/download/8/7/2/872BCECA-C849-4B40-8EBE-21D48CDF1456/ENU/x64/PowerShellTools.msi" -MsiName "PowerShellTools.msi"
$PowerShellToolsName = "PowerShellTools.msi"
$PowerShellToolsUrl = "${BaseUrl}/${PowerShellToolsName}"
Install-Binary -Url $PowerShellToolsUrl -Name $PowerShellToolsName

# install sqlserver PS module
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name SqlServer -AllowClobber

exit $PowerShellToolsExitCode
Install-Module -Name SqlServer -AllowClobber
4 changes: 2 additions & 2 deletions images/win/scripts/Installers/Update-AndroidSDK.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

# Download the latest command line tools so that we can accept all of the licenses.
# See https://developer.android.com/studio/#command-tools
Invoke-WebRequest -UseBasicParsing -Uri "https://dl.google.com/android/repository/sdk-tools-windows-4333796.zip" -OutFile android-sdk-tools.zip
$sdkArchPath = Start-DownloadWithRetry -Url "https://dl.google.com/android/repository/sdk-tools-windows-4333796.zip" -Name "android-sdk-tools.zip"

# Don't replace the one that VS installs as it seems to break things.
Expand-Archive -Path android-sdk-tools.zip -DestinationPath android-sdk -Force
Expand-Archive -Path $sdkArchPath -DestinationPath android-sdk -Force

$sdk = Get-Item -Path .\android-sdk

Expand Down

0 comments on commit 33f6bf1

Please sign in to comment.