Skip to content

Commit

Permalink
build(stack,docker-compose.yml) simplify stack, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Sep 20, 2023
1 parent 710ae79 commit f86db19
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 159 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ jobs:
context: containers/php
file: containers/php/Dockerfile-PHP-5.6
push: false
tags: lucatume/wp-browser-v3-build:php5.6-apache
tags: lucatume/wp-browser-v3-wordpress:php5.6-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
Expand All @@ -35,9 +36,10 @@ jobs:
context: containers/php
file: containers/php/Dockerfile-PHP-5.6
push: false
tags: lucatume/wp-browser-v3-build:php5.6-codeception
tags: lucatume/wp-browser-v3-codecept:php5.6
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
Expand Down Expand Up @@ -70,14 +72,15 @@ jobs:
uses: docker/build-push-action@v4
with:
context: containers/php
file: containers/php/Dockerfile
file: containers/php/Dockerfile-PHP-5.6
push: false
tags: lucatume/wp-browser-v3-build:php${{ matrix.php_version }}-apache
cache-from: type=gha,scope=${{ matrix.php_version }}
cache-to: type=gha,mode=max,scope=${{ matrix.php_version }}
tags: lucatume/wp-browser-v3-wordpress:php5.6-apache
cache-from: type=gha,scope=5.6
cache-to: type=gha,mode=max,scope=5.6
load: true
build-args: |
PHP_VERSION=${{ matrix.php_version }}
WP_IMAGE_VERSION=6
PHP_VERSION=5.6
WP_IMAGE_VERSION=5
TARGET=wordpress
USER_UID=33
USER_GID=33
Expand All @@ -88,9 +91,10 @@ jobs:
context: containers/php
file: containers/php/Dockerfile
push: false
tags: lucatume/wp-browser-v3-build:php${{ matrix.php_version }}-codeception
tags: lucatume/wp-browser-v3-codecept:php${{ matrix.php_version }}
cache-from: type=gha,scope=${{ matrix.php_version }}
cache-to: type=gha,mode=max,scope=${{ matrix.php_version }}
load: true
build-args: |
PHP_VERSION=${{ matrix.php_version }}
WP_IMAGE_VERSION=6
Expand All @@ -99,7 +103,7 @@ jobs:
USER_GID=33
USER_NAME=www-data
- name: Build
run: bin/stack -p${{ matrix.php_version }} build
run: bin/stack -p5.6 build
- name: Cache Composer dependencies
uses: actions/cache@v3
with:
Expand Down
71 changes: 6 additions & 65 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
build:
bin/stack build_images
bin/stack -p5.6 build
bin/stack -p7.0 build
bin/stack -p7.1 build
bin/stack -p7.2 build
bin/stack -p7.3 build
bin/stack -p7.4 build
bin/stack -p8.0 build
bin/stack -p8.1 build
.PHONY: build

build_images:
bin/stack -p5.6 build_images
bin/stack -p7.0 build_images
bin/stack -p7.1 build_images
bin/stack -p7.2 build_images
bin/stack -p7.3 build_images
bin/stack -p7.4 build_images
bin/stack -p8.0 build_images
bin/stack -p8.1 build_images

