-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Build/Test Tools: Improve dev environment's CLI in speed, non-interactive usage, and argument handling #8969
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
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@@ -184,7 +184,7 @@ | |||
"env:clean": "node ./tools/local-env/scripts/docker.js down -v --remove-orphans", | |||
"env:reset": "node ./tools/local-env/scripts/docker.js down --rmi all -v --remove-orphans", | |||
"env:install": "node ./tools/local-env/scripts/install.js", | |||
"env:cli": "node ./tools/local-env/scripts/docker.js run --rm cli", | |||
"env:cli": "node ./tools/local-env/scripts/docker.js exec cli wp --allow-root", |
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 --allow-root
? This is done when using run
: https://github.com/WordPress/wpdev-docker-images/blob/becc6740684d6ff6414d6539df040633b5ac5794/templates/Dockerfile-cli.template#L18-L24
And the entrypoint is using sudo
: https://github.com/WordPress/wpdev-docker-images/blob/becc6740684d6ff6414d6539df040633b5ac5794/entrypoint/entrypoint-cli.sh#L16-L17
run: npm run env:cli wp option get siteurl | ||
run: npm run env:cli option get siteurl |
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.
The wp
is removed here because previously the entrypoint would inject it if it was missing: https://github.com/WordPress/wpdev-docker-images/blob/becc6740684d6ff6414d6539df040633b5ac5794/entrypoint/entrypoint-cli.sh#L16-L17
With this PR, the wp
is always assumed.
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.
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.
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.
PR opened: Antonin06/wc-bretagne-2024#1
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
// Since WP-CLI runs as root, the wp-config.php created above will be read-only. This needs to be writable for the sake of E2E tests. | ||
execSync( 'node ./tools/local-env/scripts/docker.js exec cli chmod 666 wp-config.php' ); |
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 not clear to me why this is needed now. Without it, E2E tests fail due to wp-config.php
not being writable: https://github.com/WordPress/wordpress-develop/actions/runs/15627027244/job/44023152411
In 0e4ddbb I tried using the node API to set the file permissions, but this failed because it's not being run as root: https://github.com/WordPress/wordpress-develop/actions/runs/15624512371/job/44016093197
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 in 0e4ddbb it was running on the local filesystem whereas in this implementation it is running in the container.
run: npm run env:cli wp option get siteurl | ||
run: npm run env:cli option get siteurl |
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.
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.
// Since WP-CLI runs as root, the wp-config.php created above will be read-only. This needs to be writable for the sake of E2E tests. | ||
execSync( 'node ./tools/local-env/scripts/docker.js exec cli chmod 666 wp-config.php' ); |
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 in 0e4ddbb it was running on the local filesystem whereas in this implementation it is running in the container.
@@ -111,6 +111,9 @@ services: | |||
volumes: | |||
- ./:/var/www | |||
|
|||
# Keeps the service alive. | |||
command: 'sleep infinity' |
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.
For a true idling container I would rather use
command: 'tail -f /dev/null'
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 chose this for consistency with wp-env.
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 seems there were no big explanations
WordPress/gutenberg@c11312a
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.
If Gutenberg switches back to tail
we can switch it back here too.
@@ -111,6 +111,9 @@ services: | |||
volumes: | |||
- ./:/var/www | |||
|
|||
# Keeps the service alive. | |||
command: 'sleep infinity' |
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 seems there were no big explanations
WordPress/gutenberg@c11312a
Build/Test Tools: Improve dev environment's CLI in speed, non-interactive usage, and argument handling.
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.env:cli
in non-interactive context (non-TTY) to allow piping content into commands or use in shell scripts.env:cli
so that arguments with spaces are passed as expected.This aligns the wordpress-develop environment closer to wp-env. See WordPress/gutenberg#50007.
Props westonruter, jorbin, SirLouen, sandeepdahiya.
Fixes #63564.
Trac ticket: https://core.trac.wordpress.org/ticket/63564
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
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.