Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 7.0: Major improvements + PHP 8.1 support #14

Merged
merged 8 commits into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## v7.0.0
* **[2021-11-02 15:47:49 CDT]** PHP 8.1 RC5.
* **[2021-11-01 08:08:36 CDT]** Dramatically reduced total build time from 33 minutes to 11 minutes.
* **[2021-11-01 06:24:52 CDT]** Embedded composer into the php container.
* **[2021-11-01 06:00:30 CDT]** Run the native PHP when inside docker.
* **[2021-07-29 07:13:12 CDT]** Set the PHP memory_limit to unlimited by default.
* **[2021-07-29 07:07:35 CDT]** Fixed the building of xdebug.
* **[2021-06-21 07:10:58 CDT]** Added git and ssh for private packages supoprt.

## v6.6.0
* [2021-09-22 08:40:22 CDT] - Added the abiltiy to run commands in containers from the CLI.

Expand Down
Binary file modified bin/composer
Binary file not shown.
12 changes: 7 additions & 5 deletions bin/php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"

# Detect if it's running inside of docker and run it natively if it is.
# @see https://stackoverflow.com/a/25518345/430062
if [ "$PHP_VERSION" == "native" ] || [ -f "/.dockerenv" ]; then
(/bin/env --chdir=/ php "$@")
exit
fi

if [ -z "$PROJECT_NAME" ]; then
PROJECT_NAME=$(basename $ROOT | tr '[:upper:]' '[:lower:]' | sed "s/[^[:alpha:]-]//g")
fi
Expand All @@ -13,11 +20,6 @@ if [ -z "$PHP_VERSION" ]; then
PHP_VERSION="7"
fi

if [ "$PHP_VERSION" == "native" ]; then
(/bin/env --chdir=/ php "$@")
exit
fi

# Test if the network exists.
docker network inspect $NETWORK_NAME > /dev/null 2>&1
if [ $? == 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
"phpexperts/docker-phpstan": "Dockerized phpstan/phpstan",
"phpexperts/docker-rector": "Dockerized rector/rector"
},
"bin": ["bin/php"]
"bin": ["bin/php", "bin/composer"]
}
18 changes: 12 additions & 6 deletions docker/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@

#PHP_VERSIONS="7.4"
#PHP_VERSIONS="5.6 7.0 7.1 7.2 7.3 7.4"
#PHP_VERSIONS="5.6 7.0 7.1 7.2 7.3 7.4 8.0"
PHP_VERSIONS="7.0 7.1 7.2 7.3 7.4 8.0"
PHP_VERSIONS="5.6 7.0 7.1 7.2 7.3 7.4 8.0"
#PHP_VERSIONS="7.0 7.1 7.2 7.3 7.4 8.0"
#PHP_VERSIONS="8.0"
cd images

# Build the base linux image first.
docker build linux --tag="phpexperts/linux:latest"

for VERSION in ${PHP_VERSIONS}; do
MAJOR_VERSION=${VERSION%.*}
# @TODO: Need to add support for v8.0, too.
docker rm $(docker ps -aq)
docker rmi --force phpexperts/php:latest
docker rmi --force phpexperts/php:${MAJOR_VERSION}-debug
docker rmi --force phpexperts/php:${MAJOR_VERSION}
docker rmi --force phpexperts/php:latest 2> /dev/null
docker rmi --force phpexperts/php:${MAJOR_VERSION}-debug 2> /dev/null
docker rmi --force phpexperts/php:${MAJOR_VERSION} 2> /dev/null

docker rmi --force phpexperts/web:nginx-php${VERSION}-debug 2> /dev/null
docker rmi --force phpexperts/web:nginx-php${VERSION}-debug 2> /dev/null

docker build base --tag="phpexperts/php:latest" --build-arg PHP_VERSION=$VERSION
docker build base --tag="phpexperts/php:${MAJOR_VERSION}" --build-arg PHP_VERSION=$VERSION
Expand All @@ -27,7 +33,7 @@ for VERSION in ${PHP_VERSIONS}; do
done

# docker rmi --force phpexperts/php:8 phpexperts/php:8.0 phpexperts/web:nginx-php8
# docker build base-php8 --tag="phpexperts/php:8.0"
# docker build base-php8 --tag="phpexperts/php:8.1"
# docker build base-php8 --tag="phpexperts/php:8"

# docker build web-php8 --tag="phpexperts/web:nginx-php8"
11 changes: 5 additions & 6 deletions docker/images/base-debug/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ ARG PHP_VERSION=7.4

COPY xdebug.conf /tmp

RUN apt-get update && \
apt-get install -y php-xdebug && \

