Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Clean up logs and format
  • Loading branch information
captainsafia committed Jul 8, 2025
commit e00837e451194b42b27029b134e933250c6f5fcc
14 changes: 6 additions & 8 deletions src/Aspire.Hosting/Publishing/DockerContainerRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ private async Task<int> RunDockerBuildAsync(string contextPath, string dockerfil
var outputType = options?.ImageFormat switch
{
ContainerImageFormat.Oci => "type=oci",
ContainerImageFormat.Docker => "type=docker,compression=gzip",
ContainerImageFormat.Docker => "type=docker",
null => "type=docker",
_ => throw new ArgumentOutOfRangeException(nameof(options), options.ImageFormat, "Invalid container image format")
};

if (!string.IsNullOrEmpty(options?.OutputPath))
{
// Extract resource name from imageName for the file name
var resourceName = imageName.Split('/').Last().Split(':').First();
outputType += $",dest=\"{options.OutputPath}/{resourceName}.tar\"";
outputType += $",dest=\"{options.OutputPath}/{imageName}.tar\"";
}

arguments += $" --output \"{outputType}\"";
Expand All @@ -55,11 +53,11 @@ private async Task<int> RunDockerBuildAsync(string contextPath, string dockerfil
Arguments = arguments,
OnOutputData = output =>
{
logger.LogInformation("docker builds (stdout): {Output}", output);
logger.LogInformation("docker buildx (stdout): {Output}", output);
},
OnErrorData = error =>
{
logger.LogInformation("docker builds (stderr): {Error}", error);
logger.LogInformation("docker buildx (stderr): {Error}", error);
},
ThrowOnNonZeroReturnCode = false,
InheritEnv = true
Expand All @@ -76,11 +74,11 @@ private async Task<int> RunDockerBuildAsync(string contextPath, string dockerfil

if (processResult.ExitCode != 0)
{
logger.LogError("Docker builds for {ImageName} failed with exit code {ExitCode}.", imageName, processResult.ExitCode);
logger.LogError("docker buildx for {ImageName} failed with exit code {ExitCode}.", imageName, processResult.ExitCode);
return processResult.ExitCode;
}

logger.LogInformation("Docker builds for {ImageName} succeeded.", imageName);
logger.LogInformation("docker buildx for {ImageName} succeeded.", imageName);
return processResult.ExitCode;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Aspire.Hosting/Publishing/PodmanContainerRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ private async Task<int> RunPodmanBuildAsync(string contextPath, string dockerfil
Arguments = arguments,
OnOutputData = output =>
{
logger.LogInformation("podman builds (stdout): {Output}", output);
logger.LogInformation("podman build (stdout): {Output}", output);
},
OnErrorData = error =>
{
logger.LogInformation("podman builds (stderr): {Error}", error);
logger.LogInformation("podman build (stderr): {Error}", error);
},
ThrowOnNonZeroReturnCode = false,
InheritEnv = true
Expand All @@ -69,11 +69,11 @@ private async Task<int> RunPodmanBuildAsync(string contextPath, string dockerfil

if (processResult.ExitCode != 0)
{
logger.LogError("Podman builds for {ImageName} failed with exit code {ExitCode}.", imageName, processResult.ExitCode);
logger.LogError("Podman build for {ImageName} failed with exit code {ExitCode}.", imageName, processResult.ExitCode);
return processResult.ExitCode;
}

logger.LogInformation("Podman builds for {ImageName} succeeded.", imageName);
logger.LogInformation("Podman build for {ImageName} succeeded.", imageName);
return processResult.ExitCode;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,4 @@ public void ContainerBuildOptions_CanSetAllProperties()
Assert.Equal("/custom/path", options.OutputPath);
Assert.Equal(ContainerTargetPlatform.LinuxArm64, options.TargetPlatform);
}

[Theory]
[InlineData(ContainerImageFormat.Docker, "Docker")]
[InlineData(ContainerImageFormat.Oci, "OCI")]
public void ContainerImageFormat_EnumValues_AreCorrect(ContainerImageFormat format, string expectedValue)
{
// This test ensures that the enum values match what's expected for MSBuild properties
var formatString = format switch
{
ContainerImageFormat.Docker => "Docker",
ContainerImageFormat.Oci => "OCI",
_ => throw new ArgumentOutOfRangeException(nameof(format))
};

Assert.Equal(expectedValue, formatString);
}
}
Loading