From 0e04c0a62199f6b6292ab19c7b9ecfe0ede4890e Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 13 Aug 2022 23:23:26 +0000 Subject: [PATCH] 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 --- .github/workflows/phpunit-tests.yml | 8 -------- docker-compose.yml | 15 +++++++++++++++ tools/local-env/scripts/start.js | 5 ++++- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 1c2230ba19..5f4081eb6c 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 6fcbe4d1f3..c4ddb0faa1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: {} diff --git a/tools/local-env/scripts/start.js b/tools/local-env/scripts/start.js index 9f4fb849db..94180ce4b3 100644 --- a/tools/local-env/scripts/start.js +++ b/tools/local-env/scripts/start.js @@ -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 ) {