-
-
Notifications
You must be signed in to change notification settings - Fork 651
feat: prune orphaned Node.js versions after install, fixes #7325 #7326
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
Conversation
@@ -47,6 +47,9 @@ if [ "${n_install_result}" = "false" ]; then | |||
rm -f "${N_PREFIX}" && exit 6 | |||
fi | |||
|
|||
# prune orphaned Node.js versions | |||
log-stderr.sh n prune || true |
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 wasn’t sure if including log-stderr.sh
here was worth it given that this command isn’t really essential. Happy to remove it.
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.
It's fine to use log-stderr.sh
here.
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.
Thank you!
I'm pushing a new Docker image now.
Important: test starting/stopping the project, then disable Internet and start the project again. It should work as before.
@@ -47,6 +47,9 @@ if [ "${n_install_result}" = "false" ]; then | |||
rm -f "${N_PREFIX}" && exit 6 | |||
fi | |||
|
|||
# prune orphaned Node.js versions | |||
log-stderr.sh n prune || true |
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.
It's fine to use log-stderr.sh
here.
A new Docker image is ready, build artifacts will appear shortly below. |
Download the artifacts for this pull request:
See Testing a PR. |
Hmm, it’s not working properly - it removes all the versions. Node still “works” but when restarting without an internet connection it fails over to Node 22 (presumably whatever is installed with the image by default). I think this may be because the prune command needs to be moved after the symlinks are added here: ddev/containers/ddev-webserver/ddev-webserver-base-files/usr/local/bin/n-install.sh Lines 50 to 57 in 2842925
https://github.com/tj/n/blob/f52d2172f12cd76f0efe9524690723f52ab74f40/bin/n#L477-L494 I’ve pushed a commit that moves the command. If that works I can squash the commits + force push if you’d like, not sure if you’d prefer that done upfront or if you’ll squash + merge |
We always squash on merge, no need to do it here. Pushing a new image. |
The new Docker image is ready. Before testing run:
|
Great! I'll test it later today as well. (Ignore the "Container tests" failure: it's unrelated to this PR.) |
0480dbd
to
02c6ff9
Compare
Rebased to fix 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.
Thank you!
There might be cases where someone wants to install multiple Node versions, but they can work around it by using a different N_PREFIX
.
The logic behaves as expected:
$ ddev config --nodejs-version="14.1.0"
$ ddev start
$ ddev exec node -v
v14.1.0
$ ddev exec "n install 14 && n install 16 && n install 18"
$ ddev exec n ls
node/14.1.0
node/14.21.3
node/16.20.2
node/18.20.8
$ ddev config --nodejs-version="14"
$ ddev restart
$ ddev exec node -v
v14.21.3
# only one version as expected
$ ddev exec n ls
node/14.21.3
$ ddev exec "n install 14.21.2 && n install 14.21.1 && n install 14.21.0"
$ ddev exec n ls
node/14.21.0
node/14.21.1
node/14.21.2
node/14.21.3
$ ddev poweroff
# turn off the Internet
$ ddev start
$ ddev exec node -v
v14.21.3
# only one version as expected
$ ddev exec n ls
node/14.21.3
$ ddev restart
$ ddev exec node -v
v14.21.3
# only one version as expected
$ ddev exec n ls
node/14.21.3
The Issue
How This PR Solves The Issue
Runs the
n prune
commandManual Testing Instructions
Open the
ddev-global-cache
volume and look at a long-standing project’s directory:n_prefix/<project-name>/n/versions/node/
. It’ll likely already contain multiple Node.js versions.After this change, the next time you start DDEV only the most recent Node.js version should be present
Automated Testing Overview
I’m not really sure how you’d test this, but given that this is a non-essential enhancement (everything’s running fine without this change, it just saves some disk space) I don’t think additional testing is necessary
Release/Deployment Notes
N/A