Build/Test Tools: Move the Memcached container into the Docker Compose config.

This allows a developer to use the persistent Memcached object cache on their local development environment via the `LOCAL_PHP_MEMCACHED` environment variable.

Enable the memcached config via `LOCAL_PHP_MEMCACHED=true` in the `.env` file and then restart the environment with `npm run env:restart`.

Fixes #55700


git-svn-id: https://develop.svn.wordpress.org/trunk@53895 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2022-08-13 23:23:26 +00:00
parent 33368fc8c5
commit 0e04c0a621
3 changed files with 19 additions and 9 deletions

View File

@ -46,7 +46,6 @@ jobs:
# - Installs Composer dependencies.
# - Logs Docker debug information (about the Docker installation within the runner).
# - Starts the WordPress Docker container.
# - Starts the Memcached server after the Docker network has been created (if desired).
# - Logs general debug information about the runner.
# - Logs the running Docker containers.
# - Logs debug information from inside the WordPress Docker container.
@ -159,13 +158,6 @@ jobs:
run: |
npm run env:start
# The memcached server needs to start after the Docker network has been set up with `npm run env:start`.
- name: Start the Memcached server.
if: ${{ matrix.memcached }}
run: |
cp tests/phpunit/includes/object-cache.php src/wp-content/object-cache.php
docker run --name memcached --net $(basename "$PWD")_wpdevnet -d memcached
- name: General debug information
run: |
npm --version

View File

@ -49,6 +49,9 @@ services:
- ./tools/local-env/php-config.ini:/usr/local/etc/php/conf.d/php-config.ini
- ./:/var/www
# Copy or delete the Memcached dropin plugin file as appropriate.
command: /bin/sh -c "if [ $LOCAL_PHP_MEMCACHED = true ]; then cp -n /var/www/tests/phpunit/includes/object-cache.php /var/www/src/wp-content/object-cache.php; else rm -f /var/www/src/wp-content/object-cache.php; fi && exec php-fpm"
depends_on:
- mysql
@ -104,6 +107,18 @@ services:
extra_hosts:
- localhost:host-gateway
##
# The Memcached container.
##
memcached:
image: memcached
networks:
- wpdevnet
ports:
- 11211:11211
volumes:
# So that sites aren't wiped every time containers are restarted, MySQL uses a persistent volume.
mysql: {}

View File

@ -9,7 +9,10 @@ if ( process.arch === 'arm64' ) {
}
// Start the local-env containers.
execSync( 'docker-compose up -d wordpress-develop', { stdio: 'inherit' } );
const containers = ( process.env.LOCAL_PHP_MEMCACHED === 'true' )
? 'wordpress-develop memcached'
: 'wordpress-develop';
execSync( `docker-compose up -d -- ${containers}`, { stdio: 'inherit' } );
// If Docker Toolbox is being used, we need to manually forward LOCAL_PORT to the Docker VM.
if ( process.env.DOCKER_TOOLBOX_INSTALL_PATH ) {