build_56_lock_files:
[ -d config/composer ] || mkdir config/composer
rm -f config/composer/*5.6*
Expand All @@ -40,46 +24,6 @@ build_56_lock_files:

mv config/composer/composer.json.bak composer.json

build_74_lock_files:
[ -d config/composer ] || mkdir config/composer
cp composer.json config/composer/composer.json.bak

bin/stack -p7.4 -d -c2 composer_update
mv composer.json config/composer/composer-7.4-codeception-2.json
mv composer.lock config/composer/composer-7.4-codeception-2.lock
cp config/composer/composer.json.bak composer.json

bin/stack -p7.4 -d -c3 composer_update
mv composer.json config/composer/composer-7.4-codeception-3.json
mv composer.lock config/composer/composer-7.4-codeception-3.lock
cp config/composer/composer.json.bak composer.json

bin/stack -p7.4 -d -c4 composer_update
mv composer.json config/composer/composer-7.4-codeception-4.json
mv composer.lock config/composer/composer-7.4-codeception-4.lock

mv config/composer/composer.json.bak composer.json

build_80_lock_files:
[ -d config/composer ] || mkdir config/composer
cp composer.json config/composer/composer.json.bak

bin/stack -p8.0 -d -c4 composer_update
mv composer.json config/composer/composer-8.0-codeception-4.json
mv composer.lock config/composer/composer-8.0-codeception-4.lock

mv config/composer/composer.json.bak composer.json

build_81_lock_files:
[ -d config/composer ] || mkdir config/composer
cp composer.json config/composer/composer.json.bak

bin/stack -p8.1 -d -c4 composer_update
mv composer.json config/composer/composer-8.1-codeception-4.json
mv composer.lock config/composer/composer-8.1-codeception-4.lock

mv config/composer/composer.json.bak composer.json

lint:
docker run --rm \
--volume "$(PWD):$(PWD):ro" \
Expand Down Expand Up @@ -140,14 +84,11 @@ static_analysis: lint phpcs phpstan
.PHONE: static_analysis

test: static_analysis
bin/stack -p5.6 xdebug-off && bin/stack -c2 composer_update && bin/stack -p5.6 test
bin/stack -p5.6 xdebug-off && bin/stack -c3 composer_update && bin/stack -p5.6 test
bin/stack -p5.6 xdebug-off && bin/stack -c4 composer_update && bin/stack -p5.6 test
bin/stack -p7.4 xdebug-off && bin/stack -c2 composer_update && bin/stack -p7.4 test
bin/stack -p7.4 xdebug-off && bin/stack -c3 composer_update && bin/stack -p7.4 test
bin/stack -p7.4 xdebug-off && bin/stack -c4 composer_update && bin/stack -p7.4 test
bin/stack -p8.0 xdebug-off && bin/stack -c4 composer_update && bin/stack -p8.0 test
bin/stack -p8.1 xdebug-off && bin/stack -c4 composer_update && bin/stack -p8.1 test
bin/stack -p5.6 xdebug-off && bin/stack composer_update && bin/stack -p5.6 test
bin/stack -p7.4 xdebug-off && bin/stack composer_update && bin/stack -p7.4 test
bin/stack -p8.0 xdebug-off && bin/stack composer_update && bin/stack -p8.0 test
bin/stack -p8.1 xdebug-off && bin/stack composer_update && bin/stack -p8.1 test
bin/stack -p8.2 xdebug-off && bin/stack composer_update && bin/stack -p8.2 test
.PHONY: test

clean:
Expand Down
72 changes: 36 additions & 36 deletions bin/stack
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export USER_GID=$(id -g)
export USER_NAME=$(id -un)
export PWD="$(pwd)"

if [[ "${PHP_VERSION}" =~ ^(5.6|7.0|7.1|7.2|7.3)$ ]]; then
export WORDPRESS_VERSION=5
else
export WORDPRESS_VERSION=6
fi

# If the current architecture is arm64, use the arm64v8 images.
if [ "$(arch)" = "arm64" ]; then
export DOCKER_CHROME_IMAGE="seleniarm/standalone-chromium:116.0-20230828"
Expand Down Expand Up @@ -154,10 +160,10 @@ function ensure_wordpress_scaffolded() {

function run_wp_cli_command() {
docker run --rm -v "${PWD}/var/wordpress:/var/www/html" \
--network "wpbrowser_php_${PHP_VERSION}" \
--network "wpbrowser_v3" \
-w /var/www/html \
-u "${USER_UID}:${USER_GID}" \
"lucatume/wp-browser-v3-build:php${PHP_VERSION}-apache" \
"lucatume/wp-browser-v3-wordpress:php5.6-apache" \
wp --allow-root --url=http://wordpress.test --path=/var/www/html "$@"
}

Expand All @@ -175,10 +181,10 @@ function ensure_wordpress_configured() {
# If the var/wordpress/wp-config.php file is not found, configure WordPress using wp-cli.
# Configure WordPress using wp-cli.
if ! docker run --rm -v "${PWD}/var/wordpress:/var/www/html" \
--network "wpbrowser_php_${PHP_VERSION}" \
--network "wpbrowser_v3" \
-w /var/www/html \
-u "${USER_UID}:${USER_GID}" \
"lucatume/wp-browser-v3-build:php${PHP_VERSION}-apache" \
"lucatume/wp-browser-v3-wordpress:php5.6-apache" \
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 Expand Up @@ -233,27 +239,12 @@ function ensure_externals_unblocked() {
}

function build_images() {
if [ "${PHP_VERSION}" = "5.6" ]; then
export DOCKERFILE_SUFFIX="-PHP-5.6"
fi

if [[ "${PHP_VERSION}" =~ ^(5.6|7.0|7.1|7.2|7.3)$ ]]; then
export WP_IMAGE_VERSION=5
else
export WP_IMAGE_VERSION=6
fi

docker compose build --build-arg "WP_IMAGE_VERSION=${WP_IMAGE_VERSION}" --progress plain wordpress || exit 1
docker compose build --build-arg "WP_IMAGE_VERSION=${WP_IMAGE_VERSION}" --progress plain codecept || exit 1
docker compose build || exit 1
}

function build() {
[ ! -d "${PWD}/var/cache/composer" ] && mkdir -p "${PWD}/var/cache/composer"
docker compose pull --ignore-buildable || exit 1
# Skip building the images if SKIP_BUILD is 1.
if [ "${SKIP_BUILD}" = "0" ]; then
build_images
fi
docker compose up -d --force-recreate --wait database || exit 1
ensure_wordpress_scaffolded
ensure_wordpress_configured
Expand All @@ -262,7 +253,12 @@ function build() {
ensure_wordpress_updated
docker compose up -d --wait wordpress
docker compose up -d --wait chrome
docker compose up -d --wait codecept

# Up all the Codecept versions.
for version in "${SUPPORTED_PHP_VERSIONS[@]}"; do
docker compose up -d --wait codecept_${version}
done

ensure_test_databases
ensure_twentytwenty_theme
ensure_twentytwentyone_theme
Expand All @@ -271,14 +267,12 @@ function build() {
}

function clean() {
for version in "${SUPPORTED_PHP_VERSIONS[@]}"; do
PHP_VERSION=$version docker compose down -v
PHP_VERSION=$version docker compose rm -f
docker rmi "lucatume/wp-browser-v3-build:php${version}-apache"
docker rmi "lucatume/wp-browser-v3-build:php${version}-codeception"
done
docker compose down -v || true
docker compose rm -f || true
docker rmi $(docker image ls -q lucatume/wp-browser-v3-wordpress) || true
docker rmi $(docker image ls -q lucatume/wp-browser-v3-codecept) || true

rm -rf var/wordpress
rm -rf var && mkdir -p var
}

function clean_tmp() {
Expand All @@ -295,7 +289,7 @@ function composer_run() {
-w "$(pwd)" \
--no-deps \
--entrypoint=bash \
codecept -c "composer $*" || exit 1
codecept_${PHP_VERSION} -c "composer $*" || exit 1
}

function composer_update() {
Expand All @@ -316,18 +310,18 @@ function run_tests() {
echo "Running tests for suite $suite ... "
echo "=============================================================================="
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" \
codecept bash -c "php vendor/bin/codecept run $suite --ext DotReporter" || exit 1
codecept_${PHP_VERSION} bash -c "php vendor/bin/codecept run $suite --ext DotReporter" || exit 1
done
}

function xdebug_off() {
docker compose exec -u "$(id -u):$(id -g)" -w "/var/www/html" wordpress bash xdebug-off || exit 1
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept bash xdebug-off || exit 1
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept_${PHP_VERSION} bash xdebug-off || exit 1
}

function xdebug_on() {
docker compose exec -u "$(id -u):$(id -g)" -w "/var/www/html" wordpress bash xdebug-on || exit 1
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)}" codecept bash xdebug-on || exit 1
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)}" codecept_${PHP_VERSION} bash xdebug-on || exit 1
}

COMMAND=${1:-help}
Expand Down Expand Up @@ -372,6 +366,9 @@ down)
;;
exec)
service=${2:-codecept}
if [ $service = 'codecept' ]; then
service="codecept_${PHP_VERSION}"
fi
docker compose exec -u "$(id -u):$(id -g)" -it -w "$(pwd)" "$service" "${@:2}"
;;
help)
Expand All @@ -384,19 +381,22 @@ mysql)
docker compose exec database mysql -u root -ppassword
;;
phpcs)
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept bash -c "composer run cs"
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept_${PHP_VERSION} bash -c "composer run cs"
;;
phpcbf)
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept bash -c "composer run cs-fix"
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept_${PHP_VERSION} bash -c "composer run cs-fix"
;;
phpstan)
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept bash -c "composer run stan"
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept_${PHP_VERSION} bash -c "composer run stan"
;;
ps)
docker compose ps
;;
ssh)
service=${2:-codecept}
if [ $service = "codecept" ]; then
service="codecept_${PHP_VERSION}"
fi
# If ROOT is set, set the user to "0:0", else set the user to the current user.
if [ "${ROOT}" ]; then
docker_user="0:0"
Expand All @@ -407,7 +407,7 @@ ssh)
;;
run)
shift
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept php vendor/bin/codecept run $@
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept_${PHP_VERSION} php vendor/bin/codecept run $@
;;
test)
run_tests
Expand Down
38 changes: 23 additions & 15 deletions containers/php/Dockerfile-PHP-5.6
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ ARG PHP_VERSION=5.6
ARG COMPOSER_VERSION=2.2

FROM composer:${COMPOSER_VERSION} AS composer
FROM lucatume/codeception-php-5.6:cc3.1.0-v1.1.1 as php_56_sos
FROM wordpress:php${PHP_VERSION}-apache
FROM wordpress:php5.6-apache

ARG USER_UID=33
ARG USER_GID=33
ARG USER_NAME=www-data
ARG TARGET=wordpress
ARG CI

# Install wp-cli
ADD https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar /usr/local/bin/wp
Expand All @@ -20,19 +20,27 @@ RUN chmod a+x /usr/local/bin/install-php-extensions && \
chmod -R a+rwx /usr/local/etc/php/conf.d && \
install-php-extensions gd pdo pdo_mysql mysqli zip

# Build XDebug and Uopz for PHP 5.6 from source.
COPY --chmod=0777 php_56_sos/xdebug-2.5.5.tgz /tmp/xdebug-2.5.5.tgz
COPY --chmod=0777 php_56_sos/uopz-2.0.7.tar.gz /tmp/uopz-2.0.7.tar.gz
RUN tar xzf /tmp/xdebug-2.5.5.tgz -C /tmp \
&& mv /tmp/package.xml /tmp/xdebug-2.5.5/package.xml \
&& ls -la /tmp/xdebug-2.5.5 \
&& install-php-extensions /tmp/xdebug-2.5.5 \
&& rm -rf /tmp/xdebug-2.5.5.tgz /tmp/xdebug-2.5.5 \
&& tar xzf /tmp/uopz-2.0.7.tar.gz -C /tmp \
&& install-php-extensions /tmp/uopz-2.0.7 \
&& rm -rf /tmp/uopz-2.0.7.tar.gz /tmp/uopz-2.0.7 \
&& docker-php-ext-enable xdebug \
&& if [ "${TARGET}" = "codeception" ]; then docker-php-ext-enable uopz; fi
# Build XDebug from source if the CI env var is not set.
RUN if [ -z "${CI}" ]; then \
curl -k -o /tmp/xdebug.tgz "https://pecl.php.net/get/xdebug-2.5.5.tgz" && \
tar xzf /tmp/xdebug.tgz -C /tmp && \
mv /tmp/package.xml /tmp/xdebug-2.5.5 && \
rm /tmp/xdebug.tgz && \
install-php-extensions /tmp/xdebug-2.5.5 && \
rm -rf /tmp/xdebug-2.5.5 && \
docker-php-ext-enable xdebug; \
fi

# Build Uopz from source if the target is not "wordpress".
RUN if [ "${TARGET}" != "wordpress" ]; then \
curl -k -o /tmp/uopz.tgz "https://pecl.php.net/get/uopz-2.0.7.tgz" && \
tar xzf /tmp/uopz.tgz -C /tmp && \
mv /tmp/package.xml /tmp/uopz-2.0.7 && \
rm /tmp/uopz.tgz && \
install-php-extensions /tmp/uopz-2.0.7 && \
rm -rf /tmp/uopz-2.0.7 && \
docker-php-ext-enable uopz; \
fi

# Install required utils
RUN apt-get update && apt-get install -y \
Expand Down
Binary file removed containers/php/php_56_sos/uopz-2.0.7.tar.gz
Binary file not shown.
Binary file removed containers/php/php_56_sos/xdebug-2.5.5.tgz
Binary file not shown.
Loading

0 comments on commit f86db19

Please sign in to comment.