-
Notifications
You must be signed in to change notification settings - Fork 719
Add support for creating files and folders in a container via docker/podman cp
#8121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f7858a9
Add support for creating files in a container at runtime
danegsta 63fe575
Update API, add test
danegsta 486f74a
Improve equality comparison, fix tests
danegsta 3bf355b
Fix another test
danegsta 28f6bd5
Also update WithPgWeb
danegsta e55a237
Ensure directories have correct permission
danegsta a404ed1
Update API name, use IEnumerable instead of List
danegsta 8371b8e
Update doc comment
danegsta 61f414b
Add support for callback based API
danegsta 745c543
Use context specific to annotation
danegsta 238509f
Update context type
danegsta cb411b6
Merge remote-tracking branch 'upstream/main' into danegsta/createFiles
danegsta 6d8b35f
Use umask for default permissions
danegsta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/Aspire.Hosting/ApplicationModel/ContainerCreateFilesCallbackAnnotation.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
|
|
||
| namespace Aspire.Hosting.ApplicationModel; | ||
|
|
||
| /// <summary> | ||
| /// Represents a base class for file system entries in a container. | ||
| /// </summary> | ||
| public abstract class ContainerFileSystemItem | ||
| { | ||
| private string? _name; | ||
|
|
||
| /// <summary> | ||
| /// The name of the file or directory. Must be a simple file or folder name and not include any path separators (eg, / or \). To specify parent folders, use one or more <see cref="ContainerDirectory"/> entries. | ||
| /// </summary> | ||
| public string Name | ||
| { | ||
| get => _name!; | ||
| set | ||
| { | ||
| ArgumentException.ThrowIfNullOrWhiteSpace(value, nameof(value)); | ||
|
|
||
| if (Path.GetDirectoryName(value) != string.Empty) | ||
| { | ||
| throw new ArgumentException("Name must be a simple file or folder name and not include any path separators (eg, / or \\). To specify parent folders, use one or more ContainerDirectory entries.", nameof(value)); | ||
| } | ||
|
|
||
| _name = value; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The UID of the owner of the file or directory. If set to null, the UID will be inherited from the parent directory or defaults. | ||
| /// </summary> | ||
| public int? Owner { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The GID of the group of the file or directory. If set to null, the GID will be inherited from the parent directory or defaults. | ||
| /// </summary> | ||
| public int? Group { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The permissions of the file or directory. If set to 0, the permissions will be inherited from the parent directory or defaults. | ||
| /// </summary> | ||
| public UnixFileMode Mode { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents a file in the container file system. | ||
| /// </summary> | ||
| public sealed class ContainerFile : ContainerFileSystemItem | ||
| { | ||
| /// <summary> | ||
| /// The contents of the file. If null, the file will be created as an empty file. | ||
| /// </summary> | ||
| public string? Contents { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents a directory in the container file system. | ||
| /// </summary> | ||
| public sealed class ContainerDirectory : ContainerFileSystemItem | ||
| { | ||
| /// <summary> | ||
| /// The contents of the directory to create in the container. Will create specified <see cref="ContainerFile"/> and <see cref="ContainerDirectory"/> entries in the directory. | ||
| /// </summary> | ||
| public IEnumerable<ContainerFileSystemItem> Entries { get; set; } = []; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents a callback annotation that specifies files and folders that should be created or updated in a container. | ||
| /// </summary> | ||
| [DebuggerDisplay("Type = {GetType().Name,nw}, DestinationPath = {DestinationPath}")] | ||
| public sealed class ContainerCreateFilesCallbackAnnotation : IResourceAnnotation | ||
| { | ||
| /// <summary> | ||
| /// The (absolute) base path to create the new file (and any parent directories) in the container. | ||
| /// This path should already exist in the container. | ||
| /// </summary> | ||
| public required string DestinationPath { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The UID of the default owner for files/directories to be created or updated in the container. Defaults to 0 for root. | ||
| /// </summary> | ||
| public int DefaultOwner { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The GID of the default group for files/directories to be created or updated in the container. Defaults to 0 for root. | ||
| /// </summary> | ||
| public int DefaultGroup { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// 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. | ||
| /// The umask takes away permissions from the default permission set (rather than granting them). | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The umask is a bitmask that determines the default permissions for newly created files and directories. The umask value is subtracted (bitwise masked) | ||
| /// from the maximum possible default permissions to determine the final permissions. For directories, the umask is subtracted from 0777 (rwxrwxrwx) to get | ||
| /// the final permissions and for files it is subtracted from 0666 (rw-rw-rw-). For a umask of 0022, this gives a default folder permission of 0755 (rwxr-xr-x) | ||
| /// and a default file permission of 0644 (rw-r--r--). | ||
| /// </remarks> | ||
| public UnixFileMode? Umask { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The callback to be executed when the container is created. Should return a tree of <see cref="ContainerFileSystemItem"/> entries to create (or update) in the container. | ||
| /// </summary> | ||
| public required Func<ContainerCreateFilesCallbackContext, CancellationToken, Task<IEnumerable<ContainerFileSystemItem>>> Callback { get; init; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents the context for a <see cref="ContainerCreateFilesCallbackAnnotation"/> callback. | ||
| /// </summary> | ||
| public sealed class ContainerCreateFilesCallbackContext | ||
| { | ||
| /// <summary> | ||
| /// A <see cref="IServiceProvider"/> that can be used to resolve services in the callback. | ||
| /// </summary> | ||
| public required IServiceProvider ServiceProvider { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The app model resource the callback is associated with. | ||
| /// </summary> | ||
| public required IResource Model { get; init; } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.