Skip to content

Surface build output on failure for Docker, Podman, and dotnet publish#16093

Merged
davidfowl merged 7 commits intomainfrom
davidfowl/surface-build-output-on-failure
Apr 15, 2026
Merged

Surface build output on failure for Docker, Podman, and dotnet publish#16093
davidfowl merged 7 commits intomainfrom
davidfowl/surface-build-output-on-failure

Conversation

@davidfowl
Copy link
Copy Markdown
Contributor

Description

Surface build output on failure for Docker, Podman, and dotnet publish container builds.

Problem

When a container image build fails, users see only:

Docker build failed with exit code 1.

The actual build output (compiler errors, missing files, Dockerfile issues) is logged at Debug level only. Users have to re-run with --log-level debug to see what went wrong.

Solution

Introduce ProcessFailedException that captures stdout/stderr from failed build processes. The exception's Message property includes the last 50 lines of output so it surfaces through the pipeline step reporter automatically.

Changes

  • ProcessFailedException — new internal exception type with ExitCode, BuildOutput (raw lines), and GetFormattedOutput(). Message is overridden to include formatted output.
  • Docker buildx — deduped to use base class ExecuteContainerCommandWithExitCodeAsync, throws ProcessFailedException with captured output
  • Podman build — throws ProcessFailedException with captured output
  • dotnet publish /t:PublishContainer — throws ProcessFailedException with captured output
  • Buildkit instance creation — also throws ProcessFailedException
  • Uses ConcurrentQueue<string> for thread-safe output buffering (callbacks fire on different threads)
  • Integration test for Docker build failure verifying exception carries output

Before

(build-myapi) ✗ Docker build failed with exit code 1.

After

(build-myapi) ✗ Docker build failed with exit code 1.
  #8 [builder 4/5] COPY nonexistent-file.txt /app/
  #8 ERROR: "/nonexistent-file.txt": not found
  Dockerfile:4
  >>> COPY nonexistent-file.txt /app/
  ERROR: failed to build: failed to compute cache key

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No

Introduce ProcessFailedException that captures stdout/stderr from
failed build processes. The exception's Message property includes the
last 50 lines of output so it surfaces through the pipeline step
reporter without requiring --log-level debug.

All three container build paths now throw ProcessFailedException
consistently:
- Docker buildx (deduped to use base class ExecuteContainerCommand)
- Podman build
- dotnet publish /t:PublishContainer

Uses ConcurrentQueue<string> for thread-safe output buffering since
OnOutputData/OnErrorData fire on different threads.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl davidfowl requested a review from mitchdenny as a code owner April 12, 2026 17:47
Copilot AI review requested due to automatic review settings April 12, 2026 17:47
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 12, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16093

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16093"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves diagnostics for container image builds by capturing and surfacing build stdout/stderr when Docker, Podman, or dotnet publish /t:PublishContainer fails, so users can see actionable error output without re-running with --log-level debug.

Changes:

  • Added ProcessFailedException to carry exit code plus captured build output and include formatted tail output in Message.
  • Updated Docker and Podman build paths (including buildkit instance creation) to capture output and throw ProcessFailedException on non-zero exit codes.
  • Updated dotnet publish container build path to capture output and throw ProcessFailedException, plus added an integration test asserting build output is present.
Show a summary per file
File Description
tests/Aspire.Hosting.Tests/Publishing/ResourceContainerImageManagerTests.cs Adds Docker build failure integration test validating captured output is present on failure.
src/Aspire.Hosting/Publishing/ResourceContainerImageManager.cs Captures dotnet publish output and throws ProcessFailedException on failure.
src/Aspire.Hosting/Publishing/ProcessFailedException.cs Introduces new exception type that formats and surfaces tail build output in Message.
src/Aspire.Hosting/Publishing/PodmanContainerRuntime.cs Captures Podman build output and throws ProcessFailedException on failure.
src/Aspire.Hosting/Publishing/DockerContainerRuntime.cs Refactors Docker buildx path to shared execution helper, captures output, throws ProcessFailedException (including for buildkit creation failures).
src/Aspire.Hosting/Publishing/ContainerRuntimeBase.cs Extends command execution helper to optionally buffer stdout/stderr lines for callers to include in exceptions.

