-
Notifications
You must be signed in to change notification settings - Fork 707
Add support for docker static files #12265
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
Add support for docker static files #12265
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12265Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12265" |
src/Aspire.Hosting/ApplicationModel/StaticDockerFilesAnnotation.cs
Outdated
Show resolved
Hide resolved
src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/Aspire.Hosting/ApplicationModel/DistributedApplicationModelExtensions.cs
Outdated
Show resolved
Hide resolved
| /// <param name="appDirectory">The directory containing the Python application files.</param> | ||
| /// <param name="moduleName"></param> | ||
| /// <returns>A resource builder for further configuration of the Uvicorn Python application resource.</returns> | ||
| public static IResourceBuilder<PythonAppResource> AddUvicornApp( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to decide if we make this UvicornAppResource : PythonAppResource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the advantage to doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can build extension methods that target unvicorn configuration. We'll want that but lets file a follow up issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public static IResourceBuilder<PythonAppResource> AddUvicornApp( | ||
| this IDistributedApplicationBuilder builder, [ResourceName] string name, string appDirectory, string moduleName) | ||
| { | ||
| var resourceBuilder = builder.AddPythonExecutable(name, appDirectory, "uvicorn") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamint - is this going to cause a problem with VS Code debugging?
aspire/src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs
Lines 322 to 323 in 5a87acf
| // VS Code debug support - only applicable for Script and Module types | |
| if (entrypointType is EntrypointType.Script or EntrypointType.Module) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we cannot debug any python executable. You'll need to call WithVSCodeDebugSupport and in the launch configuration provide the right entrypoint and then uvicorn as the module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We an switch to a module instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to switch, we just need to indicate to the AppHost to start the right module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OR, we can switch and make it just work in all cases :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just not sure if there are performance differences between using the uvicorn executable and running as a python module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6e4a15d to
1030250
Compare
This allows a resource that contains files (for example a Javascript frontend) to embed its files into another app server - for example a fastapi python app backend. Key changes: * Add ContainerFilesSourceAnnotation which goes on the resource that can produce files. A resource with this annotation builds a docker image, but the image doesn't get pushed to a registry. * Add ContainerFilesDestinationAnnotation which goes on the resource that receives the files. Resources that support this COPY the static files from the source resource into their own docker image. * All compute environment resources respect a new HasEntrypoint=false bool to mean that this resource shouldn't be considered a compute resource, but should still build an image. Contributes to dotnet#12162
1030250 to
69e92f1
Compare
|
I think this is now ready. I added a few tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces support for embedding static files from one Docker container into another during the build process. This enables scenarios like embedding a JavaScript frontend (built with Vite) into a Python backend server (FastAPI/Uvicorn).
Key changes:
- New annotation system (
ContainerFilesSourceAnnotation,ContainerFilesDestinationAnnotation) to mark resources that produce/consume static files DockerfileBuildAnnotation.HasEntrypointproperty to distinguish build-only containers from compute resources- Pipeline integration to ensure static file sources are built before their consumers
AddUvicornAppextension method for FastAPI/Uvicorn applications with automatic endpoint configuration
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
ResourceBuilderExtensions.cs |
Adds PublishWithContainerFiles extension method for configuring file copying between containers |
ResourceExtensions.cs |
Splits image build logic into RequiresImageBuild and RequiresImageBuildAndPush to handle build-only containers |
IResourceWithContainerFiles.cs |
New marker interface for resources that can produce container files |
DockerfileBuildAnnotation.cs |
Adds HasEntrypoint property to identify containers without entrypoints |
DockerfileStage.cs |
Renames parameter from stage to from for clarity in CopyFrom method |
ContainerFilesSourceAnnotation.cs |
Annotation marking the source path of files within a container |
ContainerFilesDestinationAnnotation.cs |
Annotation specifying where to copy files and from which source |
PythonAppResourceBuilderExtensions.cs |
Adds AddUvicornApp method and build pipeline logic for static file integration |
ViteAppResource.cs |
Implements IResourceWithContainerFiles interface |
NodeExtensions.cs |
Configures Vite apps as build-only containers with static file annotations |
AzureEnvironmentResource.cs |
Updates to use RequiresImageBuild instead of RequiresImageBuildAndPush |
| Test files | New tests and snapshots for the static files feature |
src/Aspire.Hosting/ApplicationModel/IResourceWithContainerFiles.cs
Outdated
Show resolved
Hide resolved
src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/Aspire.Hosting/ApplicationModel/IResourceWithContainerFiles.cs
Outdated
Show resolved
Hide resolved
| @@ -1,15 +1,4 @@ | |||
| # Stage 1: Build the Vite app | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love that the Dockerfile from the template moved to the test. 😆 Now you can see the diff in the dockerfile we generate vs what was laid down before.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Attempting to deploy the template with this it seems like we're still trying to deploy the frontend even though we don't push it. |
| if (r.IsBuildOnlyContainer()) | ||
| { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like it's in the wrong place or this method has the wrong name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion it isn't. A "build only container" (i.e. one that doesn't have an entrypoint) isn't a "Compute Resource". It can't stand alone. It doesn't have an entrypoint.
Description
This allows a resource that contains static files (for example a Javascript frontend) to embed its static files into another app server - for example a fastapi python app backend.
Key changes:
Contributes to #12162
Checklist
<remarks />and<code />elements on your triple slash comments?