-
-
Notifications
You must be signed in to change notification settings - Fork 616
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
fix: expand ~/bin
in PATH and ensure consistency in subshells, for #6627
#6689
Conversation
e605e9f
to
4129261
Compare
Why was |
Download the artifacts for this pull request:
See Testing a PR. |
It's the first item in the ddev/containers/ddev-webserver/ddev-webserver-base-files/etc/bashrc/commandline-addons.bashrc Line 1 in 92cd790
|
Sorry, my question is not whether it should work, but why we would have used it as a composer instance. As we've seen with the |
To use a different Even though I don't use it this way, I see a problem here as well, for example, after installing it, you can't uninstall it in the usual way because it can't uninstall itself:
|
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.
Minor suggestions.
I generally don't think we should add every workaround for every obscure case we encounter to the docs, because they get cluttered. I usually point to Stack Overflow for cases like that.
@@ -95,7 +95,13 @@ Composer version for the web container and the [`ddev composer`](../usage/comman | |||
| :octicons-file-directory-16: project | `2` | Can be `2`, `1`, or empty (`""`) for latest major version at container build time.<br><br>Can also be a minor version like `2.2` for the latest release of that branch, an explicit version like `1.0.22`, or a keyword like `stable`, `preview` or `snapshot`. See Composer documentation. | |||
|
|||
!!!note "If your `composer.json` requires `composer/composer` that version will be used instead" | |||
If your project `composer.json` includes `composer/composer`, then the version specified there will normally be used instead of any version specified by `composer_version`, since `vendor/bin/composer` will come first in the in-container `$PATH`. | |||
If your project `composer.json` includes `composer/composer`, then the version specified there will normally be used instead of any version specified by `composer_version`, since `vendor/bin/composer` will come first in the in-container `$PATH`. However, if you prefer to use the version specified by `composer_version`, add the following hook to your `.ddev/config.yaml`: |
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 seems like a very unusual workaround. Why would people not want to use the version they specify in their composer.json?
I worry that adding too much detail in places like this just makes it so people can't make it through the docs, or find the right thing when they need 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.
Why would people not want to use the version they specify in their composer.json?
It's less about matching the version, and more about issues upgrading composer itself since PHP can't reload classes it's already loaded: composer/composer#11672
I wonder if this should also be improved upstream. Perhaps composer should never install vendor/bin/composer
, or if it needs to it should be something like vendor/bin/composer.internal
.
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 worry that adding too much detail in places like this just makes it so people can't make it through the docs, or find the right thing when they need it.
I think if people use Composer in such an advanced way, they'll know how to change something in $PATH
.
I'll remove this example from the docs because it's unlikely to be found.
pkg/ddevapp/composer.go
Outdated
path, _, err := app.Exec(&ExecOpts{ | ||
Cmd: "echo $PATH", | ||
Cmd: `echo $PATH | sed "s|~|$HOME|g"`, |
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 wonder if homedir.Expand() could be used successfully here. Probably not, since this is in the context of the container. But transformations like this are notoriously fragile.
(I don't understand what homedir.Expand() replaces the ~ with. It it's $HOME, it's good, I don't think it is.)
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 PR is not only about Composer binary override, but also if in the future we have some commands that will work just like ddev composer
with PATH
.
This entry in PATH=~/bin
should really be PATH=$HOME/bin
, then we don't need these ugly workarounds.
I'll also look into the PATH
problem with subshells while I'm here:
411afd0
to
e754818
Compare
~/bin
for composer commands, for #6627~/bin
in PATH and ensure consistency in subshells, for #6627
Side note: when you have hooks:
post-start:
- exec: mkdir -p ~/bin and run
It has a second entry for
It doesn't check if I decided not to change/fix it. |
export PATH="~/bin:$PATH:/var/www/html/bin" | ||
case ":$PATH:" in | ||
*":$HOME/bin:"*) ;; | ||
*) PATH="$HOME/bin:$PATH" ;; |
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.
So the fix is to write $HOME/bin
instead of ~/bin
just like Debian does.
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 also needs a comment explaining what it's doing.
But it's great, and an excellent solution.
2c506da
to
10ef45e
Compare
Rebased for colima/lima problem |
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.
Minor suggestions just to make sure future readers can grok what's going on.
case ":$PATH:" in | ||
*":${DDEV_COMPOSER_ROOT:-/var/www/html}/vendor/bin:"*) ;; | ||
*) PATH="${DDEV_COMPOSER_ROOT:-/var/www/html}/vendor/bin:$PATH" ;; | ||
esac |
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 think this is a fine solution, but it's really, really cryptic. Please add a comment to both places explaining what it does.
export PATH="~/bin:$PATH:/var/www/html/bin" | ||
case ":$PATH:" in | ||
*":$HOME/bin:"*) ;; | ||
*) PATH="$HOME/bin:$PATH" ;; |
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 also needs a comment explaining what it's doing.
But it's great, and an excellent solution.
Comments added (without a new image rebuild). |
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.
Thanks!
f3a56f2
to
7f481cc
Compare
Rebased, fixed versionconstants, needs image push. Could you push the ddev-webserver image or give me perms on your fork? |
The Issue
These comments:
And:
Inside the subshells, some strange things happen:
For:
How This PR Solves The Issue
PATH=~/bin:...
as env, it doesn't understand what~
means. This PR replaces~
with$HOME
.export PATH=...
was added every time you go into the subshell, which led to more and more entries being added to the$PATH
. I don't know if it affects anything, but it looks pretty weird, so I fixed it.Manual Testing Instructions
Using DDEV HEAD, install composer:
Add this to
.ddev/config.yaml
:Try
echo $PATH
in subshells:It should be the same each time.
Automated Testing Overview
Release/Deployment Notes