diff --git a/packages/env/CHANGELOG.md b/packages/env/CHANGELOG.md index d30d34dcb9179c..96a21849baa18d 100644 --- a/packages/env/CHANGELOG.md +++ b/packages/env/CHANGELOG.md @@ -5,6 +5,7 @@ ### New Features - Add a `WP_ENV_MARIADB_VERSION` environment variable to choose the MariaDB version used by the database container ([#83751](https://github.com/WordPress/gutenberg/pull/83751)). +- Add a `WP_ENV_PHP_VERSION` environment variable to choose the PHP version used by the WordPress and WP-CLI containers. It defaults to PHP 7.4, the highest version WordPress 5.5 supports, instead of the `wordpress` and `wordpress:cli` images' default. ### Enhancements diff --git a/packages/env/README.md b/packages/env/README.md index bf44274f2064a8..b6dee81eee4bb3 100644 --- a/packages/env/README.md +++ b/packages/env/README.md @@ -300,6 +300,8 @@ _Note: the port number environment variables (`WP_ENV_PORT` and `WP_ENV_TESTS_PO _Note: the MariaDB version can be chosen with the `WP_ENV_MARIADB_VERSION` environment variable, such as `WP_ENV_MARIADB_VERSION=10.5`. It defaults to `latest`. MariaDB cannot start on a database written by a newer version. When switching to a lower version, run `wp-env destroy` first. It removes the environment's Docker containers, volumes, and networks, and its local files, not only the database, so everything is recreated on the next start. With a version older than 11.4, `wp db` commands in the `cli` and `tests-cli` containers fail, and `wp-env clean` leaves the database as it is: the MariaDB client in the `wordpress:cli` image requires TLS, and MariaDB servers before 11.4 do not offer it. `wp-env start` and WordPress itself are not affected. To start over with an empty database, run `wp-env destroy`._ +_Note: the PHP version used by the WordPress and WP-CLI containers can be chosen with the `WP_ENV_PHP_VERSION` environment variable, such as `WP_ENV_PHP_VERSION=7.3`, which uses the `wordpress:php7.3` and `wordpress:cli-php7.3` images. It defaults to `7.4`, the highest PHP version WordPress 5.5 supports. It does not change the `phpunit` service, which uses `LOCAL_PHP`._ + Several types of strings can be passed into the `core`, `plugins`, `themes`, and `mappings` fields. | Type | Format | Example(s) | diff --git a/packages/env/lib/build-docker-compose-config.js b/packages/env/lib/build-docker-compose-config.js index 52d4cc3b612569..c4a46f92421fee 100644 --- a/packages/env/lib/build-docker-compose-config.js +++ b/packages/env/lib/build-docker-compose-config.js @@ -166,7 +166,7 @@ module.exports = function buildDockerComposeConfig( config ) { condition: 'service_healthy', }, }, - image: 'wordpress', + image: 'wordpress:php${WP_ENV_PHP_VERSION:-7.4}', ports: [ developmentPorts ], environment: { WORDPRESS_DB_NAME: 'wordpress', @@ -181,7 +181,7 @@ module.exports = function buildDockerComposeConfig( config ) { condition: 'service_healthy', }, }, - image: 'wordpress', + image: 'wordpress:php${WP_ENV_PHP_VERSION:-7.4}', ports: [ testsPorts ], environment: { WORDPRESS_DB_NAME: 'tests-wordpress', @@ -193,7 +193,7 @@ module.exports = function buildDockerComposeConfig( config ) { }, cli: { depends_on: [ 'wordpress' ], - image: 'wordpress:cli', + image: 'wordpress:cli-php${WP_ENV_PHP_VERSION:-7.4}', volumes: developmentMounts, user: cliUser, environment: { @@ -203,7 +203,7 @@ module.exports = function buildDockerComposeConfig( config ) { }, 'tests-cli': { depends_on: [ 'tests-wordpress' ], - image: 'wordpress:cli', + image: 'wordpress:cli-php${WP_ENV_PHP_VERSION:-7.4}', volumes: testsMounts, user: cliUser, environment: { diff --git a/packages/env/test/build-docker-compose-config.js b/packages/env/test/build-docker-compose-config.js index 1173bc6ab5bccc..2d85ab4ee271a6 100644 --- a/packages/env/test/build-docker-compose-config.js +++ b/packages/env/test/build-docker-compose-config.js @@ -90,6 +90,21 @@ describe( 'buildDockerComposeConfig', () => { ); } ); + it( 'should let Docker Compose choose the PHP version from WP_ENV_PHP_VERSION', () => { + const { services } = buildDockerComposeConfig( CONFIG ); + + for ( const service of [ 'wordpress', 'tests-wordpress' ] ) { + expect( services[ service ].image ).toBe( + 'wordpress:php${WP_ENV_PHP_VERSION:-7.4}' + ); + } + for ( const service of [ 'cli', 'tests-cli' ] ) { + expect( services[ service ].image ).toBe( + 'wordpress:cli-php${WP_ENV_PHP_VERSION:-7.4}' + ); + } + } ); + it( 'should create a separate database for each environment', () => { const { services } = buildDockerComposeConfig( CONFIG );