-
Notifications
You must be signed in to change notification settings - Fork 733
Refactor AddNodeApp #12538
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
Refactor AddNodeApp #12538
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12538Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12538" |
76bf405 to
e3dc209
Compare
- Obsolete the existing AddNodeApp that takes a file path only - Introduce a new AddNodeApp that takes a directory path and a file path relative to that directory - Includes a default Dockerfile for the Node application - Add Npm package manager support if the directory contains a package.json file
e3dc209 to
294ee9f
Compare
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 pull request refactors the Node.js application hosting API in Aspire to separate the application directory from the script path, improving clarity and consistency. The PR changes the default run script from "start" to "dev" and adds support for custom run script arguments.
Key Changes:
- Introduces a new
AddNodeAppoverload that takes separateappDirectoryandscriptPathparameters, marking the old signature as obsolete - Changes the default run script from "start" to "dev" for
AddJavaScriptApp - Adds
WithRunScriptextension method to support custom script arguments - Automatically configures npm as the package manager when
package.jsonexists
Reviewed Changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Aspire.Hosting.NodeJs/NodeExtensions.cs | Added new AddNodeApp overload with improved API design, marked old overload as obsolete, changed default run script to "dev", enhanced WithRunScript to support arguments |
| src/Aspire.Hosting.NodeJs/Aspire.Hosting.NodeJs.csproj | Added OverloadResolutionPriorityAttribute to project for C# overload resolution |
| tests/Aspire.Hosting.Tests/DistributedApplicationTests.cs | Updated test to use new AddNodeApp API signature with separate directory and script parameters |
| tests/Aspire.Hosting.NodeJs.Tests/PackageInstallationTests.cs | Updated tests to expect "dev" as default script, added test for WithRunScript with custom arguments, minor formatting fix |
| tests/Aspire.Hosting.NodeJs.Tests/NodeJsPublicApiTests.cs | Updated tests to use new AddNodeApp API signature |
| tests/Aspire.Hosting.NodeJs.Tests/NodeAppFixture.cs | Updated fixture to use new AddNodeApp API signature |
| tests/Aspire.Hosting.NodeJs.Tests/AddNodeAppTests.cs | Added comprehensive tests for new API behavior including Dockerfile generation and npm detection |
| playground/AspireWithJavaScript/AspireJavaScript.NodeApp/* | Added new sample Node.js application with Express server, package.json, and HTML frontend |
| playground/AspireWithJavaScript/AspireJavaScript.AppHost/AppHost.cs | Updated existing apps to explicitly use "start" script and added new Node.js app with "dev" script |
Files not reviewed (1)
- playground/AspireWithJavaScript/AspireJavaScript.NodeApp/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)
src/Aspire.Hosting.NodeJs/NodeExtensions.cs:28
- Corrected grammar: 'Node should available' should be 'Node should be available'. This appears in the obsoleted method documentation as well.
/// Adds a node application to the application model. Node should available on the PATH.
IEvangelist
left a comment
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.
LGTM
Use multi-stage build. Set NODE_ENV. Expose the port. Use a non-root user.
| .Copy(".", "."); | ||
|
|
||
| var builderStage = dockerfileContext.Builder | ||
| .From($"node:{nodeVersion}-slim", "build") |
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.
@davidfowl @mitchdenny - if we decided to use -alpine by default, the size reduces by about 100MB.
Using the playground app I added, sizes are:
- Current: 334 MB
- Combining all steps into a single stage: 349 MB
- Using
node:22-alpine: 237 MB
Should we default to that instead? And if someone needs a different base image, we can add support for defining the base image via an annotation.
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 went with -alpine by default. We will allow people to change the base image with an annotation.
|
/backport to release/13.0 |
|
Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/18982618551 |
|
Tested and it works! |
|
This fixes many parts of #8350. But it doesn't fix |
Description
Fix #8350
Checklist
<remarks />and<code />elements on your triple slash comments?