From dfd8bf0773d7c14bbf0471279a81dcd8dc847b5d Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Sat, 18 Mar 2023 14:17:15 +0800 Subject: [PATCH 1/7] 8.2-bullseye --- Dockerfile => 8.2/bullseye/Dockerfile | 0 {root => 8.2/bullseye/root}/tmp/setup/oci8-extension.sh | 0 {root => 8.2/bullseye/root}/tmp/setup/php-extensions.sh | 0 {root => 8.2/bullseye/root}/tmp/setup/sqlsrv-extension.sh | 0 .../bullseye/root}/usr/local/bin/moodle-docker-php-entrypoint | 0 .../bullseye/root}/usr/local/etc/php/conf.d/docker-php-moodle.ini | 0 {tests => 8.2/bullseye/tests}/docker-entrypoint.d/20-example.ini | 0 {tests => 8.2/bullseye/tests}/docker-entrypoint.d/30-sourced.sh | 0 {tests => 8.2/bullseye/tests}/docker-entrypoint.d/40-exec.sh | 0 .../bullseye/tests}/fixtures/check-entrypoint-scripts.php | 0 {tests => 8.2/bullseye/tests}/fixtures/check-ini.php | 0 {tests => 8.2/bullseye/tests}/fixtures/test.php | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename Dockerfile => 8.2/bullseye/Dockerfile (100%) rename {root => 8.2/bullseye/root}/tmp/setup/oci8-extension.sh (100%) rename {root => 8.2/bullseye/root}/tmp/setup/php-extensions.sh (100%) rename {root => 8.2/bullseye/root}/tmp/setup/sqlsrv-extension.sh (100%) rename {root => 8.2/bullseye/root}/usr/local/bin/moodle-docker-php-entrypoint (100%) rename {root => 8.2/bullseye/root}/usr/local/etc/php/conf.d/docker-php-moodle.ini (100%) rename {tests => 8.2/bullseye/tests}/docker-entrypoint.d/20-example.ini (100%) rename {tests => 8.2/bullseye/tests}/docker-entrypoint.d/30-sourced.sh (100%) rename {tests => 8.2/bullseye/tests}/docker-entrypoint.d/40-exec.sh (100%) rename {tests => 8.2/bullseye/tests}/fixtures/check-entrypoint-scripts.php (100%) rename {tests => 8.2/bullseye/tests}/fixtures/check-ini.php (100%) rename {tests => 8.2/bullseye/tests}/fixtures/test.php (100%) diff --git a/Dockerfile b/8.2/bullseye/Dockerfile similarity index 100% rename from Dockerfile rename to 8.2/bullseye/Dockerfile diff --git a/root/tmp/setup/oci8-extension.sh b/8.2/bullseye/root/tmp/setup/oci8-extension.sh similarity index 100% rename from root/tmp/setup/oci8-extension.sh rename to 8.2/bullseye/root/tmp/setup/oci8-extension.sh diff --git a/root/tmp/setup/php-extensions.sh b/8.2/bullseye/root/tmp/setup/php-extensions.sh similarity index 100% rename from root/tmp/setup/php-extensions.sh rename to 8.2/bullseye/root/tmp/setup/php-extensions.sh diff --git a/root/tmp/setup/sqlsrv-extension.sh b/8.2/bullseye/root/tmp/setup/sqlsrv-extension.sh similarity index 100% rename from root/tmp/setup/sqlsrv-extension.sh rename to 8.2/bullseye/root/tmp/setup/sqlsrv-extension.sh diff --git a/root/usr/local/bin/moodle-docker-php-entrypoint b/8.2/bullseye/root/usr/local/bin/moodle-docker-php-entrypoint similarity index 100% rename from root/usr/local/bin/moodle-docker-php-entrypoint rename to 8.2/bullseye/root/usr/local/bin/moodle-docker-php-entrypoint diff --git a/root/usr/local/etc/php/conf.d/docker-php-moodle.ini b/8.2/bullseye/root/usr/local/etc/php/conf.d/docker-php-moodle.ini similarity index 100% rename from root/usr/local/etc/php/conf.d/docker-php-moodle.ini rename to 8.2/bullseye/root/usr/local/etc/php/conf.d/docker-php-moodle.ini diff --git a/tests/docker-entrypoint.d/20-example.ini b/8.2/bullseye/tests/docker-entrypoint.d/20-example.ini similarity index 100% rename from tests/docker-entrypoint.d/20-example.ini rename to 8.2/bullseye/tests/docker-entrypoint.d/20-example.ini diff --git a/tests/docker-entrypoint.d/30-sourced.sh b/8.2/bullseye/tests/docker-entrypoint.d/30-sourced.sh similarity index 100% rename from tests/docker-entrypoint.d/30-sourced.sh rename to 8.2/bullseye/tests/docker-entrypoint.d/30-sourced.sh diff --git a/tests/docker-entrypoint.d/40-exec.sh b/8.2/bullseye/tests/docker-entrypoint.d/40-exec.sh similarity index 100% rename from tests/docker-entrypoint.d/40-exec.sh rename to 8.2/bullseye/tests/docker-entrypoint.d/40-exec.sh diff --git a/tests/fixtures/check-entrypoint-scripts.php b/8.2/bullseye/tests/fixtures/check-entrypoint-scripts.php similarity index 100% rename from tests/fixtures/check-entrypoint-scripts.php rename to 8.2/bullseye/tests/fixtures/check-entrypoint-scripts.php diff --git a/tests/fixtures/check-ini.php b/8.2/bullseye/tests/fixtures/check-ini.php similarity index 100% rename from tests/fixtures/check-ini.php rename to 8.2/bullseye/tests/fixtures/check-ini.php diff --git a/tests/fixtures/test.php b/8.2/bullseye/tests/fixtures/test.php similarity index 100% rename from tests/fixtures/test.php rename to 8.2/bullseye/tests/fixtures/test.php From eff3d764afa9223483ddf4aaf320044749876ca9 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Sat, 18 Mar 2023 14:18:26 +0800 Subject: [PATCH 2/7] 8.2-buster --- 8.2/buster/Dockerfile | 52 ++++++++++++ 8.2/buster/root/tmp/setup/oci8-extension.sh | 30 +++++++ 8.2/buster/root/tmp/setup/php-extensions.sh | 82 +++++++++++++++++++ 8.2/buster/root/tmp/setup/sqlsrv-extension.sh | 47 +++++++++++ .../local/bin/moodle-docker-php-entrypoint | 36 ++++++++ .../etc/php/conf.d/docker-php-moodle.ini | 6 ++ .../tests/docker-entrypoint.d/20-example.ini | 2 + .../tests/docker-entrypoint.d/30-sourced.sh | 10 +++ .../tests/docker-entrypoint.d/40-exec.sh | 10 +++ .../fixtures/check-entrypoint-scripts.php | 27 ++++++ 8.2/buster/tests/fixtures/check-ini.php | 20 +++++ 8.2/buster/tests/fixtures/test.php | 53 ++++++++++++ 12 files changed, 375 insertions(+) create mode 100644 8.2/buster/Dockerfile create mode 100755 8.2/buster/root/tmp/setup/oci8-extension.sh create mode 100755 8.2/buster/root/tmp/setup/php-extensions.sh create mode 100755 8.2/buster/root/tmp/setup/sqlsrv-extension.sh create mode 100755 8.2/buster/root/usr/local/bin/moodle-docker-php-entrypoint create mode 100644 8.2/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini create mode 100644 8.2/buster/tests/docker-entrypoint.d/20-example.ini create mode 100644 8.2/buster/tests/docker-entrypoint.d/30-sourced.sh create mode 100755 8.2/buster/tests/docker-entrypoint.d/40-exec.sh create mode 100644 8.2/buster/tests/fixtures/check-entrypoint-scripts.php create mode 100644 8.2/buster/tests/fixtures/check-ini.php create mode 100644 8.2/buster/tests/fixtures/test.php diff --git a/8.2/buster/Dockerfile b/8.2/buster/Dockerfile new file mode 100644 index 0000000..0a3e973 --- /dev/null +++ b/8.2/buster/Dockerfile @@ -0,0 +1,52 @@ +FROM php:8.2-apache-buster + +# So we can use it anywhere for conditional stuff. Keeping BC with old (non-buildkit, builders) +ARG TARGETPLATFORM +ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} +RUN echo "Building for ${TARGETPLATFORM}" + +# Install some packages that are useful within the images. +RUN apt-get update && apt-get install -y \ + git \ +&& rm -rf /var/lib/apt/lists/* + +# Install pickle as an easier alternative to PECL, that is not +# available any more for PHP 8 and up. Some alternatives searched were: +# - https://olvlvl.com/2019-06-docker-pecl-without-pecl +# - https://github.com/FriendsOfPHP/pickle +# - manually "curl https://pecl.php.net/get/xxxx && tar && docker-php-ext-install xxx" +# Of course, if the images end using some alternative, we'll switch to it. Just right now +# there isn't such an alternative.a +# +# Update 20201126: Finally, see https://github.com/docker-library/php/issues/1087 it seems that pear/pecl +# continues being availbale with php8, so we are going to continue using it. The previous comments as +# left in case we need to find an alternative way to install PECL stuff and there isn't any official. +# For an example of php80-rc5 near complete, using pickle instead of pear/pecl, look to: +# https://github.com/stronk7/moodle-php-apache/tree/8.0-buster-pickle-version + +# Setup the required extensions. +ARG DEBIAN_FRONTEND=noninteractive +ADD root/tmp/setup/php-extensions.sh /tmp/setup/php-extensions.sh +RUN /tmp/setup/php-extensions.sh + +# Install Oracle Instantclient +ADD root/tmp/setup/oci8-extension.sh /tmp/setup/oci8-extension.sh +RUN /tmp/setup/oci8-extension.sh +ENV LD_LIBRARY_PATH /usr/local/instantclient + +# Install Microsoft sqlsrv. +ADD root/tmp/setup/sqlsrv-extension.sh /tmp/setup/sqlsrv-extension.sh +RUN /tmp/setup/sqlsrv-extension.sh + +RUN mkdir /var/www/moodledata && chown www-data /var/www/moodledata && \ + mkdir /var/www/phpunitdata && chown www-data /var/www/phpunitdata && \ + mkdir /var/www/behatdata && chown www-data /var/www/behatdata && \ + mkdir /var/www/behatfaildumps && chown www-data /var/www/behatfaildumps + +ADD root/usr /usr + +# Fix the original permissions of /tmp, the PHP default upload tmp dir. +RUN chmod 777 /tmp && chmod +t /tmp + +CMD ["apache2-foreground"] +ENTRYPOINT ["moodle-docker-php-entrypoint"] diff --git a/8.2/buster/root/tmp/setup/oci8-extension.sh b/8.2/buster/root/tmp/setup/oci8-extension.sh new file mode 100755 index 0000000..72d4ecc --- /dev/null +++ b/8.2/buster/root/tmp/setup/oci8-extension.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -e + +if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then + echo "oracle extension not available for ${TARGETPLATFORM} architecture, skipping" + exit 0 +fi + +echo "Downloading oracle files" +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip + +unzip /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip +unzip /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip +unzip /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip + +ln -s /usr/local/instantclient_21_6 /usr/local/instantclient +ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus + +echo 'instantclient,/usr/local/instantclient' | pecl install oci8 +docker-php-ext-enable oci8 +echo 'oci8.statement_cache_size = 0' >> /usr/local/etc/php/conf.d/docker-php-ext-oci8.ini diff --git a/8.2/buster/root/tmp/setup/php-extensions.sh b/8.2/buster/root/tmp/setup/php-extensions.sh new file mode 100755 index 0000000..eb4b70e --- /dev/null +++ b/8.2/buster/root/tmp/setup/php-extensions.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +set -e + +echo "Installing apt dependencies" + +# Build packages will be added during the build, but will be removed at the end. +BUILD_PACKAGES="gettext libcurl4-openssl-dev libfreetype6-dev libicu-dev libjpeg62-turbo-dev \ + libldap2-dev libmariadbclient-dev libmemcached-dev libpng-dev libpq-dev libxml2-dev libxslt-dev \ + uuid-dev" + +# Packages for Postgres. +PACKAGES_POSTGRES="libpq5" + +# Packages for MariaDB and MySQL. +PACKAGES_MYMARIA="libmariadb3" + +# Packages for other Moodle runtime dependenices. +PACKAGES_RUNTIME="ghostscript libaio1 libcurl4 libgss3 libicu63 libmcrypt-dev libxml2 libxslt1.1 \ + libzip-dev locales sassc unzip zip" + +# Packages for Memcached. +PACKAGES_MEMCACHED="libmemcached11 libmemcachedutil2" + +# Packages for LDAP. +PACKAGES_LDAP="libldap-2.4-2" + +apt-get update +apt-get install -y --no-install-recommends apt-transport-https \ + $BUILD_PACKAGES \ + $PACKAGES_POSTGRES \ + $PACKAGES_MYMARIA \ + $PACKAGES_RUNTIME \ + $PACKAGES_MEMCACHED \ + $PACKAGES_LDAP + +# Generate the locales configuration fo rboth Australia, and the US. +echo 'Generating locales..' +echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen +echo 'en_AU.UTF-8 UTF-8' >> /etc/locale.gen +locale-gen + +echo "Installing php extensions" + +# ZIP +docker-php-ext-configure zip --with-zip +docker-php-ext-install zip + +docker-php-ext-install -j$(nproc) \ + exif \ + intl \ + mysqli \ + opcache \ + pgsql \ + soap \ + xsl + +# GD. +docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ +docker-php-ext-install -j$(nproc) gd + +# LDAP. +docker-php-ext-configure ldap +docker-php-ext-install -j$(nproc) ldap + +# APCu, igbinary, Memcached, PCov, Redis, Solr, timezonedb, uuid, XMLRPC (beta) +pecl install apcu igbinary memcached pcov redis solr timezonedb uuid xmlrpc-beta +docker-php-ext-enable apcu igbinary memcached pcov redis solr timezonedb uuid xmlrpc + +echo 'apc.enable_cli = On' >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini + +echo "pcov.enabled=0" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.exclude='~\/(tests|coverage|vendor|node_modules)\/~'" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.directory=." >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.initial.files=1024" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini + +# Keep our image size down.. +pecl clear-cache +apt-get remove --purge -y $BUILD_PACKAGES +apt-get autoremove -y +apt-get clean +rm -rf /var/lib/apt/lists/* diff --git a/8.2/buster/root/tmp/setup/sqlsrv-extension.sh b/8.2/buster/root/tmp/setup/sqlsrv-extension.sh new file mode 100755 index 0000000..060de2c --- /dev/null +++ b/8.2/buster/root/tmp/setup/sqlsrv-extension.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +set -e + +# Debian buster (10) haven't got the arm64 packages, it seems, see: +# - buster: https://packages.microsoft.com/debian/10/prod/pool/main/m/msodbcsql18/ +# So we won't build the extension for buster (10) images on arm64. +if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then + echo "sqlsrv extension not available for ${TARGETPLATFORM} architecture, skipping" + exit 0 +fi + +# Packages for build. +BUILD_PACKAGES="gnupg unixodbc-dev" + +# Packages for sqlsrv runtime. +PACKAGES_SQLSRV="unixodbc" + +# Note: These dependencies must be installed before installing the Microsoft source because there is a package in there +# which breaks the install. +echo "Installing apt dependencies" +apt-get update +apt-get install -y --no-install-recommends apt-transport-https \ + $BUILD_PACKAGES \ + $PACKAGES_SQLSRV + +# Install Microsoft dependencies for sqlsrv +echo "Downloading sqlsrv files" +curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - +curl https://packages.microsoft.com/config/debian/10/prod.list -o /etc/apt/sources.list.d/mssql-release.list +apt-get update + +echo "Install msodbcsql" +ACCEPT_EULA=Y apt-get install -y msodbcsql18 + +ln -fsv /opt/mssql-tools/bin/* /usr/bin + +# Need 5.11.0 (or later) for PHP 8.2 support +pecl install sqlsrv-5.11.0 +docker-php-ext-enable sqlsrv + +# Keep our image size down.. +pecl clear-cache +apt-get remove --purge -y $BUILD_PACKAGES +apt-get autoremove -y +apt-get clean +rm -rf /var/lib/apt/lists/* diff --git a/8.2/buster/root/usr/local/bin/moodle-docker-php-entrypoint b/8.2/buster/root/usr/local/bin/moodle-docker-php-entrypoint new file mode 100755 index 0000000..3abc465 --- /dev/null +++ b/8.2/buster/root/usr/local/bin/moodle-docker-php-entrypoint @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -Eeo pipefail + +docker_process_init_files() { + local f + for f; do + case "$f" in + *.sh) + # Note: This hack is required for MacOS because the exeute bit is not checked for bind mounts. + # The executable bit is stored, but the test -x flag does not return corretly. + # Copying the file to an alternate file system allows it to be respected. + rm -f /tmp/testscript + cp "$f" /tmp/testscript + if [ -x "/tmp/testscript" ]; then + echo "$0: running $f" + "$f" + else + echo "$0: sourcing $f" + . "$f" + fi + ;; + *.ini) + echo "$0: copying $f into /usr/local/etc/php/conf.d/" + cp "$f" /usr/local/etc/php/conf.d/ + ;; + esac + done +} + +echo "Running entrypoint files from /docker-entrypoint.d/*" +docker_process_init_files /docker-entrypoint.d/* +echo + +echo "Starting docker-php-entrypoint with $@" +source /usr/local/bin/docker-php-entrypoint +echo diff --git a/8.2/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini b/8.2/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini new file mode 100644 index 0000000..c5675bf --- /dev/null +++ b/8.2/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini @@ -0,0 +1,6 @@ +; CONFIGURATION SETTINGS REQUIRED BY MOODLE + +; How many GET/POST/COOKIE input variables may be accepted +; See MDL-71390 for more info. This is the recommended / required +; value to support sites having 1000 courses, activities, users.... +max_input_vars = 5000 diff --git a/8.2/buster/tests/docker-entrypoint.d/20-example.ini b/8.2/buster/tests/docker-entrypoint.d/20-example.ini new file mode 100644 index 0000000..ec45086 --- /dev/null +++ b/8.2/buster/tests/docker-entrypoint.d/20-example.ini @@ -0,0 +1,2 @@ +; Test file which disable file uploads. +file_uploads = Off diff --git a/8.2/buster/tests/docker-entrypoint.d/30-sourced.sh b/8.2/buster/tests/docker-entrypoint.d/30-sourced.sh new file mode 100644 index 0000000..86a6286 --- /dev/null +++ b/8.2/buster/tests/docker-entrypoint.d/30-sourced.sh @@ -0,0 +1,10 @@ +# This file should not have a shbang! as it is expected to be sourced. +# It should not be executable either. + +mkdir -p /var/www/data + +(return 0 2>/dev/null) && sourced=1 || sourced=0 + +if [[ $sourced -eq 1 ]]; then + echo "Sourced" >> /var/www/data/sourced.txt +fi diff --git a/8.2/buster/tests/docker-entrypoint.d/40-exec.sh b/8.2/buster/tests/docker-entrypoint.d/40-exec.sh new file mode 100755 index 0000000..d924fc6 --- /dev/null +++ b/8.2/buster/tests/docker-entrypoint.d/40-exec.sh @@ -0,0 +1,10 @@ +# This file should not have a shbang! as it is expected to be sourced. +# It should not be executable either. + +mkdir -p /var/www/data + +(return 0 2>/dev/null) && sourced=1 || sourced=0 + +if [[ $sourced -eq 0 ]]; then + echo "Executed" >> /var/www/data/executed.txt +fi diff --git a/8.2/buster/tests/fixtures/check-entrypoint-scripts.php b/8.2/buster/tests/fixtures/check-entrypoint-scripts.php new file mode 100644 index 0000000..aa06d16 --- /dev/null +++ b/8.2/buster/tests/fixtures/check-entrypoint-scripts.php @@ -0,0 +1,27 @@ + Date: Sat, 18 Mar 2023 14:18:57 +0800 Subject: [PATCH 3/7] 8.1-bullseye --- 8.1/bullseye/Dockerfile | 52 ++++++++++++ 8.1/bullseye/root/tmp/setup/oci8-extension.sh | 30 +++++++ 8.1/bullseye/root/tmp/setup/php-extensions.sh | 82 +++++++++++++++++++ .../root/tmp/setup/sqlsrv-extension.sh | 45 ++++++++++ .../local/bin/moodle-docker-php-entrypoint | 36 ++++++++ .../etc/php/conf.d/docker-php-moodle.ini | 6 ++ .../tests/docker-entrypoint.d/20-example.ini | 2 + .../tests/docker-entrypoint.d/30-sourced.sh | 10 +++ .../tests/docker-entrypoint.d/40-exec.sh | 10 +++ .../fixtures/check-entrypoint-scripts.php | 27 ++++++ 8.1/bullseye/tests/fixtures/check-ini.php | 20 +++++ 8.1/bullseye/tests/fixtures/test.php | 54 ++++++++++++ 12 files changed, 374 insertions(+) create mode 100644 8.1/bullseye/Dockerfile create mode 100755 8.1/bullseye/root/tmp/setup/oci8-extension.sh create mode 100755 8.1/bullseye/root/tmp/setup/php-extensions.sh create mode 100755 8.1/bullseye/root/tmp/setup/sqlsrv-extension.sh create mode 100755 8.1/bullseye/root/usr/local/bin/moodle-docker-php-entrypoint create mode 100644 8.1/bullseye/root/usr/local/etc/php/conf.d/docker-php-moodle.ini create mode 100644 8.1/bullseye/tests/docker-entrypoint.d/20-example.ini create mode 100644 8.1/bullseye/tests/docker-entrypoint.d/30-sourced.sh create mode 100755 8.1/bullseye/tests/docker-entrypoint.d/40-exec.sh create mode 100644 8.1/bullseye/tests/fixtures/check-entrypoint-scripts.php create mode 100644 8.1/bullseye/tests/fixtures/check-ini.php create mode 100644 8.1/bullseye/tests/fixtures/test.php diff --git a/8.1/bullseye/Dockerfile b/8.1/bullseye/Dockerfile new file mode 100644 index 0000000..a00d02f --- /dev/null +++ b/8.1/bullseye/Dockerfile @@ -0,0 +1,52 @@ +FROM php:8.1-apache-bullseye + +# So we can use it anywhere for conditional stuff. Keeping BC with old (non-buildkit, builders) +ARG TARGETPLATFORM +ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} +RUN echo "Building for ${TARGETPLATFORM}" + +# Install some packages that are useful within the images. +RUN apt-get update && apt-get install -y \ + git \ +&& rm -rf /var/lib/apt/lists/* + +# Install pickle as an easier alternative to PECL, that is not +# available any more for PHP 8 and up. Some alternatives searched were: +# - https://olvlvl.com/2019-06-docker-pecl-without-pecl +# - https://github.com/FriendsOfPHP/pickle +# - manually "curl https://pecl.php.net/get/xxxx && tar && docker-php-ext-install xxx" +# Of course, if the images end using some alternative, we'll switch to it. Just right now +# there isn't such an alternative.a +# +# Update 20201126: Finally, see https://github.com/docker-library/php/issues/1087 it seems that pear/pecl +# continues being availbale with php8, so we are going to continue using it. The previous comments as +# left in case we need to find an alternative way to install PECL stuff and there isn't any official. +# For an example of php80-rc5 near complete, using pickle instead of pear/pecl, look to: +# https://github.com/stronk7/moodle-php-apache/tree/8.0-buster-pickle-version + +# Setup the required extensions. +ARG DEBIAN_FRONTEND=noninteractive +ADD root/tmp/setup/php-extensions.sh /tmp/setup/php-extensions.sh +RUN /tmp/setup/php-extensions.sh + +# Install Oracle Instantclient +ADD root/tmp/setup/oci8-extension.sh /tmp/setup/oci8-extension.sh +RUN /tmp/setup/oci8-extension.sh +ENV LD_LIBRARY_PATH /usr/local/instantclient + +# Install Microsoft sqlsrv. +ADD root/tmp/setup/sqlsrv-extension.sh /tmp/setup/sqlsrv-extension.sh +RUN /tmp/setup/sqlsrv-extension.sh + +RUN mkdir /var/www/moodledata && chown www-data /var/www/moodledata && \ + mkdir /var/www/phpunitdata && chown www-data /var/www/phpunitdata && \ + mkdir /var/www/behatdata && chown www-data /var/www/behatdata && \ + mkdir /var/www/behatfaildumps && chown www-data /var/www/behatfaildumps + +ADD root/usr /usr + +# Fix the original permissions of /tmp, the PHP default upload tmp dir. +RUN chmod 777 /tmp && chmod +t /tmp + +CMD ["apache2-foreground"] +ENTRYPOINT ["moodle-docker-php-entrypoint"] diff --git a/8.1/bullseye/root/tmp/setup/oci8-extension.sh b/8.1/bullseye/root/tmp/setup/oci8-extension.sh new file mode 100755 index 0000000..72d4ecc --- /dev/null +++ b/8.1/bullseye/root/tmp/setup/oci8-extension.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -e + +if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then + echo "oracle extension not available for ${TARGETPLATFORM} architecture, skipping" + exit 0 +fi + +echo "Downloading oracle files" +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip + +unzip /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip +unzip /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip +unzip /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip + +ln -s /usr/local/instantclient_21_6 /usr/local/instantclient +ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus + +echo 'instantclient,/usr/local/instantclient' | pecl install oci8 +docker-php-ext-enable oci8 +echo 'oci8.statement_cache_size = 0' >> /usr/local/etc/php/conf.d/docker-php-ext-oci8.ini diff --git a/8.1/bullseye/root/tmp/setup/php-extensions.sh b/8.1/bullseye/root/tmp/setup/php-extensions.sh new file mode 100755 index 0000000..38c9ff1 --- /dev/null +++ b/8.1/bullseye/root/tmp/setup/php-extensions.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +set -e + +echo "Installing apt dependencies" + +# Build packages will be added during the build, but will be removed at the end. +BUILD_PACKAGES="gettext libcurl4-openssl-dev libfreetype6-dev libicu-dev libjpeg62-turbo-dev \ + libldap2-dev libmariadb-dev libmemcached-dev libpng-dev libpq-dev libxml2-dev libxslt-dev \ + uuid-dev" + +# Packages for Postgres. +PACKAGES_POSTGRES="libpq5" + +# Packages for MariaDB and MySQL. +PACKAGES_MYMARIA="libmariadb3" + +# Packages for other Moodle runtime dependenices. +PACKAGES_RUNTIME="ghostscript libaio1 libcurl4 libgss3 libicu67 libmcrypt-dev libxml2 libxslt1.1 \ + libzip-dev locales sassc unzip zip" + +# Packages for Memcached. +PACKAGES_MEMCACHED="libmemcached11 libmemcachedutil2" + +# Packages for LDAP. +PACKAGES_LDAP="libldap-2.4-2" + +apt-get update +apt-get install -y --no-install-recommends apt-transport-https \ + $BUILD_PACKAGES \ + $PACKAGES_POSTGRES \ + $PACKAGES_MYMARIA \ + $PACKAGES_RUNTIME \ + $PACKAGES_MEMCACHED \ + $PACKAGES_LDAP + +# Generate the locales configuration fo rboth Australia, and the US. +echo 'Generating locales..' +echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen +echo 'en_AU.UTF-8 UTF-8' >> /etc/locale.gen +locale-gen + +echo "Installing php extensions" + +# ZIP +docker-php-ext-configure zip --with-zip +docker-php-ext-install zip + +docker-php-ext-install -j$(nproc) \ + exif \ + intl \ + mysqli \ + opcache \ + pgsql \ + soap \ + xsl + +# GD. +docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ +docker-php-ext-install -j$(nproc) gd + +# LDAP. +docker-php-ext-configure ldap +docker-php-ext-install -j$(nproc) ldap + +# APCu, igbinary, Memcached, MongoDB, PCov, Redis, Solr, timezonedb, uuid, XMLRPC (beta) +pecl install apcu igbinary memcached mongodb pcov redis solr timezonedb uuid xmlrpc-beta +docker-php-ext-enable apcu igbinary memcached mongodb pcov redis solr timezonedb uuid xmlrpc + +echo 'apc.enable_cli = On' >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini + +echo "pcov.enabled=0" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.exclude='~\/(tests|coverage|vendor|node_modules)\/~'" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.directory=." >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.initial.files=1024" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini + +# Keep our image size down.. +pecl clear-cache +apt-get remove --purge -y $BUILD_PACKAGES +apt-get autoremove -y +apt-get clean +rm -rf /var/lib/apt/lists/* diff --git a/8.1/bullseye/root/tmp/setup/sqlsrv-extension.sh b/8.1/bullseye/root/tmp/setup/sqlsrv-extension.sh new file mode 100755 index 0000000..94a8870 --- /dev/null +++ b/8.1/bullseye/root/tmp/setup/sqlsrv-extension.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +set -e + +if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then + echo "sqlsrv extension not available for ${TARGETPLATFORM} architecture, skipping" + exit 0 +fi + +# Packages for build. +BUILD_PACKAGES="gnupg unixodbc-dev" + +# Packages for sqlsrv runtime. +PACKAGES_SQLSRV="unixodbc" + +# Note: These dependencies must be installed before installing the Microsoft source because there is a package in there +# which breaks the install. +echo "Installing apt dependencies" +apt-get update +apt-get install -y --no-install-recommends apt-transport-https \ + $BUILD_PACKAGES \ + $PACKAGES_SQLSRV + +# Install Microsoft dependencies for sqlsrv +echo "Downloading sqlsrv files" +curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - +# TODO, bullseye should be 11, but the msodbcsql17 package is not available yet, hence using buster (10) one. +curl https://packages.microsoft.com/config/debian/10/prod.list -o /etc/apt/sources.list.d/mssql-release.list +apt-get update + +echo "Install msodbcsql" +ACCEPT_EULA=Y apt-get install -y msodbcsql17 + +ln -fsv /opt/mssql-tools/bin/* /usr/bin + +# Need 5..10.0beta1 (or later) for PHP 8.1 support +pecl install sqlsrv-5.10.0 +docker-php-ext-enable sqlsrv + +# Keep our image size down.. +pecl clear-cache +apt-get remove --purge -y $BUILD_PACKAGES +apt-get autoremove -y +apt-get clean +rm -rf /var/lib/apt/lists/* diff --git a/8.1/bullseye/root/usr/local/bin/moodle-docker-php-entrypoint b/8.1/bullseye/root/usr/local/bin/moodle-docker-php-entrypoint new file mode 100755 index 0000000..3abc465 --- /dev/null +++ b/8.1/bullseye/root/usr/local/bin/moodle-docker-php-entrypoint @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -Eeo pipefail + +docker_process_init_files() { + local f + for f; do + case "$f" in + *.sh) + # Note: This hack is required for MacOS because the exeute bit is not checked for bind mounts. + # The executable bit is stored, but the test -x flag does not return corretly. + # Copying the file to an alternate file system allows it to be respected. + rm -f /tmp/testscript + cp "$f" /tmp/testscript + if [ -x "/tmp/testscript" ]; then + echo "$0: running $f" + "$f" + else + echo "$0: sourcing $f" + . "$f" + fi + ;; + *.ini) + echo "$0: copying $f into /usr/local/etc/php/conf.d/" + cp "$f" /usr/local/etc/php/conf.d/ + ;; + esac + done +} + +echo "Running entrypoint files from /docker-entrypoint.d/*" +docker_process_init_files /docker-entrypoint.d/* +echo + +echo "Starting docker-php-entrypoint with $@" +source /usr/local/bin/docker-php-entrypoint +echo diff --git a/8.1/bullseye/root/usr/local/etc/php/conf.d/docker-php-moodle.ini b/8.1/bullseye/root/usr/local/etc/php/conf.d/docker-php-moodle.ini new file mode 100644 index 0000000..c5675bf --- /dev/null +++ b/8.1/bullseye/root/usr/local/etc/php/conf.d/docker-php-moodle.ini @@ -0,0 +1,6 @@ +; CONFIGURATION SETTINGS REQUIRED BY MOODLE + +; How many GET/POST/COOKIE input variables may be accepted +; See MDL-71390 for more info. This is the recommended / required +; value to support sites having 1000 courses, activities, users.... +max_input_vars = 5000 diff --git a/8.1/bullseye/tests/docker-entrypoint.d/20-example.ini b/8.1/bullseye/tests/docker-entrypoint.d/20-example.ini new file mode 100644 index 0000000..ec45086 --- /dev/null +++ b/8.1/bullseye/tests/docker-entrypoint.d/20-example.ini @@ -0,0 +1,2 @@ +; Test file which disable file uploads. +file_uploads = Off diff --git a/8.1/bullseye/tests/docker-entrypoint.d/30-sourced.sh b/8.1/bullseye/tests/docker-entrypoint.d/30-sourced.sh new file mode 100644 index 0000000..86a6286 --- /dev/null +++ b/8.1/bullseye/tests/docker-entrypoint.d/30-sourced.sh @@ -0,0 +1,10 @@ +# This file should not have a shbang! as it is expected to be sourced. +# It should not be executable either. + +mkdir -p /var/www/data + +(return 0 2>/dev/null) && sourced=1 || sourced=0 + +if [[ $sourced -eq 1 ]]; then + echo "Sourced" >> /var/www/data/sourced.txt +fi diff --git a/8.1/bullseye/tests/docker-entrypoint.d/40-exec.sh b/8.1/bullseye/tests/docker-entrypoint.d/40-exec.sh new file mode 100755 index 0000000..d924fc6 --- /dev/null +++ b/8.1/bullseye/tests/docker-entrypoint.d/40-exec.sh @@ -0,0 +1,10 @@ +# This file should not have a shbang! as it is expected to be sourced. +# It should not be executable either. + +mkdir -p /var/www/data + +(return 0 2>/dev/null) && sourced=1 || sourced=0 + +if [[ $sourced -eq 0 ]]; then + echo "Executed" >> /var/www/data/executed.txt +fi diff --git a/8.1/bullseye/tests/fixtures/check-entrypoint-scripts.php b/8.1/bullseye/tests/fixtures/check-entrypoint-scripts.php new file mode 100644 index 0000000..aa06d16 --- /dev/null +++ b/8.1/bullseye/tests/fixtures/check-entrypoint-scripts.php @@ -0,0 +1,27 @@ + Date: Sat, 18 Mar 2023 14:19:13 +0800 Subject: [PATCH 4/7] 8.1-buster --- 8.1/buster/Dockerfile | 52 ++++++++++++ 8.1/buster/root/tmp/setup/oci8-extension.sh | 30 +++++++ 8.1/buster/root/tmp/setup/php-extensions.sh | 82 +++++++++++++++++++ 8.1/buster/root/tmp/setup/sqlsrv-extension.sh | 47 +++++++++++ .../local/bin/moodle-docker-php-entrypoint | 36 ++++++++ .../etc/php/conf.d/docker-php-moodle.ini | 6 ++ .../tests/docker-entrypoint.d/20-example.ini | 2 + .../tests/docker-entrypoint.d/30-sourced.sh | 10 +++ .../tests/docker-entrypoint.d/40-exec.sh | 10 +++ .../fixtures/check-entrypoint-scripts.php | 27 ++++++ 8.1/buster/tests/fixtures/check-ini.php | 20 +++++ 8.1/buster/tests/fixtures/test.php | 54 ++++++++++++ 12 files changed, 376 insertions(+) create mode 100644 8.1/buster/Dockerfile create mode 100755 8.1/buster/root/tmp/setup/oci8-extension.sh create mode 100755 8.1/buster/root/tmp/setup/php-extensions.sh create mode 100755 8.1/buster/root/tmp/setup/sqlsrv-extension.sh create mode 100755 8.1/buster/root/usr/local/bin/moodle-docker-php-entrypoint create mode 100644 8.1/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini create mode 100644 8.1/buster/tests/docker-entrypoint.d/20-example.ini create mode 100644 8.1/buster/tests/docker-entrypoint.d/30-sourced.sh create mode 100755 8.1/buster/tests/docker-entrypoint.d/40-exec.sh create mode 100644 8.1/buster/tests/fixtures/check-entrypoint-scripts.php create mode 100644 8.1/buster/tests/fixtures/check-ini.php create mode 100644 8.1/buster/tests/fixtures/test.php diff --git a/8.1/buster/Dockerfile b/8.1/buster/Dockerfile new file mode 100644 index 0000000..8de7c1d --- /dev/null +++ b/8.1/buster/Dockerfile @@ -0,0 +1,52 @@ +FROM php:8.1-apache-buster + +# So we can use it anywhere for conditional stuff. Keeping BC with old (non-buildkit, builders) +ARG TARGETPLATFORM +ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} +RUN echo "Building for ${TARGETPLATFORM}" + +# Install some packages that are useful within the images. +RUN apt-get update && apt-get install -y \ + git \ +&& rm -rf /var/lib/apt/lists/* + +# Install pickle as an easier alternative to PECL, that is not +# available any more for PHP 8 and up. Some alternatives searched were: +# - https://olvlvl.com/2019-06-docker-pecl-without-pecl +# - https://github.com/FriendsOfPHP/pickle +# - manually "curl https://pecl.php.net/get/xxxx && tar && docker-php-ext-install xxx" +# Of course, if the images end using some alternative, we'll switch to it. Just right now +# there isn't such an alternative.a +# +# Update 20201126: Finally, see https://github.com/docker-library/php/issues/1087 it seems that pear/pecl +# continues being availbale with php8, so we are going to continue using it. The previous comments as +# left in case we need to find an alternative way to install PECL stuff and there isn't any official. +# For an example of php80-rc5 near complete, using pickle instead of pear/pecl, look to: +# https://github.com/stronk7/moodle-php-apache/tree/8.0-buster-pickle-version + +# Setup the required extensions. +ARG DEBIAN_FRONTEND=noninteractive +ADD root/tmp/setup/php-extensions.sh /tmp/setup/php-extensions.sh +RUN /tmp/setup/php-extensions.sh + +# Install Oracle Instantclient +ADD root/tmp/setup/oci8-extension.sh /tmp/setup/oci8-extension.sh +RUN /tmp/setup/oci8-extension.sh +ENV LD_LIBRARY_PATH /usr/local/instantclient + +# Install Microsoft sqlsrv. +ADD root/tmp/setup/sqlsrv-extension.sh /tmp/setup/sqlsrv-extension.sh +RUN /tmp/setup/sqlsrv-extension.sh + +RUN mkdir /var/www/moodledata && chown www-data /var/www/moodledata && \ + mkdir /var/www/phpunitdata && chown www-data /var/www/phpunitdata && \ + mkdir /var/www/behatdata && chown www-data /var/www/behatdata && \ + mkdir /var/www/behatfaildumps && chown www-data /var/www/behatfaildumps + +ADD root/usr /usr + +# Fix the original permissions of /tmp, the PHP default upload tmp dir. +RUN chmod 777 /tmp && chmod +t /tmp + +CMD ["apache2-foreground"] +ENTRYPOINT ["moodle-docker-php-entrypoint"] diff --git a/8.1/buster/root/tmp/setup/oci8-extension.sh b/8.1/buster/root/tmp/setup/oci8-extension.sh new file mode 100755 index 0000000..72d4ecc --- /dev/null +++ b/8.1/buster/root/tmp/setup/oci8-extension.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -e + +if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then + echo "oracle extension not available for ${TARGETPLATFORM} architecture, skipping" + exit 0 +fi + +echo "Downloading oracle files" +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip + +unzip /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip +unzip /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip +unzip /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip + +ln -s /usr/local/instantclient_21_6 /usr/local/instantclient +ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus + +echo 'instantclient,/usr/local/instantclient' | pecl install oci8 +docker-php-ext-enable oci8 +echo 'oci8.statement_cache_size = 0' >> /usr/local/etc/php/conf.d/docker-php-ext-oci8.ini diff --git a/8.1/buster/root/tmp/setup/php-extensions.sh b/8.1/buster/root/tmp/setup/php-extensions.sh new file mode 100755 index 0000000..7556c28 --- /dev/null +++ b/8.1/buster/root/tmp/setup/php-extensions.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +set -e + +echo "Installing apt dependencies" + +# Build packages will be added during the build, but will be removed at the end. +BUILD_PACKAGES="gettext libcurl4-openssl-dev libfreetype6-dev libicu-dev libjpeg62-turbo-dev \ + libldap2-dev libmariadbclient-dev libmemcached-dev libpng-dev libpq-dev libxml2-dev libxslt-dev \ + uuid-dev" + +# Packages for Postgres. +PACKAGES_POSTGRES="libpq5" + +# Packages for MariaDB and MySQL. +PACKAGES_MYMARIA="libmariadb3" + +# Packages for other Moodle runtime dependenices. +PACKAGES_RUNTIME="ghostscript libaio1 libcurl4 libgss3 libicu63 libmcrypt-dev libxml2 libxslt1.1 \ + libzip-dev locales sassc unzip zip" + +# Packages for Memcached. +PACKAGES_MEMCACHED="libmemcached11 libmemcachedutil2" + +# Packages for LDAP. +PACKAGES_LDAP="libldap-2.4-2" + +apt-get update +apt-get install -y --no-install-recommends apt-transport-https \ + $BUILD_PACKAGES \ + $PACKAGES_POSTGRES \ + $PACKAGES_MYMARIA \ + $PACKAGES_RUNTIME \ + $PACKAGES_MEMCACHED \ + $PACKAGES_LDAP + +# Generate the locales configuration fo rboth Australia, and the US. +echo 'Generating locales..' +echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen +echo 'en_AU.UTF-8 UTF-8' >> /etc/locale.gen +locale-gen + +echo "Installing php extensions" + +# ZIP +docker-php-ext-configure zip --with-zip +docker-php-ext-install zip + +docker-php-ext-install -j$(nproc) \ + exif \ + intl \ + mysqli \ + opcache \ + pgsql \ + soap \ + xsl + +# GD. +docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ +docker-php-ext-install -j$(nproc) gd + +# LDAP. +docker-php-ext-configure ldap +docker-php-ext-install -j$(nproc) ldap + +# APCu, igbinary, Memcached, MongoDB, PCov, Redis, Solr, timezonedb, uuid, XMLRPC (beta) +pecl install apcu igbinary memcached mongodb pcov redis solr timezonedb uuid xmlrpc-beta +docker-php-ext-enable apcu igbinary memcached mongodb pcov redis solr timezonedb uuid xmlrpc + +echo 'apc.enable_cli = On' >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini + +echo "pcov.enabled=0" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.exclude='~\/(tests|coverage|vendor|node_modules)\/~'" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.directory=." >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.initial.files=1024" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini + +# Keep our image size down.. +pecl clear-cache +apt-get remove --purge -y $BUILD_PACKAGES +apt-get autoremove -y +apt-get clean +rm -rf /var/lib/apt/lists/* diff --git a/8.1/buster/root/tmp/setup/sqlsrv-extension.sh b/8.1/buster/root/tmp/setup/sqlsrv-extension.sh new file mode 100755 index 0000000..8a807f2 --- /dev/null +++ b/8.1/buster/root/tmp/setup/sqlsrv-extension.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +set -e + +# Debian buster (10) haven't got the arm64 packages, it seems, see: +# - buster: https://packages.microsoft.com/debian/10/prod/pool/main/m/msodbcsql18/ +# So we won't build the extension for buster (10) images on arm64. +if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then + echo "sqlsrv extension not available for ${TARGETPLATFORM} architecture, skipping" + exit 0 +fi + +# Packages for build. +BUILD_PACKAGES="gnupg unixodbc-dev" + +# Packages for sqlsrv runtime. +PACKAGES_SQLSRV="unixodbc" + +# Note: These dependencies must be installed before installing the Microsoft source because there is a package in there +# which breaks the install. +echo "Installing apt dependencies" +apt-get update +apt-get install -y --no-install-recommends apt-transport-https \ + $BUILD_PACKAGES \ + $PACKAGES_SQLSRV + +# Install Microsoft dependencies for sqlsrv +echo "Downloading sqlsrv files" +curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - +curl https://packages.microsoft.com/config/debian/10/prod.list -o /etc/apt/sources.list.d/mssql-release.list +apt-get update + +echo "Install msodbcsql" +ACCEPT_EULA=Y apt-get install -y msodbcsql18 + +ln -fsv /opt/mssql-tools/bin/* /usr/bin + +# Need 5.10.0beta1 (or later) for PHP 8.1 support +pecl install sqlsrv-5.11.0 +docker-php-ext-enable sqlsrv + +# Keep our image size down.. +pecl clear-cache +apt-get remove --purge -y $BUILD_PACKAGES +apt-get autoremove -y +apt-get clean +rm -rf /var/lib/apt/lists/* diff --git a/8.1/buster/root/usr/local/bin/moodle-docker-php-entrypoint b/8.1/buster/root/usr/local/bin/moodle-docker-php-entrypoint new file mode 100755 index 0000000..3abc465 --- /dev/null +++ b/8.1/buster/root/usr/local/bin/moodle-docker-php-entrypoint @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -Eeo pipefail + +docker_process_init_files() { + local f + for f; do + case "$f" in + *.sh) + # Note: This hack is required for MacOS because the exeute bit is not checked for bind mounts. + # The executable bit is stored, but the test -x flag does not return corretly. + # Copying the file to an alternate file system allows it to be respected. + rm -f /tmp/testscript + cp "$f" /tmp/testscript + if [ -x "/tmp/testscript" ]; then + echo "$0: running $f" + "$f" + else + echo "$0: sourcing $f" + . "$f" + fi + ;; + *.ini) + echo "$0: copying $f into /usr/local/etc/php/conf.d/" + cp "$f" /usr/local/etc/php/conf.d/ + ;; + esac + done +} + +echo "Running entrypoint files from /docker-entrypoint.d/*" +docker_process_init_files /docker-entrypoint.d/* +echo + +echo "Starting docker-php-entrypoint with $@" +source /usr/local/bin/docker-php-entrypoint +echo diff --git a/8.1/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini b/8.1/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini new file mode 100644 index 0000000..c5675bf --- /dev/null +++ b/8.1/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini @@ -0,0 +1,6 @@ +; CONFIGURATION SETTINGS REQUIRED BY MOODLE + +; How many GET/POST/COOKIE input variables may be accepted +; See MDL-71390 for more info. This is the recommended / required +; value to support sites having 1000 courses, activities, users.... +max_input_vars = 5000 diff --git a/8.1/buster/tests/docker-entrypoint.d/20-example.ini b/8.1/buster/tests/docker-entrypoint.d/20-example.ini new file mode 100644 index 0000000..ec45086 --- /dev/null +++ b/8.1/buster/tests/docker-entrypoint.d/20-example.ini @@ -0,0 +1,2 @@ +; Test file which disable file uploads. +file_uploads = Off diff --git a/8.1/buster/tests/docker-entrypoint.d/30-sourced.sh b/8.1/buster/tests/docker-entrypoint.d/30-sourced.sh new file mode 100644 index 0000000..86a6286 --- /dev/null +++ b/8.1/buster/tests/docker-entrypoint.d/30-sourced.sh @@ -0,0 +1,10 @@ +# This file should not have a shbang! as it is expected to be sourced. +# It should not be executable either. + +mkdir -p /var/www/data + +(return 0 2>/dev/null) && sourced=1 || sourced=0 + +if [[ $sourced -eq 1 ]]; then + echo "Sourced" >> /var/www/data/sourced.txt +fi diff --git a/8.1/buster/tests/docker-entrypoint.d/40-exec.sh b/8.1/buster/tests/docker-entrypoint.d/40-exec.sh new file mode 100755 index 0000000..d924fc6 --- /dev/null +++ b/8.1/buster/tests/docker-entrypoint.d/40-exec.sh @@ -0,0 +1,10 @@ +# This file should not have a shbang! as it is expected to be sourced. +# It should not be executable either. + +mkdir -p /var/www/data + +(return 0 2>/dev/null) && sourced=1 || sourced=0 + +if [[ $sourced -eq 0 ]]; then + echo "Executed" >> /var/www/data/executed.txt +fi diff --git a/8.1/buster/tests/fixtures/check-entrypoint-scripts.php b/8.1/buster/tests/fixtures/check-entrypoint-scripts.php new file mode 100644 index 0000000..aa06d16 --- /dev/null +++ b/8.1/buster/tests/fixtures/check-entrypoint-scripts.php @@ -0,0 +1,27 @@ + Date: Sat, 18 Mar 2023 14:19:31 +0800 Subject: [PATCH 5/7] 8.0-buster --- 8.0/buster/Dockerfile | 52 ++++++++++++ 8.0/buster/root/tmp/setup/oci8-extension.sh | 30 +++++++ 8.0/buster/root/tmp/setup/php-extensions.sh | 82 +++++++++++++++++++ 8.0/buster/root/tmp/setup/sqlsrv-extension.sh | 47 +++++++++++ .../local/bin/moodle-docker-php-entrypoint | 36 ++++++++ .../etc/php/conf.d/docker-php-moodle.ini | 6 ++ .../tests/docker-entrypoint.d/20-example.ini | 2 + .../tests/docker-entrypoint.d/30-sourced.sh | 10 +++ .../tests/docker-entrypoint.d/40-exec.sh | 10 +++ .../fixtures/check-entrypoint-scripts.php | 27 ++++++ 8.0/buster/tests/fixtures/check-ini.php | 20 +++++ 8.0/buster/tests/fixtures/test.php | 54 ++++++++++++ 12 files changed, 376 insertions(+) create mode 100644 8.0/buster/Dockerfile create mode 100755 8.0/buster/root/tmp/setup/oci8-extension.sh create mode 100755 8.0/buster/root/tmp/setup/php-extensions.sh create mode 100755 8.0/buster/root/tmp/setup/sqlsrv-extension.sh create mode 100755 8.0/buster/root/usr/local/bin/moodle-docker-php-entrypoint create mode 100644 8.0/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini create mode 100644 8.0/buster/tests/docker-entrypoint.d/20-example.ini create mode 100644 8.0/buster/tests/docker-entrypoint.d/30-sourced.sh create mode 100755 8.0/buster/tests/docker-entrypoint.d/40-exec.sh create mode 100644 8.0/buster/tests/fixtures/check-entrypoint-scripts.php create mode 100644 8.0/buster/tests/fixtures/check-ini.php create mode 100644 8.0/buster/tests/fixtures/test.php diff --git a/8.0/buster/Dockerfile b/8.0/buster/Dockerfile new file mode 100644 index 0000000..cb75b56 --- /dev/null +++ b/8.0/buster/Dockerfile @@ -0,0 +1,52 @@ +FROM php:8.0-apache-buster + +# So we can use it anywhere for conditional stuff. Keeping BC with old (non-buildkit, builders) +ARG TARGETPLATFORM +ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} +RUN echo "Building for ${TARGETPLATFORM}" + +# Install some packages that are useful within the images. +RUN apt-get update && apt-get install -y \ + git \ +&& rm -rf /var/lib/apt/lists/* + +# Install pickle as an easier alternative to PECL, that is not +# available any more for PHP 8 and up. Some alternatives searched were: +# - https://olvlvl.com/2019-06-docker-pecl-without-pecl +# - https://github.com/FriendsOfPHP/pickle +# - manually "curl https://pecl.php.net/get/xxxx && tar && docker-php-ext-install xxx" +# Of course, if the images end using some alternative, we'll switch to it. Just right now +# there isn't such an alternative.a +# +# Update 20201126: Finally, see https://github.com/docker-library/php/issues/1087 it seems that pear/pecl +# continues being availbale with php8, so we are going to continue using it. The previous comments as +# left in case we need to find an alternative way to install PECL stuff and there isn't any official. +# For an example of php80-rc5 near complete, using pickle instead of pear/pecl, look to: +# https://github.com/stronk7/moodle-php-apache/tree/8.0-buster-pickle-version + +# Setup the required extensions. +ARG DEBIAN_FRONTEND=noninteractive +ADD root/tmp/setup/php-extensions.sh /tmp/setup/php-extensions.sh +RUN /tmp/setup/php-extensions.sh + +# Install Oracle Instantclient +ADD root/tmp/setup/oci8-extension.sh /tmp/setup/oci8-extension.sh +RUN /tmp/setup/oci8-extension.sh +ENV LD_LIBRARY_PATH /usr/local/instantclient + +# Install Microsoft sqlsrv. +ADD root/tmp/setup/sqlsrv-extension.sh /tmp/setup/sqlsrv-extension.sh +RUN /tmp/setup/sqlsrv-extension.sh + +RUN mkdir /var/www/moodledata && chown www-data /var/www/moodledata && \ + mkdir /var/www/phpunitdata && chown www-data /var/www/phpunitdata && \ + mkdir /var/www/behatdata && chown www-data /var/www/behatdata && \ + mkdir /var/www/behatfaildumps && chown www-data /var/www/behatfaildumps + +ADD root/usr /usr + +# Fix the original permissions of /tmp, the PHP default upload tmp dir. +RUN chmod 777 /tmp && chmod +t /tmp + +CMD ["apache2-foreground"] +ENTRYPOINT ["moodle-docker-php-entrypoint"] diff --git a/8.0/buster/root/tmp/setup/oci8-extension.sh b/8.0/buster/root/tmp/setup/oci8-extension.sh new file mode 100755 index 0000000..28a83c0 --- /dev/null +++ b/8.0/buster/root/tmp/setup/oci8-extension.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -e + +if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then + echo "oracle extension not available for ${TARGETPLATFORM} architecture, skipping" + exit 0 +fi + +echo "Downloading oracle files" +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip + +unzip /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip +unzip /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip +unzip /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip + +ln -s /usr/local/instantclient_21_6 /usr/local/instantclient +ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus + +echo 'instantclient,/usr/local/instantclient' | pecl install oci8-3.0.1 +docker-php-ext-enable oci8 +echo 'oci8.statement_cache_size = 0' >> /usr/local/etc/php/conf.d/docker-php-ext-oci8.ini diff --git a/8.0/buster/root/tmp/setup/php-extensions.sh b/8.0/buster/root/tmp/setup/php-extensions.sh new file mode 100755 index 0000000..7556c28 --- /dev/null +++ b/8.0/buster/root/tmp/setup/php-extensions.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +set -e + +echo "Installing apt dependencies" + +# Build packages will be added during the build, but will be removed at the end. +BUILD_PACKAGES="gettext libcurl4-openssl-dev libfreetype6-dev libicu-dev libjpeg62-turbo-dev \ + libldap2-dev libmariadbclient-dev libmemcached-dev libpng-dev libpq-dev libxml2-dev libxslt-dev \ + uuid-dev" + +# Packages for Postgres. +PACKAGES_POSTGRES="libpq5" + +# Packages for MariaDB and MySQL. +PACKAGES_MYMARIA="libmariadb3" + +# Packages for other Moodle runtime dependenices. +PACKAGES_RUNTIME="ghostscript libaio1 libcurl4 libgss3 libicu63 libmcrypt-dev libxml2 libxslt1.1 \ + libzip-dev locales sassc unzip zip" + +# Packages for Memcached. +PACKAGES_MEMCACHED="libmemcached11 libmemcachedutil2" + +# Packages for LDAP. +PACKAGES_LDAP="libldap-2.4-2" + +apt-get update +apt-get install -y --no-install-recommends apt-transport-https \ + $BUILD_PACKAGES \ + $PACKAGES_POSTGRES \ + $PACKAGES_MYMARIA \ + $PACKAGES_RUNTIME \ + $PACKAGES_MEMCACHED \ + $PACKAGES_LDAP + +# Generate the locales configuration fo rboth Australia, and the US. +echo 'Generating locales..' +echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen +echo 'en_AU.UTF-8 UTF-8' >> /etc/locale.gen +locale-gen + +echo "Installing php extensions" + +# ZIP +docker-php-ext-configure zip --with-zip +docker-php-ext-install zip + +docker-php-ext-install -j$(nproc) \ + exif \ + intl \ + mysqli \ + opcache \ + pgsql \ + soap \ + xsl + +# GD. +docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ +docker-php-ext-install -j$(nproc) gd + +# LDAP. +docker-php-ext-configure ldap +docker-php-ext-install -j$(nproc) ldap + +# APCu, igbinary, Memcached, MongoDB, PCov, Redis, Solr, timezonedb, uuid, XMLRPC (beta) +pecl install apcu igbinary memcached mongodb pcov redis solr timezonedb uuid xmlrpc-beta +docker-php-ext-enable apcu igbinary memcached mongodb pcov redis solr timezonedb uuid xmlrpc + +echo 'apc.enable_cli = On' >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini + +echo "pcov.enabled=0" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.exclude='~\/(tests|coverage|vendor|node_modules)\/~'" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.directory=." >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.initial.files=1024" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini + +# Keep our image size down.. +pecl clear-cache +apt-get remove --purge -y $BUILD_PACKAGES +apt-get autoremove -y +apt-get clean +rm -rf /var/lib/apt/lists/* diff --git a/8.0/buster/root/tmp/setup/sqlsrv-extension.sh b/8.0/buster/root/tmp/setup/sqlsrv-extension.sh new file mode 100755 index 0000000..cfbf87a --- /dev/null +++ b/8.0/buster/root/tmp/setup/sqlsrv-extension.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +set -e + +# Debian buster (10) haven't got the arm64 packages, it seems, see: +# - buster: https://packages.microsoft.com/debian/10/prod/pool/main/m/msodbcsql18/ +# So we won't build the extension for buster (10) images on arm64. +if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then + echo "sqlsrv extension not available for ${TARGETPLATFORM} architecture, skipping" + exit 0 +fi + +# Packages for build. +BUILD_PACKAGES="gnupg unixodbc-dev" + +# Packages for sqlsrv runtime. +PACKAGES_SQLSRV="unixodbc" + +# Note: These dependencies must be installed before installing the Microsoft source because there is a package in there +# which breaks the install. +echo "Installing apt dependencies" +apt-get update +apt-get install -y --no-install-recommends apt-transport-https \ + $BUILD_PACKAGES \ + $PACKAGES_SQLSRV + +# Install Microsoft dependencies for sqlsrv +echo "Downloading sqlsrv files" +curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - +curl https://packages.microsoft.com/config/debian/10/prod.list -o /etc/apt/sources.list.d/mssql-release.list +apt-get update + +echo "Install msodbcsql" +ACCEPT_EULA=Y apt-get install -y msodbcsql18 + +ln -fsv /opt/mssql-tools/bin/* /usr/bin + +# Need 5.9.0preview1 (or later) for PHP 8.0 support +pecl install sqlsrv-5.11.0 +docker-php-ext-enable sqlsrv + +# Keep our image size down.. +pecl clear-cache +apt-get remove --purge -y $BUILD_PACKAGES +apt-get autoremove -y +apt-get clean +rm -rf /var/lib/apt/lists/* diff --git a/8.0/buster/root/usr/local/bin/moodle-docker-php-entrypoint b/8.0/buster/root/usr/local/bin/moodle-docker-php-entrypoint new file mode 100755 index 0000000..3abc465 --- /dev/null +++ b/8.0/buster/root/usr/local/bin/moodle-docker-php-entrypoint @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -Eeo pipefail + +docker_process_init_files() { + local f + for f; do + case "$f" in + *.sh) + # Note: This hack is required for MacOS because the exeute bit is not checked for bind mounts. + # The executable bit is stored, but the test -x flag does not return corretly. + # Copying the file to an alternate file system allows it to be respected. + rm -f /tmp/testscript + cp "$f" /tmp/testscript + if [ -x "/tmp/testscript" ]; then + echo "$0: running $f" + "$f" + else + echo "$0: sourcing $f" + . "$f" + fi + ;; + *.ini) + echo "$0: copying $f into /usr/local/etc/php/conf.d/" + cp "$f" /usr/local/etc/php/conf.d/ + ;; + esac + done +} + +echo "Running entrypoint files from /docker-entrypoint.d/*" +docker_process_init_files /docker-entrypoint.d/* +echo + +echo "Starting docker-php-entrypoint with $@" +source /usr/local/bin/docker-php-entrypoint +echo diff --git a/8.0/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini b/8.0/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini new file mode 100644 index 0000000..c5675bf --- /dev/null +++ b/8.0/buster/root/usr/local/etc/php/conf.d/docker-php-moodle.ini @@ -0,0 +1,6 @@ +; CONFIGURATION SETTINGS REQUIRED BY MOODLE + +; How many GET/POST/COOKIE input variables may be accepted +; See MDL-71390 for more info. This is the recommended / required +; value to support sites having 1000 courses, activities, users.... +max_input_vars = 5000 diff --git a/8.0/buster/tests/docker-entrypoint.d/20-example.ini b/8.0/buster/tests/docker-entrypoint.d/20-example.ini new file mode 100644 index 0000000..ec45086 --- /dev/null +++ b/8.0/buster/tests/docker-entrypoint.d/20-example.ini @@ -0,0 +1,2 @@ +; Test file which disable file uploads. +file_uploads = Off diff --git a/8.0/buster/tests/docker-entrypoint.d/30-sourced.sh b/8.0/buster/tests/docker-entrypoint.d/30-sourced.sh new file mode 100644 index 0000000..86a6286 --- /dev/null +++ b/8.0/buster/tests/docker-entrypoint.d/30-sourced.sh @@ -0,0 +1,10 @@ +# This file should not have a shbang! as it is expected to be sourced. +# It should not be executable either. + +mkdir -p /var/www/data + +(return 0 2>/dev/null) && sourced=1 || sourced=0 + +if [[ $sourced -eq 1 ]]; then + echo "Sourced" >> /var/www/data/sourced.txt +fi diff --git a/8.0/buster/tests/docker-entrypoint.d/40-exec.sh b/8.0/buster/tests/docker-entrypoint.d/40-exec.sh new file mode 100755 index 0000000..d924fc6 --- /dev/null +++ b/8.0/buster/tests/docker-entrypoint.d/40-exec.sh @@ -0,0 +1,10 @@ +# This file should not have a shbang! as it is expected to be sourced. +# It should not be executable either. + +mkdir -p /var/www/data + +(return 0 2>/dev/null) && sourced=1 || sourced=0 + +if [[ $sourced -eq 0 ]]; then + echo "Executed" >> /var/www/data/executed.txt +fi diff --git a/8.0/buster/tests/fixtures/check-entrypoint-scripts.php b/8.0/buster/tests/fixtures/check-entrypoint-scripts.php new file mode 100644 index 0000000..aa06d16 --- /dev/null +++ b/8.0/buster/tests/fixtures/check-entrypoint-scripts.php @@ -0,0 +1,27 @@ + Date: Sat, 18 Mar 2023 14:20:01 +0800 Subject: [PATCH 6/7] 8.0-bullseye --- 8.0/bullseye/Dockerfile | 52 ++++++++++++ 8.0/bullseye/root/tmp/setup/oci8-extension.sh | 30 +++++++ 8.0/bullseye/root/tmp/setup/php-extensions.sh | 82 +++++++++++++++++++ .../root/tmp/setup/sqlsrv-extension.sh | 45 ++++++++++ .../local/bin/moodle-docker-php-entrypoint | 36 ++++++++ .../etc/php/conf.d/docker-php-moodle.ini | 6 ++ .../tests/docker-entrypoint.d/20-example.ini | 2 + .../tests/docker-entrypoint.d/30-sourced.sh | 10 +++ .../tests/docker-entrypoint.d/40-exec.sh | 10 +++ .../fixtures/check-entrypoint-scripts.php | 27 ++++++ 8.0/bullseye/tests/fixtures/check-ini.php | 20 +++++ 8.0/bullseye/tests/fixtures/test.php | 54 ++++++++++++ 12 files changed, 374 insertions(+) create mode 100644 8.0/bullseye/Dockerfile create mode 100755 8.0/bullseye/root/tmp/setup/oci8-extension.sh create mode 100755 8.0/bullseye/root/tmp/setup/php-extensions.sh create mode 100755 8.0/bullseye/root/tmp/setup/sqlsrv-extension.sh create mode 100755 8.0/bullseye/root/usr/local/bin/moodle-docker-php-entrypoint create mode 100644 8.0/bullseye/root/usr/local/etc/php/conf.d/docker-php-moodle.ini create mode 100644 8.0/bullseye/tests/docker-entrypoint.d/20-example.ini create mode 100644 8.0/bullseye/tests/docker-entrypoint.d/30-sourced.sh create mode 100755 8.0/bullseye/tests/docker-entrypoint.d/40-exec.sh create mode 100644 8.0/bullseye/tests/fixtures/check-entrypoint-scripts.php create mode 100644 8.0/bullseye/tests/fixtures/check-ini.php create mode 100644 8.0/bullseye/tests/fixtures/test.php diff --git a/8.0/bullseye/Dockerfile b/8.0/bullseye/Dockerfile new file mode 100644 index 0000000..99b0028 --- /dev/null +++ b/8.0/bullseye/Dockerfile @@ -0,0 +1,52 @@ +FROM php:8.0-apache-bullseye + +# So we can use it anywhere for conditional stuff. Keeping BC with old (non-buildkit, builders) +ARG TARGETPLATFORM +ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} +RUN echo "Building for ${TARGETPLATFORM}" + +# Install some packages that are useful within the images. +RUN apt-get update && apt-get install -y \ + git \ +&& rm -rf /var/lib/apt/lists/* + +# Install pickle as an easier alternative to PECL, that is not +# available any more for PHP 8 and up. Some alternatives searched were: +# - https://olvlvl.com/2019-06-docker-pecl-without-pecl +# - https://github.com/FriendsOfPHP/pickle +# - manually "curl https://pecl.php.net/get/xxxx && tar && docker-php-ext-install xxx" +# Of course, if the images end using some alternative, we'll switch to it. Just right now +# there isn't such an alternative.a +# +# Update 20201126: Finally, see https://github.com/docker-library/php/issues/1087 it seems that pear/pecl +# continues being availbale with php8, so we are going to continue using it. The previous comments as +# left in case we need to find an alternative way to install PECL stuff and there isn't any official. +# For an example of php80-rc5 near complete, using pickle instead of pear/pecl, look to: +# https://github.com/stronk7/moodle-php-apache/tree/8.0-buster-pickle-version + +# Setup the required extensions. +ARG DEBIAN_FRONTEND=noninteractive +ADD root/tmp/setup/php-extensions.sh /tmp/setup/php-extensions.sh +RUN /tmp/setup/php-extensions.sh + +# Install Oracle Instantclient +ADD root/tmp/setup/oci8-extension.sh /tmp/setup/oci8-extension.sh +RUN /tmp/setup/oci8-extension.sh +ENV LD_LIBRARY_PATH /usr/local/instantclient + +# Install Microsoft sqlsrv. +ADD root/tmp/setup/sqlsrv-extension.sh /tmp/setup/sqlsrv-extension.sh +RUN /tmp/setup/sqlsrv-extension.sh + +RUN mkdir /var/www/moodledata && chown www-data /var/www/moodledata && \ + mkdir /var/www/phpunitdata && chown www-data /var/www/phpunitdata && \ + mkdir /var/www/behatdata && chown www-data /var/www/behatdata && \ + mkdir /var/www/behatfaildumps && chown www-data /var/www/behatfaildumps + +ADD root/usr /usr + +# Fix the original permissions of /tmp, the PHP default upload tmp dir. +RUN chmod 777 /tmp && chmod +t /tmp + +CMD ["apache2-foreground"] +ENTRYPOINT ["moodle-docker-php-entrypoint"] diff --git a/8.0/bullseye/root/tmp/setup/oci8-extension.sh b/8.0/bullseye/root/tmp/setup/oci8-extension.sh new file mode 100755 index 0000000..28a83c0 --- /dev/null +++ b/8.0/bullseye/root/tmp/setup/oci8-extension.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -e + +if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then + echo "oracle extension not available for ${TARGETPLATFORM} architecture, skipping" + exit 0 +fi + +echo "Downloading oracle files" +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip +curl https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip \ + -o /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip + +unzip /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip +unzip /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip +unzip /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip -d /usr/local/ +rm /tmp/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip + +ln -s /usr/local/instantclient_21_6 /usr/local/instantclient +ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus + +echo 'instantclient,/usr/local/instantclient' | pecl install oci8-3.0.1 +docker-php-ext-enable oci8 +echo 'oci8.statement_cache_size = 0' >> /usr/local/etc/php/conf.d/docker-php-ext-oci8.ini diff --git a/8.0/bullseye/root/tmp/setup/php-extensions.sh b/8.0/bullseye/root/tmp/setup/php-extensions.sh new file mode 100755 index 0000000..38c9ff1 --- /dev/null +++ b/8.0/bullseye/root/tmp/setup/php-extensions.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +set -e + +echo "Installing apt dependencies" + +# Build packages will be added during the build, but will be removed at the end. +BUILD_PACKAGES="gettext libcurl4-openssl-dev libfreetype6-dev libicu-dev libjpeg62-turbo-dev \ + libldap2-dev libmariadb-dev libmemcached-dev libpng-dev libpq-dev libxml2-dev libxslt-dev \ + uuid-dev" + +# Packages for Postgres. +PACKAGES_POSTGRES="libpq5" + +# Packages for MariaDB and MySQL. +PACKAGES_MYMARIA="libmariadb3" + +# Packages for other Moodle runtime dependenices. +PACKAGES_RUNTIME="ghostscript libaio1 libcurl4 libgss3 libicu67 libmcrypt-dev libxml2 libxslt1.1 \ + libzip-dev locales sassc unzip zip" + +# Packages for Memcached. +PACKAGES_MEMCACHED="libmemcached11 libmemcachedutil2" + +# Packages for LDAP. +PACKAGES_LDAP="libldap-2.4-2" + +apt-get update +apt-get install -y --no-install-recommends apt-transport-https \ + $BUILD_PACKAGES \ + $PACKAGES_POSTGRES \ + $PACKAGES_MYMARIA \ + $PACKAGES_RUNTIME \ + $PACKAGES_MEMCACHED \ + $PACKAGES_LDAP + +# Generate the locales configuration fo rboth Australia, and the US. +echo 'Generating locales..' +echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen +echo 'en_AU.UTF-8 UTF-8' >> /etc/locale.gen +locale-gen + +echo "Installing php extensions" + +# ZIP +docker-php-ext-configure zip --with-zip +docker-php-ext-install zip + +docker-php-ext-install -j$(nproc) \ + exif \ + intl \ + mysqli \ + opcache \ + pgsql \ + soap \ + xsl + +# GD. +docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ +docker-php-ext-install -j$(nproc) gd + +# LDAP. +docker-php-ext-configure ldap +docker-php-ext-install -j$(nproc) ldap + +# APCu, igbinary, Memcached, MongoDB, PCov, Redis, Solr, timezonedb, uuid, XMLRPC (beta) +pecl install apcu igbinary memcached mongodb pcov redis solr timezonedb uuid xmlrpc-beta +docker-php-ext-enable apcu igbinary memcached mongodb pcov redis solr timezonedb uuid xmlrpc + +echo 'apc.enable_cli = On' >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini + +echo "pcov.enabled=0" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.exclude='~\/(tests|coverage|vendor|node_modules)\/~'" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.directory=." >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini +echo "pcov.initial.files=1024" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini + +# Keep our image size down.. +pecl clear-cache +apt-get remove --purge -y $BUILD_PACKAGES +apt-get autoremove -y +apt-get clean +rm -rf /var/lib/apt/lists/* diff --git a/8.0/bullseye/root/tmp/setup/sqlsrv-extension.sh b/8.0/bullseye/root/tmp/setup/sqlsrv-extension.sh new file mode 100755 index 0000000..64d8ef6 --- /dev/null +++ b/8.0/bullseye/root/tmp/setup/sqlsrv-extension.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +set -e + +if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then + echo "sqlsrv extension not available for ${TARGETPLATFORM} architecture, skipping" + exit 0 +fi + +# Packages for build. +BUILD_PACKAGES="gnupg unixodbc-dev" + +# Packages for sqlsrv runtime. +PACKAGES_SQLSRV="unixodbc" + +# Note: These dependencies must be installed before installing the Microsoft source because there is a package in there +# which breaks the install. +echo "Installing apt dependencies" +apt-get update +apt-get install -y --no-install-recommends apt-transport-https \ + $BUILD_PACKAGES \ + $PACKAGES_SQLSRV + +# Install Microsoft dependencies for sqlsrv +echo "Downloading sqlsrv files" +curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - +# TODO, bullseye should be 11, but the msodbcsql17 package is not available yet, hence using buster (10) one. +curl https://packages.microsoft.com/config/debian/10/prod.list -o /etc/apt/sources.list.d/mssql-release.list +apt-get update + +echo "Install msodbcsql" +ACCEPT_EULA=Y apt-get install -y msodbcsql17 + +ln -fsv /opt/mssql-tools/bin/* /usr/bin + +# Need 5.9.0preview1 (or later) for PHP 8.0 support +pecl install sqlsrv-5.10.0 +docker-php-ext-enable sqlsrv + +# Keep our image size down.. +pecl clear-cache +apt-get remove --purge -y $BUILD_PACKAGES +apt-get autoremove -y +apt-get clean +rm -rf /var/lib/apt/lists/* diff --git a/8.0/bullseye/root/usr/local/bin/moodle-docker-php-entrypoint b/8.0/bullseye/root/usr/local/bin/moodle-docker-php-entrypoint new file mode 100755 index 0000000..3abc465 --- /dev/null +++ b/8.0/bullseye/root/usr/local/bin/moodle-docker-php-entrypoint @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -Eeo pipefail + +docker_process_init_files() { + local f + for f; do + case "$f" in + *.sh) + # Note: This hack is required for MacOS because the exeute bit is not checked for bind mounts. + # The executable bit is stored, but the test -x flag does not return corretly. + # Copying the file to an alternate file system allows it to be respected. + rm -f /tmp/testscript + cp "$f" /tmp/testscript + if [ -x "/tmp/testscript" ]; then + echo "$0: running $f" + "$f" + else + echo "$0: sourcing $f" + . "$f" + fi + ;; + *.ini) + echo "$0: copying $f into /usr/local/etc/php/conf.d/" + cp "$f" /usr/local/etc/php/conf.d/ + ;; + esac + done +} + +echo "Running entrypoint files from /docker-entrypoint.d/*" +docker_process_init_files /docker-entrypoint.d/* +echo + +echo "Starting docker-php-entrypoint with $@" +source /usr/local/bin/docker-php-entrypoint +echo diff --git a/8.0/bullseye/root/usr/local/etc/php/conf.d/docker-php-moodle.ini b/8.0/bullseye/root/usr/local/etc/php/conf.d/docker-php-moodle.ini new file mode 100644 index 0000000..c5675bf --- /dev/null +++ b/8.0/bullseye/root/usr/local/etc/php/conf.d/docker-php-moodle.ini @@ -0,0 +1,6 @@ +; CONFIGURATION SETTINGS REQUIRED BY MOODLE + +; How many GET/POST/COOKIE input variables may be accepted +; See MDL-71390 for more info. This is the recommended / required +; value to support sites having 1000 courses, activities, users.... +max_input_vars = 5000 diff --git a/8.0/bullseye/tests/docker-entrypoint.d/20-example.ini b/8.0/bullseye/tests/docker-entrypoint.d/20-example.ini new file mode 100644 index 0000000..ec45086 --- /dev/null +++ b/8.0/bullseye/tests/docker-entrypoint.d/20-example.ini @@ -0,0 +1,2 @@ +; Test file which disable file uploads. +file_uploads = Off diff --git a/8.0/bullseye/tests/docker-entrypoint.d/30-sourced.sh b/8.0/bullseye/tests/docker-entrypoint.d/30-sourced.sh new file mode 100644 index 0000000..86a6286 --- /dev/null +++ b/8.0/bullseye/tests/docker-entrypoint.d/30-sourced.sh @@ -0,0 +1,10 @@ +# This file should not have a shbang! as it is expected to be sourced. +# It should not be executable either. + +mkdir -p /var/www/data + +(return 0 2>/dev/null) && sourced=1 || sourced=0 + +if [[ $sourced -eq 1 ]]; then + echo "Sourced" >> /var/www/data/sourced.txt +fi diff --git a/8.0/bullseye/tests/docker-entrypoint.d/40-exec.sh b/8.0/bullseye/tests/docker-entrypoint.d/40-exec.sh new file mode 100755 index 0000000..d924fc6 --- /dev/null +++ b/8.0/bullseye/tests/docker-entrypoint.d/40-exec.sh @@ -0,0 +1,10 @@ +# This file should not have a shbang! as it is expected to be sourced. +# It should not be executable either. + +mkdir -p /var/www/data + +(return 0 2>/dev/null) && sourced=1 || sourced=0 + +if [[ $sourced -eq 0 ]]; then + echo "Executed" >> /var/www/data/executed.txt +fi diff --git a/8.0/bullseye/tests/fixtures/check-entrypoint-scripts.php b/8.0/bullseye/tests/fixtures/check-entrypoint-scripts.php new file mode 100644 index 0000000..aa06d16 --- /dev/null +++ b/8.0/bullseye/tests/fixtures/check-entrypoint-scripts.php @@ -0,0 +1,27 @@ + Date: Sat, 18 Mar 2023 14:27:23 +0800 Subject: [PATCH 7/7] Build all images in one pipeline --- .github/workflows/test_buildx_and_publish.yml | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_buildx_and_publish.yml b/.github/workflows/test_buildx_and_publish.yml index 64c8e14..8ce7b43 100644 --- a/.github/workflows/test_buildx_and_publish.yml +++ b/.github/workflows/test_buildx_and_publish.yml @@ -14,19 +14,25 @@ env: jobs: Test: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # Note: Numbers should be quoted, especially if they're a .0 release because they'll be formatted as an int. + phpversion: ["8.0", "8.1", "8.2"] + osversion: [buster, bullseye] steps: - name: Checkout uses: actions/checkout@v3 - name: Build image run: | - docker build . -t moodle-php-apache + docker build ${{matrix.phpversion}}/${{matrix.osversion}} -t moodle-php-apache - name: Run tests run: | docker run --name test0 -d -p 8000:80 \ - -v $PWD/tests/fixtures:/var/www/html \ - -v $PWD/tests/docker-entrypoint.d:/docker-entrypoint.d \ + -v $PWD/${{matrix.phpversion}}/${{matrix.osversion}}/tests/fixtures:/var/www/html \ + -v $PWD/${{matrix.phpversion}}/${{matrix.osversion}}/tests/docker-entrypoint.d:/docker-entrypoint.d \ moodle-php-apache docker exec test0 php /var/www/html/test.php docker exec test0 php /var/www/html/check-ini.php @@ -49,6 +55,13 @@ jobs: # Requires Test to pass needs: Test runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # This matrix must match the matrix defined in the Test. + # Note: Numbers should be quoted, especially if they're a .0 release because they'll be formatted as an int. + phpversion: ["8.0", "8.1", "8.2"] + osversion: [buster, bullseye] steps: - name: Checkout uses: actions/checkout@v3 @@ -93,7 +106,7 @@ jobs: - name: Build and publish to Docker Hub and Github registries uses: docker/build-push-action@v3 with: - context: . + context: ${{matrix.phpversion}}/${{matrix.osversion}} file: Dockerfile platforms: linux/amd64,linux/arm64 push: true