Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

One branch to rule them all #169

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions .github/workflows/test_buildx_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions 8.0/bullseye/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
30 changes: 30 additions & 0 deletions 8.0/bullseye/root/tmp/setup/oci8-extension.sh
Original file line number Diff line number Diff line change
@@ -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
82 changes: 82 additions & 0 deletions 8.0/bullseye/root/tmp/setup/php-extensions.sh
Original file line number Diff line number Diff line change
@@ -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/*
45 changes: 45 additions & 0 deletions 8.0/bullseye/root/tmp/setup/sqlsrv-extension.sh
Original file line number Diff line number Diff line change
@@ -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/*
File renamed without changes.
54 changes: 54 additions & 0 deletions 8.0/bullseye/tests/fixtures/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

$requiredextensions = [
'apcu',
'exif',
'gd',
'igbinary',
'intl',
'ldap',
'memcached',
'mongodb',
'mysqli',
'oci8',
'pgsql',
'redis',
'soap',
'sodium',
'solr',
'sqlsrv',
'uuid',
'xsl',
'xmlrpc',
'zip',
];

$buffer = '';;
$missing = [];
foreach($requiredextensions as $ext) {
if (!extension_loaded($ext)) {
$missing[] = $ext;
}
}

$locale = 'en_AU.UTF-8';
if (setlocale(LC_TIME, $locale) === false) {
$missing[] = $locale;
}

if (php_sapi_name() === 'cli') {
if (empty($missing)) {
echo "OK\n";
exit(0);
}
echo 'Missing: '.join(', ', $missing)."\n";
exit(1);
} else {
if (empty($missing)) {
header('HTTP/1.1 200 - OK');
exit(0);
} else {
header('HTTP/1.1 500 - Problem PHP extension missing: ' . join(', ', $missing));
exit(1);
}
}
52 changes: 52 additions & 0 deletions 8.0/buster/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Loading