Skip to content

Commit d240956

Browse files
Copiloteerhardt
andauthored
Add ContainerFilesDestinationAnnotation support to ProjectResource (#12355)
* Initial plan * Add ContainerFilesDestinationAnnotation support to ProjectResource Implement pipeline step factory for ProjectResource to support copying static files from other container resources before building docker images. Co-authored-by: eerhardt <[email protected]> * Address PR feedback: use IContainerRuntime, fix PublishDir, generic source build steps - Added CopyContainerFilesAsync method to IContainerRuntime interface with implementations in ContainerRuntimeBase - Changed CopyContainerFilesToProjectAsync to use IContainerRuntime instead of calling docker directly - Fixed GetPublishDirectoryAsync to use 'dotnet msbuild -c Release -getProperty:PublishDir' instead of hardcoded path - Changed source resource build step to use generic CreateBuildImageStep instead of CreateProjectBuildImageStep Co-authored-by: eerhardt <[email protected]> * Make it work in the playground * Refactor to build project image first, then layer container files via Dockerfile - Build ProjectResource image with normal flow first - Tag built image with temporary GUID tag - Generate Dockerfile that FROMs temp image and COPY --from source containers - Build final image from generated Dockerfile with real tag - Removed CopyContainerFilesAsync from IContainerRuntime (no longer needed) - Removed GetPublishDirectoryAsync helper (no longer needed) Co-authored-by: eerhardt <[email protected]> * Revert CopyContainerFilesAsync from IContainerRuntime - no longer needed The new design uses DockerfileBuilder with COPY --from: instead of extracting files from containers to the host filesystem, so the CopyContainerFilesAsync method is no longer needed. Co-authored-by: eerhardt <[email protected]> * Make it work by using the correct image name. * Update for latest code * Add RemoveImageAsync to IContainerRuntime for cleanup of temporary images - Added RemoveImageAsync method to IContainerRuntime interface - Implemented in ContainerRuntimeBase using 'rmi' command - Uncommented cleanup code in ProjectResource to remove temporary tagged images - Ensures temporary images are cleaned up after layering container files Co-authored-by: eerhardt <[email protected]> * move test * Clean up code. * Clean up code Add more tests * Fix the playground app * Address PR feedback * Address PR feedback: Get ContainerWorkingDirectory from project and improve debugging - Get $(ContainerWorkingDirectory) from project using dotnet msbuild instead of hardcoding /app - Add GetContainerWorkingDirectoryAsync helper method with fallback to /app - Keep temporary Dockerfile on build failure for debugging purposes - Log debug message with path to temporary Dockerfile when build fails Co-authored-by: eerhardt <[email protected]> * Apply suggestion from @eerhardt * Refactor copilots code. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: eerhardt <[email protected]> Co-authored-by: Eric Erhardt <[email protected]>
1 parent cb79674 commit d240956

File tree

20 files changed

+459
-149
lines changed

20 files changed

+459
-149
lines changed

playground/AspireWithJavaScript/AspireJavaScript.Angular/default.conf.template

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ server {
1515
proxy_http_version 1.1;
1616
proxy_ssl_server_name on;
1717
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
18-
rewrite ^/api(/.*)$ $1 break;
1918
}
20-
}
19+
}

playground/AspireWithJavaScript/AspireJavaScript.Angular/proxy.conf.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ module.exports = {
22
"/api": {
33
target:
44
process.env["WEATHERAPI_HTTPS"] || process.env["WEATHERAPI_HTTP"],
5-
secure: process.env["NODE_ENV"] !== "development",
6-
pathRewrite: {
7-
"^/api": "",
8-
},
5+
secure: process.env["NODE_ENV"] !== "development"
96
},
107
};

playground/AspireWithJavaScript/AspireJavaScript.AppHost/AppHost.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
.WithExternalHttpEndpoints()
2929
.PublishAsDockerFile();
3030

31-
builder.AddViteApp("reactvite", "../AspireJavaScript.Vite")
31+
var reactvite = builder.AddViteApp("reactvite", "../AspireJavaScript.Vite")
3232
.WithNpm(install: true)
3333
.WithReference(weatherApi)
3434
.WithEnvironment("BROWSER", "none")
3535
.WithExternalHttpEndpoints();
3636

37+
weatherApi.PublishWithContainerFiles(reactvite, "./wwwroot");
38+
3739
builder.Build().Run();

playground/AspireWithJavaScript/AspireJavaScript.MinimalApi/AppHost.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
3131
};
3232

33-
app.MapGet("/weatherforecast", () =>
33+
app.MapGet("/api/weatherforecast", () =>
3434
{
3535
var forecast = Enumerable.Range(1, 5).Select(index =>
3636
new WeatherForecast
@@ -45,6 +45,8 @@
4545
.WithName("GetWeatherForecast")
4646
.WithOpenApi();
4747

48+
app.UseFileServer();
49+
4850
app.Run();
4951

5052
sealed record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)

playground/AspireWithJavaScript/AspireJavaScript.React/default.conf.template

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ server {
1515
proxy_http_version 1.1;
1616
proxy_ssl_server_name on;
1717
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
18-
rewrite ^/api(/.*)$ $1 break;
1918
}
20-
}
19+
}

playground/AspireWithJavaScript/AspireJavaScript.React/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module.exports = (env) => {
1111
context: ["/api"],
1212
target:
1313
process.env.WEATHERAPI_HTTPS || process.env.WEATHERAPI_HTTP,
14-
pathRewrite: { "^/api": "" },
1514
secure: false,
1615
},
1716
],

playground/AspireWithJavaScript/AspireJavaScript.Vite/default.conf.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ server {
1515
proxy_http_version 1.1;
1616
proxy_ssl_server_name on;
1717
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
18-
rewrite ^/api(/.*)$ $1 break;
1918
}
2019
}

playground/AspireWithJavaScript/AspireJavaScript.Vite/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export default defineConfig(({ mode }) => {
1313
'/api': {
1414
target: process.env.WEATHERAPI_HTTPS || process.env.WEATHERAPI_HTTP,
1515
changeOrigin: true,
16-
rewrite: (path) => path.replace(/^\/api/, ''),
1716
secure: false,
1817
}
1918
}

playground/AspireWithJavaScript/AspireJavaScript.Vue/default.conf.template

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ server {
1515
proxy_http_version 1.1;
1616
proxy_ssl_server_name on;
1717
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
18-
rewrite ^/api(/.*)$ $1 break;
1918
}
20-
}
19+
}

playground/AspireWithJavaScript/AspireJavaScript.Vue/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export default defineConfig({
2020
'/api': {
2121
target: process.env.WEATHERAPI_HTTPS || process.env.WEATHERAPI_HTTP,
2222
changeOrigin: true,
23-
rewrite: path => path.replace(/^\/api/, ''),
2423
secure: false
2524
}
2625
}

0 commit comments

Comments
 (0)