Opened 4 weeks ago
Closed 3 days ago
#63564 closed defect (bug) (fixed)
Dev environment should incorporate enhancements from wp-env for speed and non-interactive usage
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.8.2 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | has-patch fixed-major dev-reviewed |
Focuses: | Cc: |
Description (last modified by )
In gutenberg#49168 (fixed in gutenberg#50007), the cli
container is kept running so that repeated calls to WP-CLI run very quick and avoid noisy messages like:
[+] Creating 2/2 ✔ Container wordpress-develop-mysql-1 Running 0.0s ✔ Container wordpress-develop-php-1 Running
This should be done for the wordpress-develop environment as well, as currently repeated calls to env:cli
are very slow. For example, running npm run env:install
includes multiple calls to the cli
container, and it takes 15 seconds on my machine. However, if the cli
container is already running, then it takes just 4 seconds.
Additionally, when attempting to use env:cli
in a non-interactive context (e.g. piping content from stdin or using in a shell script), Docker emits an error:
$ echo "WP Develop" | npm --silent run env:cli -- option set blogname [+] Creating 2/2 ✔ Container wordpress-develop-mysql-1 Running 0.0s ✔ Container wordpress-develop-php-1 Running 0.0s the input device is not a TTY
Finally, the arguments from npm run env:cli
are not not being passed in a way that allows for spaces to be used in an argument name. For example:
$ npm --silent run env:cli option set blogname "WordPress Develop" [+] Creating 2/2 ✔ Container wordpress-develop-php-1 Running 0.0s ✔ Container wordpress-develop-mysql-1 Running 0.0s Error: Too many positional arguments: Develop
This is a follow-up to #63543.
Change History (14)
This ticket was mentioned in PR #8969 on WordPress/wordpress-develop by @westonruter.
4 weeks ago
#2
- Keywords has-patch added
#3
follow-up:
↓ 4
@
4 weeks ago
- Keywords needs-testing added
Hi @westonruter,
When I try to apply the patch, I encounter the following issue:
Running "patch:https://github.com/WordPress/wordpress-develop/pull/8969.diff" (patch) task patching file .github/workflows/reusable-test-local-docker-environment-v1.yml patching file docker-compose.yml Hunk #1 succeeded at 110 (offset -1 lines). patching file package.json patching file tools/local-env/scripts/docker.js patching file tools/local-env/scripts/install.js Hunk #1 FAILED at 13. 1 out of 1 hunk FAILED -- saving rejects to file tools/local-env/scripts/install.js.rej patching file tools/local-env/scripts/start.js patching file tools/local-env/scripts/utils.js Done.
The failed hunk appears to correspond to this line in install.js:
// Create wp-config.php. -wp_cli( `config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --force --config-file=${process.env.LOCAL_DIR}/../wp-config.php` ); +wp_cli( `config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --force --config-file="wp-config.php"` );
I already have a wp-config.php file in my root directory, so I'm unsure why this part of the patch is failing or if it’s even necessary to create the config file in my case.
#4
in reply to:
↑ 3
;
follow-up:
↓ 5
@
4 weeks ago
Replying to sandeepdahiya:
I already have a wp-config.php file in my root directory, so I'm unsure why this part of the patch is failing or if it’s even necessary to create the config file in my case.
Get the latest changes from trunk
and pull them again before applying the patch.
#5
in reply to:
↑ 4
@
4 weeks ago
Replying to SirLouen:
Get the latest changes from
trunk
and pull them again before applying the patch.
Thank you @SirLouen.
In my case, the test results are:
#Before-patch:
$ time npm run env:install > WordPress@6.9.0 env:install > node ./tools/local-env/scripts/install.js [+] Creating 2/2 ✔ Container wordpress-develop-mysql-1 Running 0.0s ✔ Container wordpress-develop-php-1 Running 0.0s Success: Generated 'wp-config.php' file. [+] Creating 2/2 ✔ Container wordpress-develop-mysql-1 Running 0.0s ✔ Container wordpress-develop-php-1 Running 0.0s Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the raw value 'true'. [+] Creating 2/2 ✔ Container wordpress-develop-mysql-1 Running 0.0s ✔ Container wordpress-develop-php-1 Running 0.0s Success: Added the constant 'WP_DEBUG_LOG' to the 'wp-config.php' file with the raw value 'true'. [+] Creating 2/2 ✔ Container wordpress-develop-php-1 Running 0.0s ✔ Container wordpress-develop-mysql-1 Running 0.0s Success: Added the constant 'WP_DEBUG_DISPLAY' to the 'wp-config.php' file with the raw value 'true'. [+] Creating 2/2 ✔ Container wordpress-develop-mysql-1 Running 0.0s ✔ Container wordpress-develop-php-1 Running 0.0s Success: Added the constant 'SCRIPT_DEBUG' to the 'wp-config.php' file with the raw value 'true'. [+] Creating 2/2 ✔ Container wordpress-develop-mysql-1 Running 0.0s ✔ Container wordpress-develop-php-1 Running 0.0s Success: Added the constant 'WP_ENVIRONMENT_TYPE' to the 'wp-config.php' file with the value 'local'. [+] Creating 2/2 ✔ Container wordpress-develop-mysql-1 Running 0.0s ✔ Container wordpress-develop-php-1 Running 0.0s Success: Added the constant 'WP_DEVELOPMENT_MODE' to the 'wp-config.php' file with the value 'core'. [+] Creating 2/2 ✔ Container wordpress-develop-mysql-1 Running 0.0s ✔ Container wordpress-develop-php-1 Running 0.0s Success: Database reset. [+] Creating 2/2 ✔ Container wordpress-develop-mysql-1 Running 0.0s ✔ Container wordpress-develop-php-1 Running 0.0s Success: WordPress installed successfully. real 0m29.395s user 0m0.212s sys 0m0.151s
#After-patch: (much cleaner and faster)
time npm run env:install > WordPress@6.9.0 env:install > node ./tools/local-env/scripts/install.js Success: Generated 'wp-config.php' file. Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the raw value 'true'. Success: Added the constant 'WP_DEBUG_LOG' to the 'wp-config.php' file with the raw value 'true'. Success: Added the constant 'WP_DEBUG_DISPLAY' to the 'wp-config.php' file with the raw value 'true'. Success: Added the constant 'SCRIPT_DEBUG' to the 'wp-config.php' file with the raw value 'true'. Success: Added the constant 'WP_ENVIRONMENT_TYPE' to the 'wp-config.php' file with the value 'local'. Success: Added the constant 'WP_DEVELOPMENT_MODE' to the 'wp-config.php' file with the value 'core'. Success: Database reset. Success: WordPress installed successfully. real 0m18.533s user 0m0.185s sys 0m0.167s
#Before-patch:
$ time npm run env:cli post list > WordPress@6.9.0 env:cli > node ./tools/local-env/scripts/docker.js run --rm cli post list [+] Creating 2/2 ✔ Container wordpress-develop-php-1 Running 0.0s ✔ Container wordpress-develop-mysql-1 Running 0.0s +----+--------------+-------------+---------------------+-------------+ | ID | post_title | post_name | post_date | post_status | +----+--------------+-------------+---------------------+-------------+ | 1 | Hello world! | hello-world | 2025-06-13 15:38:57 | publish | +----+--------------+-------------+---------------------+-------------+ real 0m4.975s user 0m0.138s sys 0m0.152s
#After-patch:
$ time npm run env:cli post list > WordPress@6.9.0 env:cli > node ./tools/local-env/scripts/docker.js exec cli wp --allow-root post list +----+--------------+-------------+---------------------+-------------+ | ID | post_title | post_name | post_date | post_status | +----+--------------+-------------+---------------------+-------------+ | 1 | Hello world! | hello-world | 2025-06-13 16:01:46 | publish | +----+--------------+-------------+---------------------+-------------+ real 0m3.520s user 0m0.120s sys 0m0.137s
#Before-patch:
$ time npm --silent run env:cli option set blogname "My World" [+] Creating 2/2 ✔ Container wordpress-develop-php-1 Running 0.0s ✔ Container wordpress-develop-mysql-1 Running 0.0s Error: Too many positional arguments: World real 0m5.503s user 0m0.165s sys 0m0.136s
#After-patch (argument passing was also successful):
time npm --silent run env:cli option set blogname "My World" Success: Value passed for 'blogname' option is unchanged. real 0m3.703s user 0m0.075s sys 0m0.167s
This is the result for
$ npm run test:e2e Running 25 tests using 1 worker: ................................................................................................ 2 failed [chromium] › tests\e2e\specs\gutenberg-plugin.test.js:25:6 › Gutenberg plugin › should activate [chromium] › tests\e2e\specs\install.test.js:34:6 › WordPress installation process › should install WordPress with pre-existing database credentials 23 passed (2.1m)
Its a lot nicer experience now. @westonruter appreciate the efforts.
#7
@
4 weeks ago
- Keywords fixed-major added; needs-testing removed
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for 6.8.2 consideration.
#8
@
4 weeks ago
With this change, if you previously invoked npm run env:cli
with a wp
then this must be omitted now.
However, I just realized that actually it was supposed to work without an explicit wp
, for example npm run env:cli pwd
previously would print out /var/www
and doesn't get routed to WP-CLI, whereas now this results in a WP-CLI error:
Error: 'pwd' is not a registered wp command. See 'wp help' for available commands.
See comment from @jorbin:
Since this is technically a breaking change, I searched github for
npm run env:cli wp
and there is only one reference which seems to be from a fork of a demo rather than actual production code, but it still might be worth a PR there after this lands and a quick note in the core room so folks are aware. I don't think it needs a dev note though since this isn't a public API.
So it seems in practice that this command is always used for WP-CLI. See also another GitHub search.
If we want to restore the ability to run arbitrary commands, perhaps this should be introduced as a separate command instead of overloading env:cli
. As it stands right now, the this overloading could cause ambiguity, when you expect to run a system command but actually there is a WP-CLI command registered with the same name.
This ticket was mentioned in Slack in #core by westonruter. View the logs.
4 weeks ago
#10
@
4 weeks ago
Another downside of the previous overloading logic is that it adds additional latency because it first checks whether the provided command is a valid WP-CLI command before proceeding to then actually call the command with WP-CLI.
Trac ticket: https://core.trac.wordpress.org/ticket/63564
cli
container when runningenv:start
. This greatly speeds up calls to WP-CLI since the container is already running rather than having to start up for each call. See https://github.com/WordPress/gutenberg/pull/50007.env:cli
in non-interactive context (non-TTY) to allow piping content into commands or use in shell scripts. Also see https://github.com/WordPress/gutenberg/pull/50007.env:cli
so that arguments with spaces are passed as expected.# Running
env:install
## Before
## After
# Running a single WP-CLI command
## Before
## After
# Passing an argument with spaces to WP-CLI
## Before
## After
# Passing data to WP-CLI via STDIN
## Before
## After
# Calling WP-CLI from shell script
Given a
watch.sh
script that runs PHP unit tests for thecomment
group whenever a couple of the comments PHP files are modified:## Before
## After