RUN apt-get install -y php${PHP_VERSION}-xdebug && \
#
# Configure XDebug
cat /tmp/xdebug.conf >> /etc/php/${PHP_VERSION}/mods-available/xdebug.ini && \
rm /tmp/xdebug.conf && \

#
# Cleanup
apt-get remove -y && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
apt-get clean
#rm -rf /var/lib/apt/lists/*
63 changes: 27 additions & 36 deletions docker/images/base-php8/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,39 @@
# phpexperts/php:7
FROM ubuntu:focal as intermediate
FROM phpexperts/linux:latest AS intermediate
#FROM phpexperts/php:8.0-temp

ARG PHP_VERSION=8.0
ARG PHP_VERSION=8.1

# Fix add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56
ENV LC_ALL C.UTF-8
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && \
# Configure ondrej PPA
apt-get install -y software-properties-common && \
apt-get upgrade -y && \
#
# Install PHP & curl (for composer)
apt-get install -y --no-install-recommends \
curl \
less vim inetutils-ping unzip net-tools && \
#
# Compile PHP 8 manuall
apt-get install -y --no-install-recommends gcc g++ make && \
# Compile PHP 8.1 manually
RUN apt-get install -y --no-install-recommends gcc g++ make && \
apt-get install -y libxml2-dev libcurl4-openssl-dev libjpeg-dev libpng-dev \
libmysqlclient-dev libpq-dev libicu-dev libfreetype6-dev \
libxslt-dev libssl-dev libldb-dev libedit-dev libsodium-dev \
zlibc zlib1g zlib1g-dev libsqlite3-dev libgmp-dev libzip-dev \
libonig-dev binutils && \
#
curl https://downloads.php.net/~carusogabriel/php-8.0.0RC3.tar.xz -o php.xz && \
curl https://downloads.php.net/~patrickallaert/php-8.1.0RC5.tar.xz -o php.xz && \
tar xvf php.xz && \
cd php-8.0.0RC3 && \
cd php-8.1.0RC5 && \
# Build CLI
./configure --enable-mbstring --with-pdo-mysql --with-pdo-pgsql --enable-mysqlnd \
--enable-gd --with-gmp --enable-bcmath --with-curl --with-zip --with-openssl \
--enable-sockets --with-libedit --with-sodium --enable-exif --enable-intl \
--enable-sockets --disable-phpdbg --with-libedit --with-sodium --enable-exif --enable-intl \
--with-mysqli --with-xsl --with-zlib --prefix=/workdir/install/usr \
--with-config-file-path=/etc/php/8.0/cli --with-config-file-scan-dir=/etc/php/8.0/cli/conf.d && \
--with-config-file-path=/etc/php/8.1/cli --with-config-file-scan-dir=/etc/php/8.1/cli/conf.d && \
make -j8 && \
make install && \
# Build FPM
./configure --enable-mbstring --with-pdo-mysql --with-pdo-pgsql --enable-mysqlnd \
--enable-gd --with-gmp --enable-bcmath --with-curl --with-zip --with-openssl \
--enable-sockets --with-libedit --with-sodium --enable-exif --enable-intl \
--enable-sockets --disable-phpdbg --with-libedit --with-sodium --enable-exif --enable-intl \
--with-mysqli --with-xsl --with-zlib \
--enable-fpm --with-fpm-user=www-data --enable-pcntl --prefix=/workdir/install/usr \
--with-config-file-path=/etc/php/8.0/fpm --with-config-file-scan-dir=/etc/php/8.0/fpm/conf.d && \
--with-config-file-path=/etc/php/8.1/fpm --with-config-file-scan-dir=/etc/php/8.1/fpm/conf.d && \
make -j8 && \
make install && \
#
Expand All @@ -52,21 +42,21 @@ RUN apt-get update && \
mkdir -p /workdir/install/etc/php/${PHP_VERSION}/cli/conf.d && \
mkdir -p /workdir/install/etc/php/${PHP_VERSION}/fpm/conf.d && \
mkdir -p /workdir/install/etc/php/${PHP_VERSION}/fpm/pool.d && \
cd /php-8.0.0RC3 && \
#cd /php-8.1.0RC5 && \
cp -v php.ini-development /workdir/install/etc/php/${PHP_VERSION}/cli/php.ini && \
cp -v php.ini-development /workdir/install/etc/php/${PHP_VERSION}/fpm/php.ini && \
cp -v ./sapi/fpm/php-fpm.conf /workdir/install/etc/php/${PHP_VERSION}/fpm/ && \
cp -v ./sapi/fpm/www.conf /workdir/install/etc/php/${PHP_VERSION}/fpm/pool.d && \
cp -v ./sapi/fpm/www.conf /workdir/install/etc/php/${PHP_VERSION}/fpm/pool.d
#
## Fix the extension_dir path (screwed up from --prefix=/workdir/install/usr):
echo extension_dir=$(/workdir/install/usr/bin/php --info | grep ^extension_dir | awk '{print $3}' | sed 's#/workdir/install##') >> /workdir/install/etc/php/${PHP_VERSION}/cli/php.ini && \
RUN echo extension_dir=$(/workdir/install/usr/bin/php --info | grep ^extension_dir | awk '{print $3}' | sed 's#/workdir/install##') >> /workdir/install/etc/php/${PHP_VERSION}/cli/php.ini && \
echo extension_dir=$(/workdir/install/usr/bin/php --info | grep ^extension_dir | awk '{print $3}' | sed 's#/workdir/install##') >> /workdir/install/etc/php/${PHP_VERSION}/fpm/php.ini && \
sed -i 's#/workdir/install##' /workdir/install/usr/bin/phpize && \
#
## Strip the PHP binaries to dramatically reduce the image size (583 MB to 156 MB).
strip /workdir/install/usr/bin/php /workdir/install/usr/sbin/php-fpm && \
## Remove the worthless php-cgi and save 64 MB.
rm /workdir/install/usr/bin/php-cgi && \
## Strip the PHP binaries to dramatically reduce the image size (583 MB to 156 MB).
strip -v /workdir/install/usr/bin/php /workdir/install/usr/sbin/php-fpm && \
#
## Install PHP so that the build programs will work.
cp -avf /workdir/install/* / && \
Expand Down Expand Up @@ -109,39 +99,40 @@ RUN apt-get update && \

WORKDIR /workdir

FROM ubuntu:focal
ENTRYPOINT ["/usr/bin/bash", "-l"]

ARG PHP_VERSION=8.0
FROM phpexperts/linux:latest

ARG PHP_VERSION=8.1

# Fix add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56
ENV LC_ALL C.UTF-8
ENV DEBIAN_FRONTEND noninteractive

COPY --from=intermediate /workdir/php-8.0-ubuntu.tar.gz /php-8.0-ubuntu.tar.gz
COPY --from=intermediate /workdir/php-8.1-ubuntu.tar.gz /php-8.1-ubuntu.tar.gz

RUN apt-get update && \
# Configure ondrej PPA
apt-get install -y software-properties-common && \
apt-get upgrade -y && \
#
# Install PHP & curl (for composer)
apt-get install -y --no-install-recommends \
curl \
less vim inetutils-ping unzip net-tools && \
# Install PHP extension dependencies
apt-get install -y libpq5 libpng16-16 libonig5 libzip5 libxslt-dev zlibc zlib1g libsodium-dev libedit-dev && \
apt-get install -y libpq5 libpng16-16 libonig5 libxslt-dev zlibc zlib1g libsodium-dev libedit-dev libcurl4 libzip4 && \
#
# Cleanup
apt-get remove -y && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
tar xvf php-8.0-ubuntu.tar.gz && \
rm -v php-8.0-ubuntu.tar.gz
# rm -rf /var/lib/apt/lists/* && \
cd / && \
tar xvf php-8.1-ubuntu.tar.gz && \
rm -v php-8.1-ubuntu.tar.gz && \
echo "Finished..."

VOLUME ["/workdir"]
WORKDIR /workdir

COPY entrypoint.sh /usr/local/bin/entrypoint-php.sh

ENTRYPOINT ["/usr/local/bin/entrypoint-php.sh"]

5 changes: 5 additions & 0 deletions docker/images/base-php8/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
if [ "$PHP_FPM_USER_ID" != "" ]; then
usermod -u $PHP_FPM_USER_ID www-data
fi
PHP_VERSION=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')

# Set php.ini options
for TYPE in cli fpm; do
PHP_INI=/etc/php/${PHP_VERSION}/${TYPE}/php.ini

if [ "$PHP_MEMORY_LIMIT" != "" ]; then
sed -i "s!memory_limit =.\+!memory_limit = $PHP_MEMORY_LIMIT!g" "$PHP_INI"
fi

# Update the PHP upload_max_filesize setting if one was specified
if [ "$PHP_UPLOAD_MAX_FILESIZE" != "" ]; then
sed -i "s!upload_max_filesize = 2M!upload_max_filesize = $PHP_UPLOAD_MAX_FILESIZE!g" "$PHP_INI"
Expand Down
41 changes: 17 additions & 24 deletions docker/images/base/Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
# phpexperts/php:7
FROM ubuntu:focal
FROM phpexperts/linux:latest

ARG PHP_VERSION=7.4

# Fix add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56
ENV LC_ALL C.UTF-8
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && \

# Configure ondrej PPA
apt-get install -y software-properties-common && \
add-apt-repository ppa:ondrej/php && \
apt-get update && \
apt-get upgrade -y && \

# Install PHP & curl (for composer)
apt-get install -y --no-install-recommends \
curl \
RUN apt-get install -y --no-install-recommends \
php${PHP_VERSION}-cli \
vim inetutils-ping unzip net-tools \
php${PHP_VERSION}-fpm && \
apt-get install -y --no-install-recommends \
php${PHP_VERSION}-fpm \
php${PHP_VERSION}-bcmath \
php${PHP_VERSION}-curl \
php${PHP_VERSION}-dom \
Expand All @@ -44,28 +32,33 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends \
php${PHP_VERSION}-sodium; \
fi && \

#
# Cleanup
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/apt/* && \

#rm -rf /var/lib/apt/lists/* && \
#rm -rf /var/cache/apt/* && \
#
# Fix "Unable to create the PID file (/run/php/php5.6-fpm.pid).: No such file or directory (2)"
mkdir -p /run/php && \

mkdir -p /run/php
#
## Configure PHP-FPM
sed -i "s!display_startup_errors = Off!display_startup_errors = On!g" /etc/php/${PHP_VERSION}/fpm/php.ini && \
RUN sed -i "s!display_startup_errors = Off!display_startup_errors = On!g" /etc/php/${PHP_VERSION}/fpm/php.ini && \
sed -i "s!memory_limit =.\+!memory_limit = -1!g" /etc/php/${PHP_VERSION}/cli/php.ini && \
sed -i "s!memory_limit =.\+!memory_limit = -1!g" /etc/php/${PHP_VERSION}/fpm/php.ini && \
sed -i "s!;error_log = php_errors.log!error_log = /proc/self/fd/2!g" /etc/php/${PHP_VERSION}/fpm/php.ini && \
sed -i "s!max_execution_time = 30!max_execution_time = 600!g" /etc/php/${PHP_VERSION}/fpm/php.ini && \
sed -i "s!session.gc_probability = 0!session.gc_probability = 1!g" /etc/php/${PHP_VERSION}/fpm/php.ini && \

#
sed -i "s!;daemonize = yes!daemonize = no!g" /etc/php/${PHP_VERSION}/fpm/php-fpm.conf && \
sed -i "s!error_log = /var/log/php${PHP_VERSION}-fpm.log!error_log = /proc/self/fd/2!g" /etc/php/${PHP_VERSION}/fpm/php-fpm.conf && \

#
sed -i "s!;catch_workers_output = yes!catch_workers_output = yes!g" /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf && \
sed -i "s!listen = /run/php/php${PHP_VERSION}-fpm.sock!listen = 0.0.0.0:9000!g" /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && composer --version

VOLUME ["/workdir"]
WORKDIR /workdir

Expand Down
10 changes: 10 additions & 0 deletions docker/images/base/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
if [ "$PHP_FPM_USER_ID" != "" ]; then
usermod -u $PHP_FPM_USER_ID www-data
fi
PHP_VERSION=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')

# Set php.ini options
for TYPE in cli fpm; do
PHP_INI=/etc/php/${PHP_VERSION}/${TYPE}/php.ini

if [ "$PHP_MEMORY_LIMIT" != "" ]; then
sed -i "s!memory_limit =.\+!memory_limit = $PHP_MEMORY_LIMIT!g" "$PHP_INI"
fi

# Update the PHP upload_max_filesize setting if one was specified
if [ "$PHP_UPLOAD_MAX_FILESIZE" != "" ]; then
sed -i "s!upload_max_filesize = 2M!upload_max_filesize = $PHP_UPLOAD_MAX_FILESIZE!g" "$PHP_INI"
Expand All @@ -20,6 +25,11 @@ for TYPE in cli fpm; do
fi
done

if [ "$RUN_COMPOSER" == "1" ]; then
/usr/local/bin/composer "$@"
exit
fi

if [ -z "$INTERACTIVE" ]; then
/usr/bin/php "$@"
else
Expand Down
31 changes: 31 additions & 0 deletions docker/images/linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM ubuntu:focal

# Fix add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56
ENV LC_ALL C.UTF-8
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && \
# Configure ondrej PPA
apt-get install -y software-properties-common && \
add-apt-repository ppa:ondrej/php && \
apt-get upgrade -y

# Fix add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56
ENV LC_ALL C.UTF-8
ENV DEBIAN_FRONTEND noninteractive

RUN echo "Building base Linux..." && \
# Configure ondrej PPA
apt-get install -y software-properties-common && \
add-apt-repository ppa:ondrej/php && \
apt-get update && \
apt-get upgrade -y && \
#
# Install PHP & curl (for composer)
apt-get install -y --no-install-recommends \
curl git ssh \
less vim inetutils-ping zip unzip net-tools

WORKDIR /workdir

ENTRYPOINT ["bash", "-l"]
Loading