Skip to content

Commit

Permalink
Merge pull request #1841 from lemeurherve/fix-windows-docker-compose-…
Browse files Browse the repository at this point in the history
…config-format-json

fix(windows): remove `ConvertFrom-Json` issue by simplifying tags management
  • Loading branch information
dduportal authored Mar 22, 2024
2 parents 8b3d583 + 30dc803 commit 0b58775
Showing 1 changed file with 15 additions and 30 deletions.
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

0 comments on commit 0b58775

Please sign in to comment.