Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 18 additions & 2 deletions src/Aspire.Hosting/Publishing/ResourceContainerImageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public async Task BuildImagesAsync(IEnumerable<IResource> resources, Cancellatio

if (!containerRuntimeHealthy)
{
logger.LogError("Container runtime is not running or is unhealthy. Cannot build container images.");
throw new InvalidOperationException("Container runtime is not running or is unhealthy.");
logger.LogError("Container runtime '{ContainerRuntimeName}' is not running or is unhealthy. Cannot build container images.", ContainerRuntime.Name);
throw new InvalidOperationException($"Container runtime '{ContainerRuntime.Name}' is not running or is unhealthy.");
}

logger.LogDebug("{ContainerRuntimeName} is healthy", ContainerRuntime.Name);
Expand All @@ -214,6 +214,22 @@ public async Task BuildImageAsync(IResource resource, CancellationToken cancella

var options = await ResolveContainerBuildOptionsAsync(resource, cancellationToken).ConfigureAwait(false);

// Check if this resource needs a container runtime
if (await ResourcesRequireContainerRuntimeAsync([resource], cancellationToken).ConfigureAwait(false))
{
logger.LogDebug("Checking {ContainerRuntimeName} health", ContainerRuntime.Name);

var containerRuntimeHealthy = await ContainerRuntime.CheckIfRunningAsync(cancellationToken).ConfigureAwait(false);

if (!containerRuntimeHealthy)
{
logger.LogError("Container runtime '{ContainerRuntimeName}' is not running or is unhealthy. Cannot build container image.", ContainerRuntime.Name);
throw new InvalidOperationException($"Container runtime '{ContainerRuntime.Name}' is not running or is unhealthy.");
}

logger.LogDebug("{ContainerRuntimeName} is healthy", ContainerRuntime.Name);
}

if (resource is ProjectResource)
{
// If it is a project resource we need to build the container image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,13 @@ public async Task BuildImageAsync_ThrowsInvalidOperationException_WhenDockerRunt
var exception = await Assert.ThrowsAsync<InvalidOperationException>(() =>
imageBuilder.BuildImagesAsync([container.Resource], cts.Token));

Assert.Equal("Container runtime is not running or is unhealthy.", exception.Message);
Assert.Contains("Container runtime", exception.Message);
Assert.Contains("is not running or is unhealthy", exception.Message);

var collector = app.Services.GetFakeLogCollector();
var logs = collector.GetSnapshot();

Assert.Contains(logs, log => log.Message.Contains("Container runtime is not running or is unhealthy. Cannot build container images."));
Assert.Contains(logs, log => log.Message.Contains("is not running or is unhealthy. Cannot build container images."));
}

[Fact]
Expand Down