From 7eb7a6a79cf03e0420b2dcbf377e5be1a541e817 Mon Sep 17 00:00:00 2001 From: David Negstad Date: Fri, 4 Apr 2025 10:47:35 -0700 Subject: [PATCH 1/4] Switch to null as default for owner and group in WithContainerFiles --- .../ContainerFileSystemCallbackAnnotation.cs | 4 ++-- .../ContainerResourceBuilderExtensions.cs | 12 ++++++------ src/Aspire.Hosting/Dcp/Model/Container.cs | 6 ++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs b/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs index 736dd24f297..dcc77311974 100644 --- a/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs +++ b/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs @@ -84,12 +84,12 @@ public sealed class ContainerFileSystemCallbackAnnotation : IResourceAnnotation /// /// The UID of the default owner for files/directories to be created or updated in the container. Defaults to 0 for root. /// - public int DefaultOwner { get; init; } + public int? DefaultOwner { get; init; } /// /// The GID of the default group for files/directories to be created or updated in the container. Defaults to 0 for root. /// - public int DefaultGroup { get; init; } + public int? DefaultGroup { get; init; } /// /// The umask to apply to files or folders without an explicit mode permission. If set to null, a default umask value of 0022 (octal) will be used. diff --git a/src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs b/src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs index bfa71505fd3..3b1d47dc1e1 100644 --- a/src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs +++ b/src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs @@ -706,8 +706,8 @@ public static IResourceBuilder WithBuildSecret(this IResourceBuilder bu /// The resource builder for the container resource. /// The destination (absolute) path in the container. /// The file system entries to create. - /// The default owner UID for the created or updated file system. Defaults to 0 for root. - /// The default group ID for the created or updated file system. Defaults to 0 for root. + /// The default owner UID for the created or updated file system. Defaults to 0 for root if not set. + /// The default group ID for the created or updated file system. Defaults to 0 for root if not set. /// The umask permissions to exclude from the default file and folder permissions. This takes away (rather than granting) default permissions to files and folders without an explicit mode permission set. /// The . /// @@ -741,7 +741,7 @@ public static IResourceBuilder WithBuildSecret(this IResourceBuilder bu /// defaultOwner: 1000); /// /// - public static IResourceBuilder WithContainerFiles(this IResourceBuilder builder, string destinationPath, IEnumerable entries, int defaultOwner = 0, int defaultGroup = 0, UnixFileMode? umask = null) where T : ContainerResource + public static IResourceBuilder WithContainerFiles(this IResourceBuilder builder, string destinationPath, IEnumerable entries, int? defaultOwner = null, int? defaultGroup = null, UnixFileMode? umask = null) where T : ContainerResource { ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(destinationPath); @@ -769,8 +769,8 @@ public static IResourceBuilder WithContainerFiles(this IResourceBuilder /// The resource builder for the container resource. /// The destination (absolute) path in the container. /// The callback that will be invoked when the resource is being created. - /// The default owner UID for the created or updated file system. Defaults to 0 for root. - /// The default group ID for the created or updated file system. Defaults to 0 for root. + /// The default owner UID for the created or updated file system. Defaults to 0 for root if not set. + /// The default group ID for the created or updated file system. Defaults to 0 for root if not set. /// The umask permissions to exclude from the default file and folder permissions. This takes away (rather than granting) default permissions to files and folders without an explicit mode permission set. /// The . /// @@ -814,7 +814,7 @@ public static IResourceBuilder WithContainerFiles(this IResourceBuilder /// }); /// /// - public static IResourceBuilder WithContainerFiles(this IResourceBuilder builder, string destinationPath, Func>> callback, int defaultOwner = 0, int defaultGroup = 0, UnixFileMode? umask = null) where T : ContainerResource + public static IResourceBuilder WithContainerFiles(this IResourceBuilder builder, string destinationPath, Func>> callback, int? defaultOwner = null, int? defaultGroup = null, UnixFileMode? umask = null) where T : ContainerResource { ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(destinationPath); diff --git a/src/Aspire.Hosting/Dcp/Model/Container.cs b/src/Aspire.Hosting/Dcp/Model/Container.cs index 4a1af7312c5..0e1ca6bf268 100644 --- a/src/Aspire.Hosting/Dcp/Model/Container.cs +++ b/src/Aspire.Hosting/Dcp/Model/Container.cs @@ -295,11 +295,13 @@ internal sealed class ContainerCreateFileSystem : IEquatable Date: Fri, 4 Apr 2025 10:54:56 -0700 Subject: [PATCH 2/4] Fix failing test --- tests/Aspire.Hosting.PostgreSQL.Tests/AddPostgresTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Aspire.Hosting.PostgreSQL.Tests/AddPostgresTests.cs b/tests/Aspire.Hosting.PostgreSQL.Tests/AddPostgresTests.cs index 116cc46a792..6a1265bddd5 100644 --- a/tests/Aspire.Hosting.PostgreSQL.Tests/AddPostgresTests.cs +++ b/tests/Aspire.Hosting.PostgreSQL.Tests/AddPostgresTests.cs @@ -476,8 +476,8 @@ public async Task WithPostgresProducesValidServersJsonFile() Assert.Equal("/pgadmin4", createServers.DestinationPath); Assert.Null(createServers.Umask); - Assert.Equal(0, createServers.DefaultOwner); - Assert.Equal(0, createServers.DefaultGroup); + Assert.Null(createServers.DefaultOwner); + Assert.Null(createServers.DefaultGroup); var entries = await createServers.Callback(new() { Model = pgadmin, ServiceProvider = app.Services }, CancellationToken.None); @@ -547,8 +547,8 @@ public async Task WithPgwebProducesValidBookmarkFiles() Assert.Equal("/", createBookmarks.DestinationPath); Assert.Null(createBookmarks.Umask); - Assert.Equal(0, createBookmarks.DefaultOwner); - Assert.Equal(0, createBookmarks.DefaultGroup); + Assert.Null(createBookmarks.DefaultOwner); + Assert.Null(createBookmarks.DefaultGroup); var entries = await createBookmarks.Callback(new() { Model = pgweb, ServiceProvider = app.Services }, CancellationToken.None); From 6445197131a41eabc57495b0ba530b94a98e9039 Mon Sep 17 00:00:00 2001 From: David Negstad Date: Fri, 4 Apr 2025 11:02:43 -0700 Subject: [PATCH 3/4] Update doc comment --- .../ApplicationModel/ContainerFileSystemCallbackAnnotation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs b/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs index dcc77311974..064b26f89d5 100644 --- a/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs +++ b/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs @@ -82,12 +82,12 @@ public sealed class ContainerFileSystemCallbackAnnotation : IResourceAnnotation public required string DestinationPath { get; init; } /// - /// The UID of the default owner for files/directories to be created or updated in the container. Defaults to 0 for root. + /// The UID of the default owner for files/directories to be created or updated in the container. The UID defaults to 0 if null. /// public int? DefaultOwner { get; init; } /// - /// The GID of the default group for files/directories to be created or updated in the container. Defaults to 0 for root. + /// The GID of the default group for files/directories to be created or updated in the container. The GID defaults to 0 if null. /// public int? DefaultGroup { get; init; } From 4dfd5fb096c854716ed20ab0498d86b8a24c5489 Mon Sep 17 00:00:00 2001 From: David Negstad Date: Fri, 4 Apr 2025 11:03:29 -0700 Subject: [PATCH 4/4] Call out that 0 is root --- .../ApplicationModel/ContainerFileSystemCallbackAnnotation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs b/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs index 064b26f89d5..ed8ce8f63ef 100644 --- a/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs +++ b/src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs @@ -82,12 +82,12 @@ public sealed class ContainerFileSystemCallbackAnnotation : IResourceAnnotation public required string DestinationPath { get; init; } /// - /// The UID of the default owner for files/directories to be created or updated in the container. The UID defaults to 0 if null. + /// The UID of the default owner for files/directories to be created or updated in the container. The UID defaults to 0 for root if null. /// public int? DefaultOwner { get; init; } /// - /// The GID of the default group for files/directories to be created or updated in the container. The GID defaults to 0 if null. + /// The GID of the default group for files/directories to be created or updated in the container. The GID defaults to 0 for root if null. /// public int? DefaultGroup { get; init; }