summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2020-04-05 20:23:31 -0400
committerBryan McLellan <btm@loftninjas.org>2020-04-06 10:59:44 -0400
commitaa7277fa9749f71e0702a5016abed6cc7b69b158 (patch)
tree06583cb9c28175b9ad828dfb4833cfb495e9c9d7 /scripts
parent7696937f41e3476547e68b2e0ea20641eb10a0f2 (diff)
downloadchef-aa7277fa9749f71e0702a5016abed6cc7b69b158.tar.gz
Download and verify the Ruby installer, then move into place
This should reduce or remove race conditions while downloading the same file on multiple container instances. Signed-off-by: Bryan McLellan <btm@loftninjas.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bk_tests/bk_win_functional.ps147
1 files changed, 33 insertions, 14 deletions
diff --git a/scripts/bk_tests/bk_win_functional.ps1 b/scripts/bk_tests/bk_win_functional.ps1
index 56dd82f9b4..5bcbfb60c9 100644
--- a/scripts/bk_tests/bk_win_functional.ps1
+++ b/scripts/bk_tests/bk_win_functional.ps1
@@ -12,16 +12,39 @@ $RubyS3Path = "s3://public-cd-buildkite-cache/$RubyFilename"
Function DownloadRuby
{
+ $RandDigits = Get-Random
echo "Downloading Ruby + DevKit"
- aws s3 cp $RubyS3Path $RubyPath | Out-Null # Out-Null is a hack to wait for the process to complete
- if ($LASTEXITCODE -ne 0)
- {
+ aws s3 cp "$RubyS3Path" "$RubyPath.$RandDigits" | Out-Null # Out-Null is a hack to wait for the process to complete
+
+ if ($LASTEXITCODE -ne 0) {
echo "aws s3 download failed: $LASTEXITCODE"
exit $LASTEXITCODE
}
- $DownloadedHash = (Get-FileHash $RubyPath -Algorithm SHA256).Hash
- echo "Downloaded SHA256: $DownloadedHash"
+
+ $FileHash = (Get-FileHash "$RubyPath.$RandDigits" -Algorithm SHA256).Hash
+ If ($FileHash -eq $RubySHA256) {
+ echo "Downloaded SHA256 matches: $FileHash"
+ } Else {
+ echo "Downloaded file hash $FileHash does not match desired $RubySHA256"
+ exit 1
+ }
+
+ # On a shared filesystem, sometimes a good file appears while we are downloading
+ If (Test-Path $RubyPath) {
+ $FileHash = (Get-FileHash "$RubyPath" -Algorithm SHA256).Hash
+ If ($FileHash -eq $RubySHA256) {
+ echo "A matching file appeared while downloading, using it."
+ Remove-Item "$RubyPath.$RandDigits" -Force
+ Return
+ } Else {
+ echo "Existing file does not match, bad hash: $FileHash"
+ Remove-Item $RubyPath -Force
+ }
+ }
+
+ echo "Moving file installer into place"
+ Rename-Item -Path "$RubyPath.$RandDigits" -NewName $RubyFilename
}
Function InstallRuby
@@ -29,16 +52,12 @@ Function InstallRuby
If (Test-Path $RubyPath) {
echo "$RubyPath already exists"
- $ExistingRubyHash = (Get-FileHash $RubyPath -Algorithm SHA256).Hash
-
- echo "Verifying file SHA256 hash $ExistingRubyHash to desired hash $RubySHA256"
-
- If ($ExistingRubyHash -ne $RubySHA256) {
- echo "SHA256 hash mismatch, attempting to remove and re-download"
- Remove-Item $RubyPath -Force
- DownloadRuby
- } Else {
+ $FileHash = (Get-FileHash "$RubyPath" -Algorithm SHA256).Hash
+ If ($FileHash -eq $RubySHA256) {
echo "Found matching Ruby + DevKit on disk"
+ } Else {
+ echo "SHA256 hash mismatch, re-downloading"
+ DownloadRuby
}
} Else {
echo "No Ruby found at $RubyPath, downloading"