diff --git a/.travis.yml b/.travis.yml index d7e2048..fec49af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,16 +3,16 @@ services: docker env: - VARIANT=php5.6/apache - - VARIANT=php7.0/apache - - VARIANT=php7.1/apache - - VARIANT=php7.2/apache - VARIANT=php5.6/fpm - - VARIANT=php7.0/fpm - - VARIANT=php7.1/fpm - - VARIANT=php7.2/fpm - VARIANT=php5.6/fpm-alpine + - VARIANT=php7.0/apache + - VARIANT=php7.0/fpm - VARIANT=php7.0/fpm-alpine + - VARIANT=php7.1/apache + - VARIANT=php7.1/fpm - VARIANT=php7.1/fpm-alpine + - VARIANT=php7.2/apache + - VARIANT=php7.2/fpm - VARIANT=php7.2/fpm-alpine install: diff --git a/Dockerfile-alpine.template b/Dockerfile-alpine.template new file mode 100644 index 0000000..2f1de78 --- /dev/null +++ b/Dockerfile-alpine.template @@ -0,0 +1,80 @@ +FROM php:%%PHP_VERSION%%-%%VARIANT%% +LABEL maintainer="Michael Babker (@mbabker)" + +# Disable remote database security requirements. +ENV JOOMLA_INSTALLATION_DISABLE_LOCALHOST_CHECK=1 + +# entrypoint.sh dependencies +RUN apk add --no-cache \ + bash + +# Install PHP extensions +RUN set -ex; \ + \ + apk add --no-cache --virtual .build-deps \ + $PHPIZE_DEPS \ + autoconf \ + bzip2-dev \ + libjpeg-turbo-dev \ + libmcrypt-dev \ + libmemcached-dev \ + libpng-dev \ + openldap-dev \ + pcre-dev \ + postgresql-dev \ + ; \ + \ + docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \ + docker-php-ext-configure ldap; \ + docker-php-ext-install \ + bz2 \ + gd \ + ldap \ + mcrypt \ + mysqli \ + pdo_mysql \ + pdo_pgsql \ + pgsql \ + zip \ + ; \ + \ +# pecl will claim success even if one install fails, so we need to perform each install separately + pecl install APCu-%%APCU_VERSION%%; \ + pecl install memcached-%%MEMCACHED_VERSION%%; \ + pecl install redis-%%REDIS_VERSION%%; \ + \ + docker-php-ext-enable \ + apcu \ + memcached \ + redis \ + ; \ + \ + runDeps="$( \ + scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \ + | tr ',' '\n' \ + | sort -u \ + | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ + )"; \ + apk add --virtual .joomla-phpext-rundeps $runDeps; \ + apk del .build-deps + +VOLUME /var/www/html + +# Define Joomla version and expected SHA1 signature +ENV JOOMLA_VERSION %%VERSION%% +ENV JOOMLA_SHA1 %%SHA1%% + +# Download package and extract to web volume +RUN curl -o joomla.tar.bz2 -SL https://github.com/joomla/joomla-cms/releases/download/${JOOMLA_VERSION}/Joomla_${JOOMLA_VERSION}-Stable-Full_Package.tar.bz2 \ + && echo "$JOOMLA_SHA1 *joomla.tar.bz2" | sha1sum -c - \ + && mkdir /usr/src/joomla \ + && tar -xf joomla.tar.bz2 -C /usr/src/joomla \ + && rm joomla.tar.bz2 \ + && chown -R www-data:www-data /usr/src/joomla + +# Copy init scripts and custom .htaccess +COPY docker-entrypoint.sh /entrypoint.sh +COPY makedb.php /makedb.php + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["%%CMD%%"] diff --git a/Dockerfile-debian.template b/Dockerfile-debian.template new file mode 100644 index 0000000..924e12a --- /dev/null +++ b/Dockerfile-debian.template @@ -0,0 +1,82 @@ +FROM php:%%PHP_VERSION%%-%%VARIANT%% +LABEL maintainer="Michael Babker (@mbabker)" + +# Disable remote database security requirements. +ENV JOOMLA_INSTALLATION_DISABLE_LOCALHOST_CHECK=1 +%%VARIANT_EXTRAS%% +# Install PHP extensions +RUN set -ex; \ + \ + savedAptMark="$(apt-mark showmanual)"; \ + \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + libbz2-dev \ + libjpeg-dev \ + libldap2-dev \ + libmcrypt-dev \ + libmemcached-dev \ + libpng-dev \ + libpq-dev \ + ; \ + \ + docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \ + debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \ + docker-php-ext-configure ldap --with-libdir="lib/$debMultiarch"; \ + docker-php-ext-install \ + bz2 \ + gd \ + ldap \ + mcrypt \ + mysqli \ + pdo_mysql \ + pdo_pgsql \ + pgsql \ + zip \ + ; \ + \ +# pecl will claim success even if one install fails, so we need to perform each install separately + pecl install APCu-%%APCU_VERSION%%; \ + pecl install memcached-%%MEMCACHED_VERSION%%; \ + pecl install redis-%%REDIS_VERSION%%; \ + \ + docker-php-ext-enable \ + apcu \ + memcached \ + redis \ + ; \ + \ +# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies + apt-mark auto '.*' > /dev/null; \ + apt-mark manual $savedAptMark; \ + ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \ + | awk '/=>/ { print $3 }' \ + | sort -u \ + | xargs -r dpkg-query -S \ + | cut -d: -f1 \ + | sort -u \ + | xargs -rt apt-mark manual; \ + \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ + rm -rf /var/lib/apt/lists/* + +VOLUME /var/www/html + +# Define Joomla version and expected SHA1 signature +ENV JOOMLA_VERSION %%VERSION%% +ENV JOOMLA_SHA1 %%SHA1%% + +# Download package and extract to web volume +RUN curl -o joomla.tar.bz2 -SL https://github.com/joomla/joomla-cms/releases/download/${JOOMLA_VERSION}/Joomla_${JOOMLA_VERSION}-Stable-Full_Package.tar.bz2 \ + && echo "$JOOMLA_SHA1 *joomla.tar.bz2" | sha1sum -c - \ + && mkdir /usr/src/joomla \ + && tar -xf joomla.tar.bz2 -C /usr/src/joomla \ + && rm joomla.tar.bz2 \ + && chown -R www-data:www-data /usr/src/joomla + +# Copy init scripts and custom .htaccess +COPY docker-entrypoint.sh /entrypoint.sh +COPY makedb.php /makedb.php + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["%%CMD%%"] diff --git a/php5.6/fpm-alpine/Dockerfile b/php5.6/fpm-alpine/Dockerfile index b757828..dee9307 100644 --- a/php5.6/fpm-alpine/Dockerfile +++ b/php5.6/fpm-alpine/Dockerfile @@ -12,13 +12,13 @@ RUN apk add --no-cache \ RUN set -ex; \ \ apk add --no-cache --virtual .build-deps \ - alpine-sdk \ + $PHPIZE_DEPS \ autoconf \ bzip2-dev \ libjpeg-turbo-dev \ libmcrypt-dev \ - libpng-dev \ libmemcached-dev \ + libpng-dev \ openldap-dev \ pcre-dev \ postgresql-dev \ diff --git a/php7.0/fpm-alpine/Dockerfile b/php7.0/fpm-alpine/Dockerfile index 04b8b73..95aef81 100644 --- a/php7.0/fpm-alpine/Dockerfile +++ b/php7.0/fpm-alpine/Dockerfile @@ -12,13 +12,13 @@ RUN apk add --no-cache \ RUN set -ex; \ \ apk add --no-cache --virtual .build-deps \ - alpine-sdk \ + $PHPIZE_DEPS \ autoconf \ bzip2-dev \ libjpeg-turbo-dev \ libmcrypt-dev \ - libpng-dev \ libmemcached-dev \ + libpng-dev \ openldap-dev \ pcre-dev \ postgresql-dev \ diff --git a/php7.1/fpm-alpine/Dockerfile b/php7.1/fpm-alpine/Dockerfile index 16f6497..26e5a80 100644 --- a/php7.1/fpm-alpine/Dockerfile +++ b/php7.1/fpm-alpine/Dockerfile @@ -12,13 +12,13 @@ RUN apk add --no-cache \ RUN set -ex; \ \ apk add --no-cache --virtual .build-deps \ - alpine-sdk \ + $PHPIZE_DEPS \ autoconf \ bzip2-dev \ libjpeg-turbo-dev \ libmcrypt-dev \ - libpng-dev \ libmemcached-dev \ + libpng-dev \ openldap-dev \ pcre-dev \ postgresql-dev \ diff --git a/php7.2/fpm-alpine/Dockerfile b/php7.2/fpm-alpine/Dockerfile index bce3438..c9a1eb2 100644 --- a/php7.2/fpm-alpine/Dockerfile +++ b/php7.2/fpm-alpine/Dockerfile @@ -12,12 +12,12 @@ RUN apk add --no-cache \ RUN set -ex; \ \ apk add --no-cache --virtual .build-deps \ - alpine-sdk \ + $PHPIZE_DEPS \ autoconf \ bzip2-dev \ libjpeg-turbo-dev \ - libpng-dev \ libmemcached-dev \ + libpng-dev \ openldap-dev \ pcre-dev \ postgresql-dev \ diff --git a/update.php b/update.php deleted file mode 100644 index b03c78c..0000000 --- a/update.php +++ /dev/null @@ -1,106 +0,0 @@ -getFilename(), 0, 3) === 'php') - { - $phpVersions[] = $dir->getFilename(); - } -} - -foreach ($phpVersions as $phpVersion) -{ - foreach ($platforms as $platform) - { - $dockerfile = __DIR__ . "/$phpVersion/$platform/Dockerfile"; - - $fileContents = file_get_contents($dockerfile); - $fileContents = preg_replace('#ENV JOOMLA_VERSION [^ ]*\n#', "ENV JOOMLA_VERSION $version\n", $fileContents); - $fileContents = preg_replace('#ENV JOOMLA_SHA1 [^ ]*\n#', "ENV JOOMLA_SHA1 $signature\n\n", $fileContents); - - file_put_contents($dockerfile, $fileContents); - - // To make management easier, we use these files for all variants - copy(__DIR__ . '/docker-entrypoint.sh', __DIR__ . "/$phpVersion/$platform/docker-entrypoint.sh"); - copy(__DIR__ . '/makedb.php', __DIR__ . "/$phpVersion/$platform/makedb.php"); - } -} - -echo 'Dockerfile variants updated' . PHP_EOL; diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..3a49fbc --- /dev/null +++ b/update.sh @@ -0,0 +1,87 @@ +#!/bin/bash +set -euo pipefail + +cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" + +phpVersions=( "$@" ) +if [ ${#phpVersions[@]} -eq 0 ]; then + phpVersions=( php*.*/ ) +fi +phpVersions=( "${phpVersions[@]%/}" ) + +current="$(curl -fsSL 'https://downloads.joomla.org/api/v1/latest/cms' | jq -r '.branches[3].version')" +urlVersion=$(echo $current | sed -e 's/\./-/g') +sha1="$(curl -fsSL "https://downloads.joomla.org/api/v1/signatures/cms/$urlVersion" | jq -r --arg file "Joomla_${current}-Stable-Full_Package.tar.bz2" '.[] | .[] | select(.filename == $file).sha1')" + +declare -A variantExtras=( + [apache]='\n# Enable Apache Rewrite Module\nRUN a2enmod rewrite\n' + [fpm]='' + [fpm-alpine]='' +) +declare -A variantCmds=( + [apache]='apache2-foreground' + [fpm]='php-fpm' + [fpm-alpine]='php-fpm' +) +declare -A variantBases=( + [apache]='debian' + [fpm]='debian' + [fpm-alpine]='alpine' +) +declare -A pecl_versions=( + [php5-APCu]='4.0.11' + [php5-memcached]='2.2.0' + [php5-redis]='3.1.6' + [php7-APCu]='5.1.11' + [php7-memcached]='3.0.4' + [php7-redis]='3.1.6' +) + +travisEnv= +for phpVersion in "${phpVersions[@]}"; do + phpVersionDir="$phpVersion" + phpVersion="${phpVersion#php}" + phpMajorVersion=$(echo $phpVersionDir | cut -d. -f1) + + for variant in apache fpm fpm-alpine; do + dir="$phpVersionDir/$variant" + mkdir -p "$dir" + + extras="${variantExtras[$variant]}" + cmd="${variantCmds[$variant]}" + base="${variantBases[$variant]}" + + entrypoint='docker-entrypoint.sh' + + ( + set -x + + sed -r \ + -e 's!%%VERSION%%!'"$current"'!g' \ + -e 's!%%SHA1%%!'"$sha1"'!g' \ + -e 's!%%PHP_VERSION%%!'"$phpVersion"'!g' \ + -e 's!%%VARIANT%%!'"$variant"'!g' \ + -e 's!%%VARIANT_EXTRAS%%!'"$extras"'!g' \ + -e 's!%%APCU_VERSION%%!'"${pecl_versions[$phpMajorVersion-APCu]}"'!g' \ + -e 's!%%MEMCACHED_VERSION%%!'"${pecl_versions[$phpMajorVersion-memcached]}"'!g' \ + -e 's!%%REDIS_VERSION%%!'"${pecl_versions[$phpMajorVersion-redis]}"'!g' \ + -e 's!%%CMD%%!'"$cmd"'!g' \ + "Dockerfile-${base}.template" > "$dir/Dockerfile" + + cp -a "$entrypoint" "$dir/docker-entrypoint.sh" + cp -a "makedb.php" "$dir/makedb.php" + + if [ $phpVersionDir = "php7.2" ]; then + sed \ + -e '/libmcrypt-dev/d' \ + -e '/mcrypt/d' \ + -i $dir/Dockerfile + fi + ) + + travisEnv+='\n - VARIANT='"$dir" + done +done + +travis="$(awk -v 'RS=\n\n' '$1 == "env:" { $0 = "env:'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)" +echo "$travis" > .travis.yml