Skip to content

Automatically run unknown commands in the web container - #3695

Closed
gilbertsoft wants to merge 2 commits into
ddev:masterfrom
gilbertsoft:task/auto-commands
Closed

gilbertsoft wants to merge 2 commits into
ddev:masterfrom
gilbertsoft:task/auto-commands

Conversation

@gilbertsoft

@gilbertsoft gilbertsoft commented Mar 13, 2022 •

Copy link
Copy Markdown
Contributor

The Problem/Issue/Bug:

Currently to run a command in the web container a proper custom command has to be defined. It would be nice if unknown commands are just forwarded to the web container without the need of defining a custom command. If the command is not found it still can fail later.

How this PR Solves The Problem:

Unknown commands are simply forwarded to the web container and if found the exit code is properly returned.

If the command is not found an error is shown like it's done before.

Manual Testing Instructions:

  • run ddev ls, the content of var/www/html should be listed
  • run ddev invalid, an error should be shown

Automated Testing Overview:

Related Issue Link(s):

Release/Deployment notes:

@rfay

rfay commented Mar 17, 2022

Copy link
Copy Markdown
Member

You'll want to rebase when you get back to this, thanks.

@rfay

rfay commented Mar 30, 2022

Copy link
Copy Markdown
Member

Looking forward to seeing this see the light of day. The only issue is whether it can be predictable for people. How will help work? How will people know what anything does?

@rfay

rfay commented Apr 27, 2022

Copy link
Copy Markdown
Member

Do you think this has a future @gilbertsoft ? It's nice, but the ambiguity of what to expect is a little troublesome. Easy enough to fix the test failure.

@gilbertsoft

Copy link
Copy Markdown
Contributor Author

Lets finish this one, will rebase later...

@gilbertsoft
gilbertsoft force-pushed the task/auto-commands branch 2 times, most recently from 756e4d7 to 4fd66a2 Compare May 6, 2022 13:53
@github-actions

github-actions Bot commented May 6, 2022 •

Copy link
Copy Markdown

@gilbertsoft
gilbertsoft marked this pull request as ready for review May 7, 2022 09:05
@gilbertsoft

Copy link
Copy Markdown
Contributor Author

Tested now and works like expected. I'm currently restarting the failing tests which don't have real issues...

@gilbertsoft
gilbertsoft force-pushed the task/auto-commands branch from 4fd66a2 to 7ef648e Compare May 8, 2022 15:11
@rfay

rfay commented May 11, 2022

Copy link
Copy Markdown
Member

It turns out that buildkite tests are run with Drupal6 by default, meaning that TestCustomCommands starts out with Drupal6. Then when the test changes the config type to php, it doesn't restart the container, meaning drush is still in there, so the test detects drush in that circumstance. At least I think this was the issue. I pushed b5b4f63 to try to fix this.

@rfay
rfay requested review from cmuench and jonaseberle May 11, 2022 22:18
@rfay

rfay commented May 11, 2022

Copy link
Copy Markdown
Member

@cmuench @jonaseberle Would love it if you could review this and try it out. It's a slick enhancement, my only concern is that it could cause confusion because of the undefined nature of commands in the future.

@jonaseberle jonaseberle left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works very well. Thank you @gilbertsoft!

I've tested with
ddev ssh (DDEV builtin)
ddev mysql (DDEV global command)
ddev dump-db live (DDEV custom command)
ddev vendor/bin/phpunit
ddev ls (command from $PATH)
ddev jq --help (check if parameter is appended to ddev or to the sub command)
ddev 'jq --help'
ddev 'source .env; echo $TYPO3_CONTEXT' (bash builtin)
ddev 'ls -als | grep public' && echo success || echo failed (pipes and exit codes)
ddev 'ls -als | grep nonexisting' && echo success || echo failed

@jonaseberle

Copy link
Copy Markdown
Member

I think it is conceptually in a tough spot:
For working inside a container we have ddev ssh, for executing commands there is ddev exec.

This feature works beautifully, but on the other hand it only saves the user from using ddev exec.

My opinion: Having 2 ways for the same thing should generally be avoided. It makes it more difficult to show a coherent usage in docs/blog posts/support channels. Some will love it because they need to type 5 characters less, others will not use it in examples because they don't like ambiguity. I am quite sure a Twitter post about it would get generally good responses, too.
My question is if the advantages outweigh.

@gilbertsoft

gilbertsoft commented May 13, 2022 •

Copy link
Copy Markdown
Contributor Author

Please see https://discord.com/channels/664580571770388500/950743021790576700 where this idea was born. I personally don't have a final opinion, it was just an idea to simlify things so I prepared this POC.

Ongoing discussion is available here https://discord.com/channels/664580571770388500/972480296899448842.

@rfay

rfay commented May 13, 2022

Copy link
Copy Markdown
Member

There are ddev exec, ddev ., and loads of shell-command wrappers. I think the confusion among all those things is in fact the real problem.

