Skip to content

Commit 617e6df

Browse files
Ensure OutputPath is created in ResourceContainerImageBuilder (#11886)
When using docker/podman, and specifying an output path, building a docker image will fail if the directory isn't created. Ensure it is created. Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
1 parent 28d5b55 commit 617e6df

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Aspire.Hosting/Publishing/ResourceContainerImageBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ private async Task BuildContainerImageFromDockerfileAsync(string resourceName, D
358358
resolvedBuildSecrets[buildSecret.Key] = await ResolveValue(buildSecret.Value, cancellationToken).ConfigureAwait(false);
359359
}
360360

361+
// ensure outputPath is created if specified since docker/podman won't create it for us
362+
if (options?.OutputPath is { } outputPath)
363+
{
364+
Directory.CreateDirectory(outputPath);
365+
}
366+
361367
if (publishingTask is not null)
362368
{
363369
await using (publishingTask.ConfigureAwait(false))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ public async Task CanBuildImageFromDockerfileResource_WithAllOptionsSet()
240240

241241
using var app = builder.Build();
242242

243-
var tempOutputPath = Path.GetTempPath();
243+
using var tempDir = new TempDirectory();
244244
var options = new ContainerBuildOptions
245245
{
246246
ImageFormat = ContainerImageFormat.Oci,
247-
OutputPath = tempOutputPath,
247+
OutputPath = Path.Combine(tempDir.Path, "NewFolder"), // tests that the folder is created if it doesn't exist
248248
TargetPlatform = ContainerTargetPlatform.LinuxAmd64
249249
};
250250

0 commit comments

Comments
 (0)