Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(windows): remove ConvertFrom-Json issue by simplifying tags management #1841

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 15 additions & 30 deletions make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ $env:COMMIT_SHA=$(git rev-parse HEAD)
$baseDockerCmd = 'docker-compose --file=build-windows.yaml'
$baseDockerBuildCmd = '{0} build --parallel --pull' -f $baseDockerCmd

$builds = @{}
$compose = Invoke-Expression "$baseDockerCmd config --format=json" 2>$null | ConvertFrom-Json
foreach ($service in $compose.services.PSObject.Properties) {
$tags = @($service.Value.image)
$tags += $service.Value.build.tags
$builds[$service.Value.image] = @{
'Tags' = $tags;
}
}

Write-Host "= PREPARE: List of $Organisation/$Repository images and tags to be processed:"
Invoke-Expression "$baseDockerCmd config"

Expand Down Expand Up @@ -101,15 +91,18 @@ function Test-Image {
$configuration.TestResult.OutputPath = ".\target\$ImageName\junit-results.xml"

$TestResults = Invoke-Pester -Configuration $configuration
$failed = $false
if ($TestResults.FailedCount -gt 0) {
Write-Host "There were $($TestResults.FailedCount) failed tests in $ImageName"
$testFailed = $true
$failed = $true
} else {
Write-Host "There were $($TestResults.PassedCount) passed tests out of $($TestResults.TotalCount) in $ImageName"
}

Remove-Item env:\CONTROLLER_IMAGE
Remove-Item env:\DOCKERFILE

return $failed
}

if($target -eq 'test') {
Expand Down Expand Up @@ -142,8 +135,10 @@ if($target -eq 'test') {
$configuration.CodeCoverage.Enabled = $false

Write-Host '= TEST: Testing all images...'
foreach($image in $builds.Keys) {
Test-Image $image.split(':')[1]
# Only fail the run afterwards in case of any test failures
$testFailed = $false
Invoke-Expression "$baseDockerCmd config" | yq '.services[].image' | ForEach-Object {
$testFailed = $testFailed -or (Test-Image $_.split(':')[1])
}

# Fail if any test failures
Expand All @@ -156,26 +151,16 @@ if($target -eq 'test') {
}
}

if($target -eq 'publish') {
# Only fail the run afterwards in case of any issues when publishing the docker images
$publishFailed = 0
foreach($b in $builds.Keys) {
foreach($taggedImage in $Builds[$b]['Tags']) {
Write-Host "Publishing $b => tag=$taggedImage"
$cmd = 'docker push {0}' -f $taggedImage
switch ($DryRun) {
$true { Write-Host "(dry-run) $cmd" }
$false { Invoke-Expression $cmd}
}
if($lastExitCode -ne 0) {
$publishFailed = 1
}
}
if($target -eq "publish") {
Write-Host "= PUBLISH: push all images and tags"
switch($DryRun) {
$true { Write-Host "(dry-run) $baseDockerCmd push" }
$false { Invoke-Expression "$baseDockerCmd push" }
}

# Fail if any issues when publising the docker images
if($publishFailed -ne 0 -and !$DryRun) {
Write-Error 'Publish failed!'
if($lastExitCode -ne 0) {
Write-Error "= PUBLISH: failed!"
exit 1
}
}
Expand Down