Skip to content

Conversation

drzraf
Copy link
Contributor

@drzraf drzraf commented Aug 21, 2024

  1. docker exec and docker-compose exec provide an option to cleanly set the working directory before running a command
    => Use it instead and use cd <...> ; command-prefixing in vagrant/ssh cases

  2. Using docker scheme, wp post update 1 - <<<foo didn't worked (issue passing stdin to command for docker-based WP instances #4972)

  • Because STDOUT being a tty, -t is passed with no ability to inhibit this
  • Because docker -i flag is necessary

=> As such:

  • docker -i (--interactive) is introduced (with sensible autodetection)
  • WP_CLI_DOCKER_NO_TTY and WP_CLI_DOCKER_NO_INTERACTIVE environment variables are introduced to optionally inhibit these respective flags

   cleanly set the working directory before running a command
=> Use it instead and use `cd <...> ;` command-prefixing in vagrant/ssh cases

2. Using `docker` scheme, `wp post update 1 - <<<foo` didn't worked (issue wp-cli#4972)
* Because STDOUT being a tty, `-t` is passed with no ability to inhibit this
* Because docker `-i` flag is necessary

=> As such:
* docker `-i` (`--interactive`) is introduced (with sensible autodetection)
* `WP_CLI_DOCKER_NO_TTY` and `WP_CLI_DOCKER_NO_INTERACTIVE` environment variables
  are introduced to optionally inhibit these respective flags
@drzraf
Copy link
Contributor Author

drzraf commented Nov 6, 2024

ping?

@schlessera
Copy link
Member

I already tested this in the past, and while it seemed to do what it is supposed to do, I was unsure at the time whether I considered all implications and tested all edge cases.
However, this has waiting for long enough already. Let's merge it as-is, I'm sure the edge cases will show themselves on their own accord then... ;)

Thanks for the PR, @drzraf !

@schlessera schlessera merged commit 1a98480 into wp-cli:main Feb 5, 2025
13 of 42 checks passed
@schlessera schlessera added this to the 2.12.0 milestone Feb 5, 2025
@swissspidy
Copy link
Member

@schlessera This actually had some test failures, see https://github.com/wp-cli/wp-cli/actions/runs/13191576733/job/36825712748#step:11:295 for example

@swissspidy
Copy link
Member

@drzraf @schlessera Unfortunately I had to temporarily revert this in #6049 because of a test failure. But we can try to land it again.

@drzraf
Copy link
Contributor Author

drzraf commented Feb 26, 2025

Can't reproduce the failure locally: composer behat -- features/flags.feature passes

16 scenarios (16 passed)
98 steps (98 passed)
0m27.49s (11.38Mb)

and the full run gives

233 scenarios (228 passed, 5 failed)
2416 steps (2390 passed, 5 failed, 21 skipped)
11m39.65s (11.97Mb)

but none of these 5 failures matches those mentioned by the CI

@mrsdizzie
Copy link
Member

The problem is that in the CI it is setting the -i flag (from the new code in this PR), which you can see in the failed test:

  Debug (bootstrap): Running SSH command: docker exec --user 'user' -i 'wordpress' sh -c 'wp '\''--debug'\'' '\''--version'\''' (0.074s)

But the test does not expect that new -i:

Scenario: SSH flag should support Docker
When I try `wp --debug --ssh=docker:user@wordpress --version`
Then STDERR should contain:
"""
Running SSH command: docker exec --user 'user' 'wordpress' sh -c
"""

The tests pass locally because
$is_stdin_tty = function_exists( 'posix_isatty' ) ? posix_isatty( STDIN ) : true;
Will return true because STDIN is attached to your local terminal which is a TTY.

You can reproduce the CI failure by piping the test through cat which will remove the tty:

composer behat -- features/flags.feature:357 | cat

FWIW I think the double negative here is a bit confusing and hard to follow

! $is_stdin_tty && ! getenv( 'WP_CLI_DOCKER_NO_INTERACTIVE' ) ? '-i ' : ''

The test should probably be updated and include the environment variables so the output is the same across local and ci testing. I think otherwise it would require creating a new custom step to check for tty if we really wanted to test the tty detection as well.

swissspidy added a commit that referenced this pull request Mar 4, 2025
 docker scheme: working-directory and stdin passing (reroll of #5974)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants