Skip to content

Commit

Permalink
dev: Add ability to switch seamlessly between PHP7 and PHP8 (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitpokhrel authored Nov 7, 2020
1 parent fa24517 commit cf97f64
Showing 6 changed files with 82 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -33,6 +33,9 @@ exec-client:
exec-redis:
@docker exec -it tus-php-redis bash -c "redis-cli"

clean:
rm -rf composer.lock vendor/ coverage/ uploads/* .cache

deps:
@composer install

18 changes: 5 additions & 13 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -14,25 +14,16 @@ RUN apk update && apk add --no-cache \
make \
supervisor \
nginx \
php7-imap \
php7-intl \
php7-curl \
composer \
curl \
ca-certificates

# Install required extensions.
RUN docker-php-ext-install pcntl

# Install pecl extensions.
#
# Some dependencies like c-compiler and autoconf are only required
# to compile pecl extensions. However, these dependencies take a
# lot of space. Therefore, we will remove these dependencies
# after installing the required extensions.
RUN apk add --no-cache g++ autoconf && \
pecl upgrade apcu xdebug && \
apk del g++ autoconf
# Install extensions not available with docker-php-ext.
COPY ./bin/php-ext.sh /bin/php-ext
RUN chmod +x /bin/php-ext && php-ext

COPY ./bin/xdebug.sh /bin/xdebug
RUN chmod +x /bin/xdebug
@@ -46,7 +37,8 @@ RUN mkdir -p /var/run/php-fpm && rm -rf /usr/local/etc/php-fpm.d/*.conf
COPY ./configs/supervisord.conf /etc/supervisord.conf
COPY ./configs/nginx.conf /etc/nginx/nginx.conf
COPY ./configs/php.ini $PHP_INI_DIR/php.ini
COPY ./configs/xdebug.ini $PHP_INI_DIR/conf.d/00_xdebug.disable
COPY ./configs/xdebug.2.ini $PHP_INI_DIR/conf.d/00_xdebug2.disable
COPY ./configs/xdebug.3.ini $PHP_INI_DIR/conf.d/00_xdebug3.disable
COPY ./configs/www.conf /usr/local/etc/php-fpm.d/www.conf

ENTRYPOINT [ "sh" ]
55 changes: 55 additions & 0 deletions docker/base/bin/php-ext.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env sh

set -e

PHP_MAJOR_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d. -f1)

# Install build dependencies.
pre_build() {
apk add git g++ autoconf
}

# APCu: https://php.net/apcu
apcu() {
cd /tmp

git clone --depth 1 --branch v5.1.19 https://github.com/krakjoe/apcu && cd apcu

phpize
./configure --with-php-config=/usr/local/bin/php-config

make
make install

rm -rf /tmp/apcu
}

# Xdebug: https://xdebug.org
xdebug() {
cd /tmp

branch="2.9.8"
if [[ ${PHP_MAJOR_VERSION} == "8" ]]; then
branch="3.0.0beta1"
fi

git clone --depth 1 --branch ${branch} https://github.com/xdebug/xdebug && cd xdebug

phpize
./configure --enable-xdebug

make
make install

rm -rf /tmp/xdebug
}

# Remove build dependencies.
post_build() {
apk del git g++ autoconf
}

pre_build
apcu
xdebug
post_build
18 changes: 13 additions & 5 deletions docker/base/bin/xdebug.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
#!/bin/sh

XDEBUG_CONFIG=/etc/php7/conf.d/00_xdebug
set -e

XDEBUG_CONFIG=/usr/local/etc/php/conf.d/00_xdebug
PHP_MAJOR_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d. -f1)

config="${XDEBUG_CONFIG}2"
if [[ ${PHP_MAJOR_VERSION} == "8" ]]; then
config="${XDEBUG_CONFIG}3"
fi

enable()
{
if [[ -f ${XDEBUG_CONFIG}.disable ]]; then
mv ${XDEBUG_CONFIG}.disable ${XDEBUG_CONFIG}.ini;
if [[ -f ${config}.disable ]]; then
mv ${config}.disable ${config}.ini;
echo "Xdebug enabled";
fi
}

disable()
{
if [[ -f ${XDEBUG_CONFIG}.ini ]]; then
mv ${XDEBUG_CONFIG}.ini ${XDEBUG_CONFIG}.disable;
if [[ -f ${config}.ini ]]; then
mv ${config}.ini ${config}.disable;
echo "Xdebug disabled";
fi
}
File renamed without changes.
6 changes: 6 additions & 0 deletions docker/base/configs/xdebug.3.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
zend_extension = xdebug.so
xdebug.mode = develop,coverage
xdebug.start_with_request = yes
xdebug.client_host = host.docker.internal
xdebug.client_port = 9999
xdebug.output_dir = /var/log/xdebug

0 comments on commit cf97f64

Please sign in to comment.