One dramatic option would be to put this on major-release track (v1.20) and at the same time remove the wrappers, like ddev php and ddev typo3, etc. I guess the issue with some of those is that the command is not necessarily in the $PATH.

@gilbertsoft

Copy link
Copy Markdown
Contributor Author

Yeah, removing existing custom commands sounds like a good idea. But this also removes them from the command list which was always a nice feature, but well, personally could live with that. We could introduce here sth like done for pull and push for the less experienced users to get a hint on project specific commands maybe...

The $PATH should be set correctly as long as the user doesn't change the install structure. And if he does he also should take care of a proper $PATH override which I'm also doing for some special cases:

web_environment:
- PATH=/var/www/html/public/bin:$PATH

@gilbertsoft

gilbertsoft commented May 13, 2022 •

Copy link
Copy Markdown
Contributor Author

We also can enhance the exec command description and say explicit this is the default command and exec can be omitted.

Because this really changes DDEV's behavior putting it into 1.20 sound also like a good idea!

@rfay

rfay commented May 13, 2022

Copy link
Copy Markdown
Member

I'm sure we could shim in key commands into the help list without custom commands, so that's something to think about.

@rfay

rfay commented May 13, 2022

Copy link
Copy Markdown
Member

We also can enhance the exec command description and say explicit this is the default command and exec can be omitted.

Interesting thinking @gilbertsoft - However, exec is still used for other services (db, add-on, etc). But still worthy thinking.

@gilbertsoft

Copy link
Copy Markdown
Contributor Author

We also can enhance the exec command description and say explicit this is the default command and exec can be omitted.

Interesting thinking @gilbertsoft - However, exec is still used for other services (db, add-on, etc). But still worthy thinking.

I guess sth like ddev -s db ls should also work but not tested so far.

@cmuench

cmuench commented May 13, 2022 •

Copy link
Copy Markdown
Collaborator

I'm still a little unsure about this change. There are pros and cons.
IMHO one of the advantages of ddev is that it provides such a simple way to add custom commands for developers which can be shared in a team. There is no other tool with that simple approach. We should do anything to keep custom commands.
Custom commands whould be listed if we see the command list.

If I type only "ddev", then we should see the command list.
On the other hand this change provides a way to deduce a lot of this one line proxy shell scripts.

Then we have ddev . which is really unknown.

gilbertsoft and others added 2 commits May 24, 2022 19:23
Since this may have been spun up as Drupal6 instance,
and then only afterwards changed (in config) to php
it may still have /usr/local/bin/drush linked, which will
make ddev drush work
@rfay
rfay force-pushed the task/auto-commands branch from b5b4f63 to 0e0ad3c Compare May 25, 2022 01:23
@rfay

rfay commented May 25, 2022

Copy link
Copy Markdown
Member

Rebased.

@shaal

shaal commented Jun 3, 2022 •

Copy link
Copy Markdown
Collaborator

My 2 cents -

  • I have some concerns with this PR (users won't be aware that a command ran inside the container without them directing ddev to do so.
  • In DrupalPod, I made a few specific custom commands available (composer, php, node), but added a message every time you run them echo "Notice: running 'composer $*' in ddev"
  • I this the current separation between ddev <custom-ddev-command> and ddev . <any-command> is a good thing.
  • I think adding the following functionality could be helpful - when you run ddev unknown_command and it's not found in custom commands, ddev could prompt - "Did you want to run unknown_command inside the container?", hitting y would run that command in the container for you.
  • I was sure I opened an issue about this before, but I guess I didn't 😅, in DrupalPod I added generic custom command exec_d that check your current directory, and runs the command in the same relative directory in the container
    https://github.com/shaal/DrupalPod/blob/main/.ddev/commands/host/exec_dir

update: I added an issue for that last piece #3881

@gilbertsoft

Copy link
Copy Markdown
Contributor Author

@rfay well, my PoC here showed it would work. But like others I'm also not sure if we should merge it at this point. So I suggest to close this PR until a real issue pops up and get back on it if really needed....

@rfay

rfay commented Jun 24, 2022

Copy link
Copy Markdown
Member

I do think it is brilliant, but the fact that we lose control of the commands, and don't have a way to provide help, and it's pretty disruptive. But I think there might be a way to provide a small bit of help for the most important commands, not sure. But probably you're right. It certainly can't go in until I start on non-minor-release candidate work.

@mbomb007

mbomb007 commented Jun 30, 2022 •

Copy link
Copy Markdown
Contributor

Just make sure that it's not the only way to run commands. Because what if you have a bash command start, but that's shadowed by ddev start? Having ddev exec makes it clear you intend to hit the web container. Similarly, not using exec makes it clear you're trying to find a ddev command. This was a nice idea, but I'm against it for the reason that the behavior of commands is less predictable.

Still, consolidating ddev php and other alternatives sounds nice.

@rfay

rfay commented Jul 3, 2022

Copy link
Copy Markdown
Member

I think we have a general consensus that we lose too much control of the user workflow with this approach. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants