Skip to content

Commit

Permalink
build(bin/stack) make WP container dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Nov 10, 2023
1 parent 6ee64dc commit 01bc278
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
20 changes: 17 additions & 3 deletions bin/stack
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 "$@"
}

Expand All @@ -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 <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ services:
user: "${USER_UID}:${USER_GID}"
sysctls:
- net.ipv4.ip_unprivileged_port_start=0
image: lucatume/wp-browser-v3-wordpress:php5.6-apache
image: lucatume/wp-browser-v3-wordpress:${WP_IMAGE_NAME:-php-apache}
build:
context: ./containers/php
dockerfile: "Dockerfile-PHP-5.6"
dockerfile: "${WP_DOCKERFILE:-Dockerfile}"
args:
PHP_VERSION: "5.6"
WP_IMAGE_VERSION: "5"
PHP_VERSION: "${WP_PHP_VERSION:-7.4}"
WP_IMAGE_VERSION: "${WP_IMAGE_VERSION:-6}"
USER_UID: "${USER_UID:-33}"
USER_GID: "${USER_GID:-33}"
USER_NAME: "${USER_NAME:-www-data}"
Expand Down

0 comments on commit 01bc278

Please sign in to comment.