diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f960b7..3ba89cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/bin/composer b/bin/composer index 6b44454..7d02308 100755 Binary files a/bin/composer and b/bin/composer differ diff --git a/bin/php b/bin/php index 095f467..6ead5c2 100755 --- a/bin/php +++ b/bin/php @@ -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 @@ -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 diff --git a/composer.json b/composer.json index d0c044f..f6b1c19 100644 --- a/composer.json +++ b/composer.json @@ -23,5 +23,5 @@ "phpexperts/docker-phpstan": "Dockerized phpstan/phpstan", "phpexperts/docker-rector": "Dockerized rector/rector" }, - "bin": ["bin/php"] + "bin": ["bin/php", "bin/composer"] } diff --git a/docker/build-images.sh b/docker/build-images.sh index c7b83d8..261d0ba 100755 --- a/docker/build-images.sh +++ b/docker/build-images.sh @@ -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 @@ -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" diff --git a/docker/images/base-debug/Dockerfile b/docker/images/base-debug/Dockerfile index b08f89a..b03c0f7 100644 --- a/docker/images/base-debug/Dockerfile +++ b/docker/images/base-debug/Dockerfile @@ -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/* diff --git a/docker/images/base-php8/Dockerfile b/docker/images/base-php8/Dockerfile index 818154e..60341a1 100644 --- a/docker/images/base-php8/Dockerfile +++ b/docker/images/base-php8/Dockerfile @@ -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 && \ # @@ -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/* / && \ @@ -109,15 +99,17 @@ 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 @@ -125,23 +117,22 @@ RUN apt-get update && \ 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"] + diff --git a/docker/images/base-php8/entrypoint.sh b/docker/images/base-php8/entrypoint.sh index 759c93c..10a1d55 100755 --- a/docker/images/base-php8/entrypoint.sh +++ b/docker/images/base-php8/entrypoint.sh @@ -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" diff --git a/docker/images/base/Dockerfile b/docker/images/base/Dockerfile old mode 100644 new mode 100755 index 979b0b4..48f861a --- a/docker/images/base/Dockerfile +++ b/docker/images/base/Dockerfile @@ -1,5 +1,5 @@ # phpexperts/php:7 -FROM ubuntu:focal +FROM phpexperts/linux:latest ARG PHP_VERSION=7.4 @@ -7,21 +7,9 @@ ARG PHP_VERSION=7.4 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 \ @@ -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 diff --git a/docker/images/base/entrypoint.sh b/docker/images/base/entrypoint.sh index 7164ecb..bc4026c 100755 --- a/docker/images/base/entrypoint.sh +++ b/docker/images/base/entrypoint.sh @@ -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" @@ -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 diff --git a/docker/images/linux/Dockerfile b/docker/images/linux/Dockerfile new file mode 100644 index 0000000..bbcfe03 --- /dev/null +++ b/docker/images/linux/Dockerfile @@ -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"] diff --git a/docker/images/web-debug/Dockerfile b/docker/images/web-debug/Dockerfile index 3c8f2b9..6ea5458 100644 --- a/docker/images/web-debug/Dockerfile +++ b/docker/images/web-debug/Dockerfile @@ -1,5 +1,6 @@ # phpexperts/web-debug -FROM phpexperts/php:latest-debug +ARG PHP_VERSION=7.4 +FROM phpexperts/php:${PHP_VERSION}-debug RUN apt-get update && \ apt-get install --no-install-recommends --no-install-suggests -y \ diff --git a/docker/images/web-php8/Dockerfile b/docker/images/web-php8/Dockerfile index 366251c..f604e72 100644 --- a/docker/images/web-php8/Dockerfile +++ b/docker/images/web-php8/Dockerfile @@ -1,5 +1,5 @@ # phpexperts/web -FROM phpexperts/php:8 +FROM phpexperts/php:8.1 RUN apt-get update && \ apt-get install --no-install-recommends --no-install-suggests -y \ diff --git a/docker/images/web/Dockerfile b/docker/images/web/Dockerfile index ecf59a8..01a1d5f 100644 --- a/docker/images/web/Dockerfile +++ b/docker/images/web/Dockerfile @@ -1,17 +1,18 @@ # phpexperts/web -FROM phpexperts/php:latest +ARG PHP_VERSION=7.4 +FROM phpexperts/php:${PHP_VERSION} RUN apt-get update && \ apt-get install --no-install-recommends --no-install-suggests -y \ ca-certificates \ nginx \ supervisor && \ - + # # Route nginx logs to syslog socket (will show in Docker logs) sed -i 's!/var/log/nginx/access.log!syslog:server=unix:/dev/log!g' /etc/nginx/nginx.conf && \ sed -i 's!/var/log/nginx/error.log!syslog:server=unix:/dev/log!g' /etc/nginx/nginx.conf && \ ln -s /usr/sbin/php-fpm* /usr/sbin/php-fpm && \ - + # # Cleanup apt-get remove -y && \ apt-get autoremove -y && \