diff --git a/eng/common/Invoke-ImageBuilder.ps1 b/eng/common/Invoke-ImageBuilder.ps1 index ed98c51e..fb349557 100644 --- a/eng/common/Invoke-ImageBuilder.ps1 +++ b/eng/common/Invoke-ImageBuilder.ps1 @@ -8,7 +8,7 @@ Executes ImageBuilder with the specified args. The args to pass to ImageBuilder. .PARAMETER ReuseImageBuilderImage -Indicates that a previously built ImageBuilder image is presumed to exist locally and that +Indicates that a previously built ImageBuilder image is presumed to exist locally and that it should be used for this execution of the script. This allows some optimization when multiple calls are being made to this script that don't require a fresh image (i.e. the repo contents in the image don't need to be or should not be updated with each call to @@ -74,6 +74,7 @@ try { } else { # On Windows, ImageBuilder is run locally due to limitations with running Docker client within a container. + # Remove when https://github.com/dotnet/docker-tools/issues/159 is resolved $imageBuilderFolder = ".Microsoft.DotNet.ImageBuilder" $imageBuilderCmd = [System.IO.Path]::Combine($imageBuilderFolder, "Microsoft.DotNet.ImageBuilder.exe") if (-not (Test-Path -Path "$imageBuilderCmd" -PathType Leaf)) { @@ -99,6 +100,6 @@ finally { if ($containerCreated) { Exec "docker container rm -f $imageBuilderContainerName" } - + popd } diff --git a/eng/dockerfile-templates/Get-GeneratedDockerfiles.ps1 b/eng/dockerfile-templates/Get-GeneratedDockerfiles.ps1 index 44a810cc..275c7669 100644 --- a/eng/dockerfile-templates/Get-GeneratedDockerfiles.ps1 +++ b/eng/dockerfile-templates/Get-GeneratedDockerfiles.ps1 @@ -3,13 +3,15 @@ param( [switch]$Validate ) +$dockerOs = docker version -f "{{ .Server.Os }}" + +$imageBuilderArgs = "generateDockerfiles --optional-templates" if ($Validate) { - $customImageBuilderArgs = " --validate" + $imageBuilderArgs += " --validate" } $repoRoot = (Get-Item "$PSScriptRoot").Parent.Parent.FullName - -$onDockerfilesGenerated = { +$onDockerfilesGeneratedLinux = { param($ContainerName) if (-Not $Validate) { @@ -17,6 +19,13 @@ $onDockerfilesGenerated = { } } -& $PSScriptRoot/../common/Invoke-ImageBuilder.ps1 ` - -ImageBuilderArgs "generateDockerfiles --optional-templates $customImageBuilderArgs" ` - -OnCommandExecuted $onDockerfilesGenerated +# On Windows, ImageBuilder is run locally due to limitations with running Docker client within a container. +# Remove when https://github.com/dotnet/docker-tools/issues/159 is resolved +if ($dockerOs -eq "windows") { + & $PSScriptRoot/../common/Invoke-ImageBuilder.ps1 ` + -ImageBuilderArgs $imageBuilderArgs +} else { + & $PSScriptRoot/../common/Invoke-ImageBuilder.ps1 ` + -ImageBuilderArgs $imageBuilderArgs ` + -OnCommandExecuted $onDockerfilesGeneratedLinux +} diff --git a/eng/readme-templates/Get-GeneratedReadmes.ps1 b/eng/readme-templates/Get-GeneratedReadmes.ps1 index 9cb369c8..4f2d6b3e 100644 --- a/eng/readme-templates/Get-GeneratedReadmes.ps1 +++ b/eng/readme-templates/Get-GeneratedReadmes.ps1 @@ -5,6 +5,8 @@ param( $ErrorActionPreference = 'Stop' +$dockerOs = docker version -f "{{ .Server.Os }}" + if ($Validate) { $customImageBuilderArgs = " --validate" } @@ -16,7 +18,7 @@ function CopyReadme([string]$containerName, [string]$readmeRelativePath) { Exec "docker cp ${containerName}:/repo/$readmeRelativePath $repoRoot/$readmeDir" } -$onDockerfilesGenerated = { +$onDockerfilesGeneratedLinux = { param($ContainerName) if (-Not $Validate) { @@ -44,10 +46,18 @@ $onDockerfilesGenerated = { function Invoke-GenerateReadme { param ([string] $Manifest) - & $PSScriptRoot/../common/Invoke-ImageBuilder.ps1 ` - -ImageBuilderArgs ` - "generateReadmes --manifest $Manifest --source-branch 'main'$customImageBuilderArgs 'https://github.com/microsoft/dotnet-framework-docker'" ` - -OnCommandExecuted $onDockerfilesGenerated ` + $imageBuilderArgs = "generateReadmes --manifest $Manifest --source-branch 'main'$customImageBuilderArgs 'https://github.com/microsoft/dotnet-framework-docker'" + + # On Windows, ImageBuilder is run locally due to limitations with running Docker client within a container. + # Remove when https://github.com/dotnet/docker-tools/issues/159 is resolved + if ($dockerOs -eq "windows") { + & $PSScriptRoot/../common/Invoke-ImageBuilder.ps1 ` + -ImageBuilderArgs $imageBuilderArgs + } else { + & $PSScriptRoot/../common/Invoke-ImageBuilder.ps1 ` + -ImageBuilderArgs $imageBuilderArgs ` + -OnCommandExecuted $onDockerfilesGeneratedLinux + } } Invoke-GenerateReadme "manifest.json"