Skip to content

Make container runtime health check conditional based on resource requirements#10393

Merged
davidfowl merged 7 commits intomainfrom
copilot/fix-10392
Jul 18, 2025
Merged

Make container runtime health check conditional based on resource requirements#10393
davidfowl merged 7 commits intomainfrom
copilot/fix-10392

Conversation

Copy link
Contributor

Copilot AI commented Jul 14, 2025

Currently, the container runtime health check is performed unconditionally before building any images, even when no resources actually need the container runtime. This causes unnecessary errors when building applications that only contain .NET projects without Dockerfile-based containers.

This PR makes the health check conditional by:

  1. Adding a helper method ResourcesRequireContainerRuntime that checks if any resources have both ContainerImageAnnotation and DockerfileBuildAnnotation
  2. Modifying BuildImagesAsync to only perform the container runtime health check when resources actually need it
  3. Adding comprehensive unit tests to validate the logic works correctly for all scenarios

Changes Made

  • Only resources with DockerfileBuildAnnotation require the container runtime health check
  • Project resources (built via dotnet publish /t:PublishContainer) don't require the health check
  • Container resources without Dockerfile annotations don't require the health check
  • Empty resource collections don't require the health check

Testing

Added unit tests covering:

  • ✅ Project resources only (no health check needed)
  • ✅ Dockerfile resources (health check required)
  • ✅ Mixed resources (health check required)
  • ✅ Empty resources (no health check needed)
  • ✅ Container resources without Dockerfile (no health check needed)

This is a minimal, surgical change that prevents unnecessary container runtime health checks while maintaining all existing functionality.

Fixes #10392.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • westus.data.mcr.microsoft.com
    • Triggering command: dotnet publish /home/REDACTED/work/aspire/aspire/tests/testproject/TestProject.ServiceA/TestProject.ServiceA.csproj --configuration Release /t:PublishContainer /p:ContainerRepository=servicea (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Container runtime health check should be more granular in ResourceContainerImageBuilder Make container runtime health check conditional based on resource requirements Jul 14, 2025
Copilot AI requested a review from captainsafia July 14, 2025 20:18
@captainsafia captainsafia marked this pull request as ready for review July 14, 2025 21:51
Copilot AI review requested due to automatic review settings July 14, 2025 21:51
@captainsafia captainsafia requested a review from mitchdenny as a code owner July 14, 2025 21:51
Copy link
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 makes the container runtime health check in BuildImagesAsync conditional on whether any resources require a Dockerfile-based container build. It adds a helper method to detect those resources and includes unit tests covering several scenarios.

  • Introduce ResourcesRequireContainerRuntime helper to detect resources with both container image and Dockerfile build annotations
  • Guard the existing runtime health check in BuildImagesAsync so it only runs when needed
  • Add unit tests for project-only, Dockerfile-only, mixed, empty, and container-without-Dockerfile cases

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Aspire.Hosting/Publishing/ResourceContainerImageBuilder.cs Wrap the health check call in an if and introduce the helper method
tests/Aspire.Hosting.Tests/Publishing/ResourceContainerImageBuilderTests.cs Add tests and supporting mocks for ResourcesRequireContainerRuntime
Comments suppressed due to low confidence (2)

tests/Aspire.Hosting.Tests/Publishing/ResourceContainerImageBuilderTests.cs:385

  • Consider adding a test case for a resource with only DockerfileBuildAnnotation (no ContainerImageAnnotation) to ensure ResourcesRequireContainerRuntime behaves as expected in that scenario.
    [Fact]

src/Aspire.Hosting/Publishing/ResourceContainerImageBuilder.cs:393

  • The PR description states only DockerfileBuildAnnotation should trigger the health check, yet this implementation also requires ContainerImageAnnotation. Please clarify if both annotations are required or update the check to only look for DockerfileBuildAnnotation.
            resource.TryGetLastAnnotation<ContainerImageAnnotation>(out _) &&

Assert.False(result, "Container resources without DockerfileBuildAnnotation should not require container runtime");
}

private static bool TestResourcesRequireContainerRuntime(IEnumerable<IResource> resources)
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

[nitpick] The test suite duplicates the logic of ResourcesRequireContainerRuntime. To reduce duplication and keep tests in sync, consider making the production helper internal (with an InternalsVisibleTo attribute) so tests can call it directly.

Copilot uses AI. Check for mistakes.
Copilot AI and others added 4 commits July 14, 2025 23:15
…inerImageBuilder

Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
…ethod instead of duplicate test logic

Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the fix!

Copy link
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 18, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • westcentralus.data.mcr.microsoft.com
    • Triggering command: buildkitd --allow-insecure-entitlement=network.host (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from davidfowl July 18, 2025 05:08
@davidfowl davidfowl added this to the 9.4 milestone Jul 18, 2025
@davidfowl davidfowl enabled auto-merge (squash) July 18, 2025 15:26
@davidfowl davidfowl merged commit c827d26 into main Jul 18, 2025
276 checks passed
@davidfowl davidfowl deleted the copilot/fix-10392 branch July 18, 2025 15:42
@captainsafia
Copy link
Contributor

/backport to release/9.4

@github-actions
Copy link
Contributor

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Container runtime health check should be more granular in ResourceContainerImageBuilder

6 participants