From e2c5aaf70ac7e766e7665c3d6a46ae6c6c80f0b4 Mon Sep 17 00:00:00 2001 From: Vasilii Polikarpov <126792224+vpolikarpov-akvelon@users.noreply.github.com> Date: Fri, 6 Oct 2023 11:31:36 +0200 Subject: [PATCH] [Windows] Exit on Docker installation failure (#8473) --- .../win/scripts/Installers/Install-Docker.ps1 | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/images/win/scripts/Installers/Install-Docker.ps1 b/images/win/scripts/Installers/Install-Docker.ps1 index cf93e547e..add81b01b 100644 --- a/images/win/scripts/Installers/Install-Docker.ps1 +++ b/images/win/scripts/Installers/Install-Docker.ps1 @@ -20,20 +20,22 @@ Function Get-DockerWincredHash } #endregion -Write-Host "Get latest release of Docker CE" +Write-Host "Get latest Moby release" $mobyLatestReleaseVersion = (Invoke-RestMethod -Uri "https://api.github.com/repos/moby/moby/releases/latest").tag_name.Trim("v") $dockerceUrl = "https://download.docker.com/win/static/stable/x86_64/" $dockerceBinaries = Invoke-WebRequest -Uri $dockerceUrl -UseBasicParsing -Write-Host "Checking $mobyLatestReleaseVersion version" +Write-Host "Check Moby version $mobyLatestReleaseVersion" $mobyRelease = $dockerceBinaries.Links.href -match "${mobyLatestReleaseVersion}\.zip" | Select-Object -Last 1 if (-not $mobyRelease) { Write-Host "Release not found for $mobyLatestRelease version" - $versions = [regex]::Matches($dockerceBinaries.Links.href, "docker-(\d+\.\d+\.\d+)\.zip") | Sort-Object {[version]$_.Groups[1].Value} + $versions = [regex]::Matches($dockerceBinaries.Links.href, "docker-(\d+\.\d+\.\d+)\.zip") | Sort-Object { [version]$_.Groups[1].Value } $mobyRelease = $versions | Select-Object -ExpandProperty Value -Last 1 Write-Host "Found $mobyRelease" } $mobyReleaseUrl = $dockerceUrl + $mobyRelease + +Write-Host "Install Moby $mobyRelease..." $mobyArchivePath = Start-DownloadWithRetry -Url $mobyReleaseUrl -Name $mobyRelease Expand-Archive -Path $mobyArchivePath -DestinationPath $env:TEMP $dockerPath = "$env:TEMP\docker\docker.exe" @@ -43,6 +45,10 @@ Write-Host "Install Docker CE" $instScriptUrl = "https://raw.githubusercontent.com/microsoft/Windows-Containers/Main/helpful_tools/Install-DockerCE/install-docker-ce.ps1" $instScriptPath = Start-DownloadWithRetry -Url $instScriptUrl -Name "install-docker-ce.ps1" & $instScriptPath -DockerPath $dockerPath -DockerDPath $dockerdPath +if ($LastExitCode -ne 0) { + Write-Host "Docker installation failed with exit code $LastExitCode" + exit $exitCode +} # Fix AZ CLI DOCKER_COMMAND_ERROR # cli.azure.cli.command_modules.acr.custom: Could not run 'docker.exe' command. @@ -69,9 +75,9 @@ $distributor_file_hash = Get-DockerWincredHash -Release $dockerCredLatestRelease $local_file_hash = (Get-FileHash -Path 'C:\Windows\System32\docker-credential-wincred.exe' -Algorithm SHA256).Hash if ($local_file_hash -ne $distributor_file_hash) { - Write-Host "hash must be equal to: ${distributor_file_hash}" - Write-Host "actual hash is: ${local_file_hash}" - throw 'Checksum verification failed, please rerun install' + Write-Host "hash must be equal to: ${distributor_file_hash}" + Write-Host "actual hash is: ${local_file_hash}" + throw 'Checksum verification failed, please rerun install' } #endregion @@ -87,4 +93,4 @@ foreach ($dockerImage in $dockerImages) { } } -Invoke-PesterTests -TestFile "Docker" \ No newline at end of file +Invoke-PesterTests -TestFile "Docker"