-
Notifications
You must be signed in to change notification settings - Fork 156
Add IContainerFilesDestinationResource support to Golang integration #1108
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 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fb673a7
Initial plan
Copilot a1bd344
Add IContainerFilesDestinationResource support to Golang integration
Copilot 30b0543
Add test and documentation for IContainerFilesDestinationResource sup…
Copilot 0de94a3
Add static frontend example to demonstrate container files feature
Copilot 205770c
Add AddContainerFiles call to Golang Dockerfile generation
Copilot a3ff324
Update examples/golang/gin-api/main.go
tommasodotNET b55b42a
Update examples/golang/CommunityToolkit.Aspire.Hosting.Golang.AppHost…
tommasodotNET ab58d40
Update src/CommunityToolkit.Aspire.Hosting.Golang/README.md
tommasodotNET 24820d5
Update examples/golang/static-frontend/README.md
tommasodotNET 841d2bf
Add integration test for container files functionality
Copilot 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
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
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,39 @@ | ||
| # Static Frontend Example | ||
|
|
||
| This directory contains a simple static HTML frontend that demonstrates the container files feature of the Golang integration. | ||
|
|
||
| ## Purpose | ||
|
|
||
| When publishing an Aspire application, static files from this directory can be copied into the Golang container using the `WithContainerFiles` method. This is useful for serving frontend assets (HTML, CSS, JavaScript, images, etc.) directly from your Go application. | ||
|
|
||
| ## Usage | ||
|
|
||
| In your AppHost `Program.cs`, you can configure the Golang resource to copy these files: | ||
|
|
||
| ```csharp | ||
| var golang = builder.AddGolangApp("golang", "../gin-api") | ||
| .WithHttpEndpoint(env: "PORT") | ||
| .WithContainerFiles("/app/static", "../static-frontend"); | ||
| ``` | ||
|
|
||
| The Golang application is configured to serve these files from the `/static` endpoint. When running in a container, the files will be available at `http://localhost:<port>/static/index.html`. | ||
|
|
||
| ## Container Files Feature | ||
|
|
||
| The Golang resource implements `IContainerFilesDestinationResource`, which tells the Aspire publishing pipeline where to copy files when building the container image. The default destination is `/app/static`, but this can be customized. | ||
tommasodotNET marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This feature works with any resource that produces output files, including: | ||
| - Static file directories (like this example) | ||
| - Frontend build tools (Vite, webpack, Create React App, etc.) | ||
| - Documentation generators | ||
| - Any other build output | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| The feature works by: | ||
| 1. The Golang resource implementing `IContainerFilesDestinationResource` | ||
| 2. Using `WithContainerFiles` to specify the source and destination | ||
| 3. During publishing, the Aspire pipeline automatically copies the files into the generated Docker image | ||
| 4. The Golang application serves the files using Gin's `Static` method | ||
|
|
||
| See the main README in the parent directory for more details. | ||
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,42 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Golang + Static Frontend Example</title> | ||
| <style> | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| max-width: 800px; | ||
| margin: 50px auto; | ||
| padding: 20px; | ||
| background-color: #f5f5f5; | ||
| } | ||
| .container { | ||
| background-color: white; | ||
| padding: 30px; | ||
| border-radius: 8px; | ||
| box-shadow: 0 2px 4px rgba(0,0,0,0.1); | ||
| } | ||
| h1 { | ||
| color: #00ADD8; | ||
| } | ||
| .status { | ||
| padding: 10px; | ||
| margin-top: 20px; | ||
| background-color: #e7f3ff; | ||
| border-left: 4px solid #00ADD8; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div class="container"> | ||
| <h1>🚀 Golang + Static Frontend</h1> | ||
| <p>This static HTML page is served from the Golang container!</p> | ||
| <p>It demonstrates the container files feature, where static frontend files are copied into the Golang container during publishing.</p> | ||
| <div class="status"> | ||
| <strong>Status:</strong> Container files feature working! ✅ | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
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
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
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
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.