diff --git a/.travis.yml b/.travis.yml index fe98ad0..3ea7128 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: bash services: docker env: + - VERSION=12.0 VARIANT=fpm + - VERSION=12.0 VARIANT=apache - VERSION=11.0 VARIANT=fpm - VERSION=11.0 VARIANT=apache - VERSION=10.0 VARIANT=fpm diff --git a/12.0/apache/Dockerfile b/12.0/apache/Dockerfile new file mode 100644 index 0000000..1c2a2fd --- /dev/null +++ b/12.0/apache/Dockerfile @@ -0,0 +1,74 @@ +FROM php:7.1-apache + +RUN apt-get update && apt-get install -y \ + rsync \ + bzip2 \ + libcurl4-openssl-dev \ + libfreetype6-dev \ + libicu-dev \ + libjpeg-dev \ + libldap2-dev \ + libmcrypt-dev \ + libmemcached-dev \ + libpng12-dev \ + libpq-dev \ + libxml2-dev \ + && rm -rf /var/lib/apt/lists/* + +# https://docs.nextcloud.com/server/9/admin_manual/installation/source_installation.html +RUN docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \ + && docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu \ + && docker-php-ext-install gd exif intl mbstring mcrypt ldap mysqli opcache pdo_mysql pdo_pgsql pgsql zip + +# set recommended PHP.ini settings +# see https://secure.php.net/manual/en/opcache.installation.php +RUN { \ + echo 'opcache.memory_consumption=128'; \ + echo 'opcache.interned_strings_buffer=8'; \ + echo 'opcache.max_accelerated_files=4000'; \ + echo 'opcache.revalidate_freq=60'; \ + echo 'opcache.fast_shutdown=1'; \ + echo 'opcache.enable_cli=1'; \ + } > /usr/local/etc/php/conf.d/opcache-recommended.ini +RUN a2enmod rewrite + +# PECL extensions +RUN set -ex \ + && pecl install APCu-5.1.8 \ + && pecl install memcached-3.0.2 \ + && pecl install redis-3.1.1 \ + && docker-php-ext-enable apcu redis memcached +RUN a2enmod rewrite + +ENV NEXTCLOUD_VERSION 12.0.0 +VOLUME /var/www/html + +RUN curl -fsSL -o nextcloud.tar.bz2 \ + "https://download.nextcloud.com/server/releases/nextcloud-${NEXTCLOUD_VERSION}.tar.bz2" \ + && curl -fsSL -o nextcloud.tar.bz2.asc \ + "https://download.nextcloud.com/server/releases/nextcloud-${NEXTCLOUD_VERSION}.tar.bz2.asc" \ + && export GNUPGHOME="$(mktemp -d)" \ +# gpg key from https://nextcloud.com/nextcloud.asc + && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 28806A878AE423A28372792ED75899B9A724937A \ + && gpg --batch --verify nextcloud.tar.bz2.asc nextcloud.tar.bz2 \ + && rm -r "$GNUPGHOME" nextcloud.tar.bz2.asc \ + && tar -xjf nextcloud.tar.bz2 -C /usr/src/ \ + && rm nextcloud.tar.bz2 \ + && rm -rf /usr/src/nextcloud/updater \ + # https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#setting-strong-directory-permissions + && mkdir -p /usr/src/nextcloud/data \ + && mkdir -p /usr/src/nextcloud/custom_apps \ + && find /usr/src/nextcloud/ -type f -print0 | xargs -0 chmod 0640 \ + && find /usr/src/nextcloud/ -type d -print0 | xargs -0 chmod 0750 \ + && chown -R root:www-data /usr/src/nextcloud/ \ + && chown -R www-data:www-data /usr/src/nextcloud/custom_apps/ \ + && chown -R www-data:www-data /usr/src/nextcloud/config/ \ + && chown -R www-data:www-data /usr/src/nextcloud/data/ \ + && chown -R www-data:www-data /usr/src/nextcloud/themes/ \ + && chmod +x /usr/src/nextcloud/occ + +COPY docker-entrypoint.sh /entrypoint.sh +COPY apps.config.php /usr/src/nextcloud/config/apps.config.php + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["apache2-foreground"] diff --git a/12.0/apache/apps.config.php b/12.0/apache/apps.config.php new file mode 100644 index 0000000..a4bed83 --- /dev/null +++ b/12.0/apache/apps.config.php @@ -0,0 +1,15 @@ + array ( + 0 => array ( + "path" => OC::$SERVERROOT."/apps", + "url" => "/apps", + "writable" => false, + ), + 1 => array ( + "path" => OC::$SERVERROOT."/custom_apps", + "url" => "/custom_apps", + "writable" => true, + ), + ), +); diff --git a/12.0/apache/docker-entrypoint.sh b/12.0/apache/docker-entrypoint.sh new file mode 100755 index 0000000..b1265d3 --- /dev/null +++ b/12.0/apache/docker-entrypoint.sh @@ -0,0 +1,54 @@ +#!/bin/bash +set -e + +# version_greater A B returns whether A > B +function version_greater() { + [[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]]; +} + +installed_version="0.0.0~unknown" +if [ -f /var/www/html/version.php ]; then + installed_version=$(php -r 'require "/var/www/html/version.php"; echo "$OC_VersionString";') +fi +image_version=$(php -r 'require "/usr/src/nextcloud/version.php"; echo "$OC_VersionString";') + +if version_greater "$installed_version" "$image_version"; then + echo "Can't start Nextcloud because the version of the data ($installed_version) is higher than the docker image version ($image_version) and downgrading is not supported. Are you sure you have pulled the newest image version?" + exit 1 +fi + +if version_greater "$image_version" "$installed_version"; then + if [ "$installed_version" != "0.0.0~unknown" ]; then + su - www-data -s /bin/bash -c 'php /var/www/html/occ app:list' > /tmp/list_before + fi + + rsync -a --delete --exclude /config/ --exclude /data/ --exclude /custom_apps/ --exclude /themes/ /usr/src/nextcloud/ /var/www/html/ + + if [ ! -d /var/www/html/config ]; then + cp -arT /usr/src/nextcloud/config /var/www/html/config + fi + + if [ ! -d /var/www/html/data ]; then + cp -arT /usr/src/nextcloud/data /var/www/html/data + fi + + if [ ! -d /var/www/html/custom_apps ]; then + cp -arT /usr/src/nextcloud/custom_apps /var/www/html/custom_apps + cp -a /usr/src/nextcloud/config/apps.config.php /var/www/html/config/apps.config.php + fi + + if [ ! -d /var/www/html/themes ]; then + cp -arT /usr/src/nextcloud/themes /var/www/html/themes + fi + + if [ "$installed_version" != "0.0.0~unknown" ]; then + su - www-data -s /bin/bash -c 'php /var/www/html/occ upgrade --no-app-disable' + + su - www-data -s /bin/bash -c 'php /var/www/html/occ app:list' > /tmp/list_after + echo "The following apps have beed disabled:" + diff <(sed -n "/Enabled:/,/Disabled:/p" /tmp/list_before) <(sed -n "/Enabled:/,/Disabled:/p" /tmp/list_after) | grep '<' | cut -d- -f2 | cut -d: -f1 + rm -f /tmp/list_before /tmp/list_after + fi +fi + +exec "$@" diff --git a/12.0/fpm/Dockerfile b/12.0/fpm/Dockerfile new file mode 100644 index 0000000..8ae3663 --- /dev/null +++ b/12.0/fpm/Dockerfile @@ -0,0 +1,72 @@ +FROM php:7.1-fpm + +RUN apt-get update && apt-get install -y \ + rsync \ + bzip2 \ + libcurl4-openssl-dev \ + libfreetype6-dev \ + libicu-dev \ + libjpeg-dev \ + libldap2-dev \ + libmcrypt-dev \ + libmemcached-dev \ + libpng12-dev \ + libpq-dev \ + libxml2-dev \ + && rm -rf /var/lib/apt/lists/* + +# https://docs.nextcloud.com/server/9/admin_manual/installation/source_installation.html +RUN docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \ + && docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu \ + && docker-php-ext-install gd exif intl mbstring mcrypt ldap mysqli opcache pdo_mysql pdo_pgsql pgsql zip + +# set recommended PHP.ini settings +# see https://secure.php.net/manual/en/opcache.installation.php +RUN { \ + echo 'opcache.memory_consumption=128'; \ + echo 'opcache.interned_strings_buffer=8'; \ + echo 'opcache.max_accelerated_files=4000'; \ + echo 'opcache.revalidate_freq=60'; \ + echo 'opcache.fast_shutdown=1'; \ + echo 'opcache.enable_cli=1'; \ + } > /usr/local/etc/php/conf.d/opcache-recommended.ini + +# PECL extensions +RUN set -ex \ + && pecl install APCu-5.1.8 \ + && pecl install memcached-3.0.2 \ + && pecl install redis-3.1.1 \ + && docker-php-ext-enable apcu redis memcached + +ENV NEXTCLOUD_VERSION 12.0.0 +VOLUME /var/www/html + +RUN curl -fsSL -o nextcloud.tar.bz2 \ + "https://download.nextcloud.com/server/releases/nextcloud-${NEXTCLOUD_VERSION}.tar.bz2" \ + && curl -fsSL -o nextcloud.tar.bz2.asc \ + "https://download.nextcloud.com/server/releases/nextcloud-${NEXTCLOUD_VERSION}.tar.bz2.asc" \ + && export GNUPGHOME="$(mktemp -d)" \ +# gpg key from https://nextcloud.com/nextcloud.asc + && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 28806A878AE423A28372792ED75899B9A724937A \ + && gpg --batch --verify nextcloud.tar.bz2.asc nextcloud.tar.bz2 \ + && rm -r "$GNUPGHOME" nextcloud.tar.bz2.asc \ + && tar -xjf nextcloud.tar.bz2 -C /usr/src/ \ + && rm nextcloud.tar.bz2 \ + && rm -rf /usr/src/nextcloud/updater \ + # https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#setting-strong-directory-permissions + && mkdir -p /usr/src/nextcloud/data \ + && mkdir -p /usr/src/nextcloud/custom_apps \ + && find /usr/src/nextcloud/ -type f -print0 | xargs -0 chmod 0640 \ + && find /usr/src/nextcloud/ -type d -print0 | xargs -0 chmod 0750 \ + && chown -R root:www-data /usr/src/nextcloud/ \ + && chown -R www-data:www-data /usr/src/nextcloud/custom_apps/ \ + && chown -R www-data:www-data /usr/src/nextcloud/config/ \ + && chown -R www-data:www-data /usr/src/nextcloud/data/ \ + && chown -R www-data:www-data /usr/src/nextcloud/themes/ \ + && chmod +x /usr/src/nextcloud/occ + +COPY docker-entrypoint.sh /entrypoint.sh +COPY apps.config.php /usr/src/nextcloud/config/apps.config.php + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["php-fpm"] diff --git a/12.0/fpm/apps.config.php b/12.0/fpm/apps.config.php new file mode 100644 index 0000000..a4bed83 --- /dev/null +++ b/12.0/fpm/apps.config.php @@ -0,0 +1,15 @@ + array ( + 0 => array ( + "path" => OC::$SERVERROOT."/apps", + "url" => "/apps", + "writable" => false, + ), + 1 => array ( + "path" => OC::$SERVERROOT."/custom_apps", + "url" => "/custom_apps", + "writable" => true, + ), + ), +); diff --git a/12.0/fpm/docker-entrypoint.sh b/12.0/fpm/docker-entrypoint.sh new file mode 100755 index 0000000..b1265d3 --- /dev/null +++ b/12.0/fpm/docker-entrypoint.sh @@ -0,0 +1,54 @@ +#!/bin/bash +set -e + +# version_greater A B returns whether A > B +function version_greater() { + [[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]]; +} + +installed_version="0.0.0~unknown" +if [ -f /var/www/html/version.php ]; then + installed_version=$(php -r 'require "/var/www/html/version.php"; echo "$OC_VersionString";') +fi +image_version=$(php -r 'require "/usr/src/nextcloud/version.php"; echo "$OC_VersionString";') + +if version_greater "$installed_version" "$image_version"; then + echo "Can't start Nextcloud because the version of the data ($installed_version) is higher than the docker image version ($image_version) and downgrading is not supported. Are you sure you have pulled the newest image version?" + exit 1 +fi + +if version_greater "$image_version" "$installed_version"; then + if [ "$installed_version" != "0.0.0~unknown" ]; then + su - www-data -s /bin/bash -c 'php /var/www/html/occ app:list' > /tmp/list_before + fi + + rsync -a --delete --exclude /config/ --exclude /data/ --exclude /custom_apps/ --exclude /themes/ /usr/src/nextcloud/ /var/www/html/ + + if [ ! -d /var/www/html/config ]; then + cp -arT /usr/src/nextcloud/config /var/www/html/config + fi + + if [ ! -d /var/www/html/data ]; then + cp -arT /usr/src/nextcloud/data /var/www/html/data + fi + + if [ ! -d /var/www/html/custom_apps ]; then + cp -arT /usr/src/nextcloud/custom_apps /var/www/html/custom_apps + cp -a /usr/src/nextcloud/config/apps.config.php /var/www/html/config/apps.config.php + fi + + if [ ! -d /var/www/html/themes ]; then + cp -arT /usr/src/nextcloud/themes /var/www/html/themes + fi + + if [ "$installed_version" != "0.0.0~unknown" ]; then + su - www-data -s /bin/bash -c 'php /var/www/html/occ upgrade --no-app-disable' + + su - www-data -s /bin/bash -c 'php /var/www/html/occ app:list' > /tmp/list_after + echo "The following apps have beed disabled:" + diff <(sed -n "/Enabled:/,/Disabled:/p" /tmp/list_before) <(sed -n "/Enabled:/,/Disabled:/p" /tmp/list_after) | grep '<' | cut -d- -f2 | cut -d: -f1 + rm -f /tmp/list_before /tmp/list_after + fi +fi + +exec "$@" diff --git a/update.sh b/update.sh index 8fd447e..b8afc6a 100755 --- a/update.sh +++ b/update.sh @@ -11,9 +11,10 @@ function version_greater_or_equal() { [[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" || "$1" == "$2" ]]; } -latests=( $(curl -sSL 'https://nextcloud.com/changelog/' |tac|tac| \ - grep -o "\(Version\|Release\)\s\+[[:digit:]]\+\(\.[[:digit:]]\+\)\+" | \ - awk '{ print $2 }' | sort -V ) ) +latests=( $(curl -sSL 'https://download.nextcloud.com/server/releases/' |tac|tac| \ + grep -oE '>nextcloud-[[:digit:]]+(.[[:digit:]]+)+\.tar\.bz2<' | \ + grep -oE '[[:digit:]]+(.[[:digit:]]+)+' | \ + sort -V ) ) travisEnv= for latest in "${latests[@]}"; do