Copilot's findings

Comments suppressed due to low confidence (1)

tests/Aspire.Hosting.Tests/Publishing/ResourceContainerImageManagerTests.cs:1457

  • This Docker build-failure test uses a remote base image (mcr.microsoft.com/cbl-mariner/...). If the pull fails (network, throttling, outage), the build may fail before the COPY nonexistent-file-12345.txt step and the assertion on that filename can become flaky. Consider using FROM scratch (or another already-cached test image used elsewhere) so the failure deterministically comes from the missing file.
        await File.WriteAllTextAsync(dockerfilePath, """
            FROM mcr.microsoft.com/cbl-mariner/base/core:2.0
            COPY nonexistent-file-12345.txt /app/
            """);
  • Files reviewed: 6/6 changed files
  • Comments generated: 6

…gging

- Add using to TestTempDirectory in test to prevent temp folder leaks
- Add catch/log pattern in BuildProjectContainerImageAsync for
  consistent error logging across build paths

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The existing BuildImageAsync_ProjectBuildFailureIncludesResourceName
test expected InvalidOperationException but now gets
ProcessFailedException after our changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found (correctness). The new exception type won't pass through the pipeline step executor cleanly — it will get wrapped with a redundant step-name prefix instead of surfacing the formatted build output directly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean implementation. The bounded BuildOutputCapture with CircularBuffer properly handles thread-safety and memory. ProcessFailedException correctly extends DistributedApplicationException for pipeline pass-through. The ThrowOnNonZeroReturnCode = false fix in ExecuteDotnetPublishAsync is a correctness improvement over the prior code. All three build paths (Docker, Podman, dotnet publish) are updated consistently.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
/// <summary>
/// Retains a bounded tail of build output while tracking the total number of lines observed.
/// </summary>
internal sealed class BuildOutputCapture(int maxRetainedLineCount = 256)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the last 256 lines enough? Sometimes it gets pretty large.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's 0 right now. 😄

/// <summary>
/// Returns the last <paramref name="maxLines"/> lines of build output formatted for display.
/// </summary>
public string GetFormattedOutput(int maxLines = 50)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

50 is even smaller than 256. Are we sure this is enough to give all the information to someone?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing yes. It's also better than 0. You can always set the log level to see it all.

Copy link
Copy Markdown
Member

@IEvangelist IEvangelist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found: 1 correctness bug and 1 security issue.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl davidfowl enabled auto-merge (squash) April 15, 2026 00:57
@davidfowl davidfowl merged commit 11cecc2 into main Apr 15, 2026
279 checks passed
@github-actions github-actions bot added this to the 13.3 milestone Apr 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 71 recordings uploaded (commit b6b8759)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AllPublishMethodsBuildDockerImages ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View Recording
DeployK8sBasicApiService ▶️ View Recording
DeployK8sWithGarnet ▶️ View Recording
DeployK8sWithMongoDB ▶️ View Recording
DeployK8sWithMySql ▶️ View Recording
DeployK8sWithPostgres ▶️ View Recording
DeployK8sWithRabbitMQ ▶️ View Recording
DeployK8sWithRedis ▶️ View Recording
DeployK8sWithSqlServer ▶️ View Recording
DeployK8sWithValkey ▶️ View Recording
DeployTypeScriptAppToKubernetes ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoListStepsShowsPipelineSteps ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
OtelLogsReturnsStructuredLogsFromStarterApp ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View Recording

📹 Recordings uploaded automatically from CI run #24422121976

@aspire-repo-bot
Copy link
Copy Markdown
Contributor

📄 Documentation check complete — no docs PR required

All changes in this PR are internal implementation details (internal sealed class ProcessFailedException, internal sealed class BuildOutputCapture). There are no new public APIs, configuration options, CLI commands, or resource types introduced.

The improvement (surfacing build output on failure for Docker, Podman, and dotnet publish) is a "just works better" behavioral improvement — users will automatically see richer error output without needing to learn anything new or change any configuration. There is nothing to document.

Generated by PR Documentation Check for issue #16093 · ● 216.1K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants