From 01bc27877c7b0293a6199f39258954857588e7a1 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Fri, 10 Nov 2023 09:48:32 +0100 Subject: [PATCH] build(bin/stack) make WP container dynamic --- .github/workflows/test.yaml | 16 +++++++++++----- bin/stack | 20 +++++++++++++++++--- docker-compose.yml | 8 ++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f41a7cafd..814800015 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,6 +26,9 @@ jobs: build-args: | PHP_VERSION=5.6 WP_IMAGE_VERSION=5 + WP_IMAGE_NAME=php-5.6apache + WP_PHP_VERSION=5.6 + WP_DOCKERFILE=Dockerfile-PHP-5.6 TARGET=wordpress USER_UID=33 USER_GID=33 @@ -72,15 +75,18 @@ jobs: uses: docker/build-push-action@v4 with: context: containers/php - file: containers/php/Dockerfile-PHP-5.6 + file: containers/php/Dockerfile push: false - tags: lucatume/wp-browser-v3-wordpress:php5.6-apache + tags: lucatume/wp-browser-v3-wordpress:php-apache cache-from: type=gha,scope=5.6 cache-to: type=gha,mode=max,scope=5.6 load: true build-args: | - PHP_VERSION=5.6 - WP_IMAGE_VERSION=5 + PHP_VERSION=${{ matrix.php_version }} + WP_IMAGE_VERSION=6 + WP_IMAGE_NAME=php-apache + WP_PHP_VERSION=${{ matrix.php_version }} + WP_DOCKERFILE=Dockerfile TARGET=wordpress USER_UID=33 USER_GID=33 @@ -103,7 +109,7 @@ jobs: USER_GID=33 USER_NAME=www-data - name: Build - run: bin/stack -p5.6 build + run: bin/stack -p${{ matrix.php_version }} build - name: Cache Composer dependencies uses: actions/cache@v3 with: diff --git a/bin/stack b/bin/stack index a8d4d4f76..5f6d66a0f 100755 --- a/bin/stack +++ b/bin/stack @@ -82,6 +82,20 @@ fi TEST_DATABASES=(wordpress test_subdir test_subdomain test_empty) export PHP_VERSION=${PHP_VERSION:-8.0} + +# If the PHP_VERSION is 5.6 export WP_IMAGE_NAME=php5.6-apache, else export WP_IMAGE_NAME=php-apache. +if [ "${PHP_VERSION}" = "5.6" ]; then + export WP_IMAGE_NAME="php5.6-apache" + export WP_IMAGE_VERSION="5" + export WP_PHP_VERSION="5.6" + export WP_DOCKERFILE="Dockerfile-PHP-5.6" +else + export WP_IMAGE_NAME="php-apache" + export WP_IMAGE_VERSION="6" + export WP_PHP_VERSION="8.0" + export WP_DOCKERFILE="Dockerfile" +fi + export USER_UID=$(id -u) export USER_GID=$(id -g) export USER_NAME=$(id -un) @@ -116,7 +130,7 @@ function ensure_twentytwentyone_theme() { fi # Download and install the twentytwentyone theme. - curl -sSL https://downloads.wordpress.org/theme/twentytwentyone.2.1.zip -o "${PWD}/var/wordpress/wp-content/themes/twentytwentyone.zip" || exit 1 + curl -sSL https://downloads.wordpress.org/theme/twentytwentyone.2.0.zip -o "${PWD}/var/wordpress/wp-content/themes/twentytwentyone.zip" || exit 1 unzip -q "${PWD}/var/wordpress/wp-content/themes/twentytwentyone.zip" -d "${PWD}/var/wordpress/wp-content/themes/" || exit 1 } @@ -163,7 +177,7 @@ function run_wp_cli_command() { --network "wpbrowser_v3" \ -w /var/www/html \ -u "${USER_UID}:${USER_GID}" \ - "lucatume/wp-browser-v3-wordpress:php5.6-apache" \ + "lucatume/wp-browser-v3-wordpress:${WP_IMAGE_NAME}" \ wp --allow-root --url=http://wordpress.test --path=/var/www/html "$@" } @@ -184,7 +198,7 @@ function ensure_wordpress_configured() { --network "wpbrowser_v3" \ -w /var/www/html \ -u "${USER_UID}:${USER_GID}" \ - "lucatume/wp-browser-v3-wordpress:php5.6-apache" \ + "lucatume/wp-browser-v3-wordpress:${WP_IMAGE_NAME}" \ bash -c "wp --allow-root core config --dbname=wordpress --dbuser=root --dbpass=password --dbhost=database --dbprefix=wp_ --extra-php <