WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.5k stars 4.2k forks source link

wp-env: Auto-start `cli` service to reduce command time #49168

Closed westonruter closed 1 year ago

westonruter commented 1 year ago

What problem does this address?

Running WP-CLI commands is relatively slow due to Docker and the container not being automatically started. Consider the following:

$ time npx wp-env run cli wp post list
ℹ Starting 'wp post list' on the cli container. 

Starting aabe871bb4b92d5867707c9f76aa7c03_mysql_1 ... done
Starting aabe871bb4b92d5867707c9f76aa7c03_wordpress_1 ... done
+----+--------------+-------------+---------------------+-------------+
| ID | post_title   | post_name   | post_date           | post_status |
+----+--------------+-------------+---------------------+-------------+
| 5  | Script       | script      | 2022-11-21 18:38:24 | publish     |
| 1  | Hello world! | hello-world | 2022-11-21 18:36:23 | publish     |
+----+--------------+-------------+---------------------+-------------+
✔ Ran `wp post list` in 'cli'. (in 2s 105ms)

real    0m2.419s
user    0m0.611s
sys     0m0.147s

It takes 2½ seconds to invoke a command. Compare this with when the container is already up and running:

$ time npx wp-env run cli bash
ℹ Starting 'bash' on the cli container. Exit bash with ctrl-d.

Starting aabe871bb4b92d5867707c9f76aa7c03_mysql_1 ... done
Starting aabe871bb4b92d5867707c9f76aa7c03_wordpress_1 ... done
bash-5.1$ time wp post list
+----+--------------+-------------+---------------------+-------------+
| ID | post_title   | post_name   | post_date           | post_status |
+----+--------------+-------------+---------------------+-------------+
| 5  | Script       | script      | 2022-11-21 18:38:24 | publish     |
| 1  | Hello world! | hello-world | 2022-11-21 18:36:23 | publish     |
+----+--------------+-------------+---------------------+-------------+

real    0m0.254s
user    0m0.203s
sys     0m0.046s

Just a quarter second, almost 10x faster.

What is your proposed solution?

Since the wordpress and mariadb containers for development and tests are all started automatically, couldn't the same be done for CLI? The same goes for the phpunit container.

noahtallen commented 1 year ago

Good idea! I implemented this in #50007