From c50132a27ac927d4caa23b777f1454eefed4c4ca Mon Sep 17 00:00:00 2001 From: Zoey Date: Wed, 3 May 2023 16:32:24 +0200 Subject: [PATCH 1/4] optimize nextcloud Dockerfile Signed-off-by: Zoey --- Containers/nextcloud/Dockerfile | 131 ++++++++++++-------------------- 1 file changed, 49 insertions(+), 82 deletions(-) diff --git a/Containers/nextcloud/Dockerfile b/Containers/nextcloud/Dockerfile index 0607bb84..9f2691cd 100644 --- a/Containers/nextcloud/Dockerfile +++ b/Containers/nextcloud/Dockerfile @@ -1,6 +1,27 @@ # From https://github.com/nextcloud/docker/blob/master/23/fpm-alpine/Dockerfile FROM php:8.1.19-fpm-alpine3.17 +VOLUME /var/www/html + +ENV PHP_MEMORY_LIMIT 512M +ENV PHP_UPLOAD_LIMIT 10G +ENV PHP_MAX_TIME 3600 + +ENV NEXTCLOUD_VERSION 26.0.2 + +COPY *.sh upgrade.exclude / +COPY config/* /usr/src/nextcloud/config/ + +ENV NEXTCLOUD_UPDATE=1 + +COPY supervisord.conf /supervisord.conf + +COPY --chmod=775 start.sh /start.sh +COPY --chmod=775 notify.sh /notify.sh +COPY --chmod=775 notify-all.sh /notify-all.sh + +VOLUME /mnt/ncdata + # Custom: change id of www-data user as it needs to be the same like on old installations RUN set -ex; \ apk add --no-cache shadow; \ @@ -8,22 +29,14 @@ RUN set -ex; \ groupmod -g 333 xfs; \ usermod -u 333 -g 333 xfs; \ addgroup -g 33 -S www-data; \ - adduser -u 33 -D -S -G www-data www-data - -# entrypoint.sh and cron.sh dependencies -RUN set -ex; \ + adduser -u 33 -D -S -G www-data www-data; \ \ +# entrypoint.sh and cron.sh dependencies apk add --no-cache \ rsync \ - ; - + ; \ # install the PHP extensions we need # see https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html -ENV PHP_MEMORY_LIMIT 512M -ENV PHP_UPLOAD_LIMIT 10G -ENV PHP_MAX_TIME 3600 -RUN set -ex; \ - \ apk add --no-cache --virtual .build-deps \ $PHPIZE_DEPS \ autoconf \ @@ -80,11 +93,11 @@ RUN set -ex; \ | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ )"; \ apk add --virtual .nextcloud-phpext-rundeps $runDeps; \ - apk del .build-deps - + apk del .build-deps; \ + \ # set recommended PHP.ini settings # see https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/server_tuning.html#enable-php-opcache -RUN { \ + { \ echo 'opcache.interned_strings_buffer=32'; \ echo 'opcache.save_comments=1'; \ echo 'opcache.revalidate_freq=60'; \ @@ -104,13 +117,8 @@ RUN { \ \ mkdir /var/www/data; \ chown -R www-data:root /var/www; \ - chmod -R g=u /var/www - -VOLUME /var/www/html - -ENV NEXTCLOUD_VERSION 26.0.2 - -RUN set -ex; \ + chmod -R g=u /var/www; \ + \ apk add --no-cache --virtual .fetch-deps \ bzip2 \ gnupg \ @@ -130,27 +138,16 @@ RUN set -ex; \ mkdir -p /usr/src/nextcloud/data; \ mkdir -p /usr/src/nextcloud/custom_apps; \ chmod +x /usr/src/nextcloud/occ; \ - apk del .fetch-deps - -COPY *.sh upgrade.exclude / -COPY config/* /usr/src/nextcloud/config/ - -ENTRYPOINT ["/entrypoint.sh"] -CMD ["php-fpm"] - -# Template from https://github.com/nextcloud/docker/blob/master/.examples/dockerfiles/full/fpm-alpine/Dockerfile - -RUN set -ex; \ + apk del .fetch-deps; \ \ +# Template from https://github.com/nextcloud/docker/blob/master/.examples/dockerfiles/full/fpm-alpine/Dockerfile apk add --no-cache \ ffmpeg \ procps \ samba-client \ supervisor \ # libreoffice \ - ; - -RUN set -ex; \ + ; \ \ apk add --no-cache --virtual .build-deps \ $PHPIZE_DEPS \ @@ -178,21 +175,12 @@ RUN set -ex; \ | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ )"; \ apk add --virtual .nextcloud-phpext-rundeps $runDeps; \ - apk del .build-deps - -RUN mkdir -p \ + apk del .build-deps; \ + \ + mkdir -p \ /var/log/supervisord \ /var/run/supervisord \ -; - -COPY supervisord.conf / - -ENV NEXTCLOUD_UPDATE=1 - -CMD ["/usr/bin/supervisord", "-c", "/supervisord.conf"] - -# Custom: -RUN set -ex; \ + ; \ \ apk add --no-cache \ bash \ @@ -206,60 +194,39 @@ RUN set -ex; \ sudo \ grep \ nodejs \ - coreutils; - -RUN set -ex; \ + coreutils; \ + \ grep -q '^pm = dynamic' /usr/local/etc/php-fpm.d/www.conf; \ sed -i 's/^pm = dynamic/pm = ondemand/' /usr/local/etc/php-fpm.d/www.conf; \ sed -i 's/^pm.max_children =.*/pm.max_children = 80/' /usr/local/etc/php-fpm.d/www.conf; \ sed -i 's/^pm.start_servers =.*/pm.start_servers = 2/' /usr/local/etc/php-fpm.d/www.conf; \ sed -i 's/^pm.min_spare_servers =.*/pm.min_spare_servers = 1/' /usr/local/etc/php-fpm.d/www.conf; \ sed -i 's/^pm.max_spare_servers =.*/pm.max_spare_servers = 3/' /usr/local/etc/php-fpm.d/www.conf; \ - sed -i 's|access.log = /proc/self/fd/2|access.log = /proc/self/fd/1|' /usr/local/etc/php-fpm.d/docker.conf - -RUN set -ex; \ + sed -i 's|access.log = /proc/self/fd/2|access.log = /proc/self/fd/1|' /usr/local/etc/php-fpm.d/docker.conf; \ + \ rm -rf /tmp/nextcloud-aio && \ mkdir -p /tmp/nextcloud-aio && \ cd /tmp/nextcloud-aio && \ git clone https://github.com/nextcloud-releases/all-in-one.git --depth 1 .; \ mkdir -p /usr/src/nextcloud/apps/nextcloud-aio; \ - cp -r ./app/* /usr/src/nextcloud/apps/nextcloud-aio/ - -RUN set -ex; \ + cp -r ./app/* /usr/src/nextcloud/apps/nextcloud-aio/; \ + \ chown www-data:root -R /usr/src && \ chown www-data:root -R /usr/local/etc/php/conf.d && \ chown www-data:root -R /usr/local/etc/php-fpm.d && \ - rm -r /usr/src/nextcloud/apps/updatenotification - -COPY start.sh / -COPY notify.sh / -COPY notify-all.sh / -RUN set -ex; \ - chmod +x /start.sh && \ - chmod +x /entrypoint.sh && \ - chmod +r /upgrade.exclude && \ - chmod +x /cron.sh && \ - chmod +x /notify.sh && \ - chmod +x /notify-all.sh && \ - chmod +x /run-exec-commands.sh && \ - chmod +x /healthcheck.sh - -RUN set -ex; \ - mkdir /mnt/ncdata; \ - chown www-data:www-data /mnt/ncdata; - -VOLUME /mnt/ncdata - -RUN set -ex; \ + rm -r /usr/src/nextcloud/apps/updatenotification; \ + chown www-data:www-data /mnt/ncdata; \ + \ mkdir -p /nc-updater; \ chown -R www-data:www-data /nc-updater; \ - chmod -R 770 /nc-updater - + chmod -R 770 /nc-updater; \ + \ # Give root a random password -RUN echo "root:$(openssl rand -base64 12)" | chpasswd + echo "root:$(openssl rand -base64 12)" | chpasswd USER root ENTRYPOINT ["/start.sh"] +CMD ["/usr/bin/supervisord", "-c", "/supervisord.conf"] HEALTHCHECK CMD sudo -E -u www-data bash /healthcheck.sh LABEL com.centurylinklabs.watchtower.monitor-only="true" From d18b58d2a1ce6d3074aa9ab11e3cfc7a79cb7791 Mon Sep 17 00:00:00 2001 From: Simon L Date: Fri, 26 May 2023 14:47:02 +0200 Subject: [PATCH 2/4] re-order some things Signed-off-by: Simon L --- Containers/nextcloud/Dockerfile | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/Containers/nextcloud/Dockerfile b/Containers/nextcloud/Dockerfile index 9f2691cd..99c6d3f4 100644 --- a/Containers/nextcloud/Dockerfile +++ b/Containers/nextcloud/Dockerfile @@ -1,26 +1,18 @@ # From https://github.com/nextcloud/docker/blob/master/23/fpm-alpine/Dockerfile FROM php:8.1.19-fpm-alpine3.17 -VOLUME /var/www/html - ENV PHP_MEMORY_LIMIT 512M ENV PHP_UPLOAD_LIMIT 10G ENV PHP_MAX_TIME 3600 - ENV NEXTCLOUD_VERSION 26.0.2 -COPY *.sh upgrade.exclude / +COPY --chmod=775 *.sh / +COPY upgrade.exclude /upgrade.exclude COPY config/* /usr/src/nextcloud/config/ - -ENV NEXTCLOUD_UPDATE=1 - COPY supervisord.conf /supervisord.conf -COPY --chmod=775 start.sh /start.sh -COPY --chmod=775 notify.sh /notify.sh -COPY --chmod=775 notify-all.sh /notify-all.sh - VOLUME /mnt/ncdata +VOLUME /var/www/html # Custom: change id of www-data user as it needs to be the same like on old installations RUN set -ex; \ From 675de94bcfdfab05f1ac9aa46170c2f75a1d6469 Mon Sep 17 00:00:00 2001 From: Simon L Date: Tue, 30 May 2023 11:57:10 +0200 Subject: [PATCH 3/4] adjust review Signed-off-by: Simon L --- Containers/nextcloud/Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Containers/nextcloud/Dockerfile b/Containers/nextcloud/Dockerfile index 99c6d3f4..dd749aa8 100644 --- a/Containers/nextcloud/Dockerfile +++ b/Containers/nextcloud/Dockerfile @@ -7,8 +7,8 @@ ENV PHP_MAX_TIME 3600 ENV NEXTCLOUD_VERSION 26.0.2 COPY --chmod=775 *.sh / -COPY upgrade.exclude /upgrade.exclude -COPY config/* /usr/src/nextcloud/config/ +COPY --chmod=774 upgrade.exclude /upgrade.exclude +COPY config/*.php / COPY supervisord.conf /supervisord.conf VOLUME /mnt/ncdata @@ -130,6 +130,8 @@ RUN set -ex; \ mkdir -p /usr/src/nextcloud/data; \ mkdir -p /usr/src/nextcloud/custom_apps; \ chmod +x /usr/src/nextcloud/occ; \ + mkdir -p /usr/src/nextcloud/config; \ + mv /*.php /usr/src/nextcloud/config/; \ apk del .fetch-deps; \ \ # Template from https://github.com/nextcloud/docker/blob/master/.examples/dockerfiles/full/fpm-alpine/Dockerfile From c854e681883391a63f368ec386b03b2c80d709f9 Mon Sep 17 00:00:00 2001 From: Simon L Date: Tue, 30 May 2023 12:10:34 +0200 Subject: [PATCH 4/4] fix build Signed-off-by: Simon L --- Containers/nextcloud/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Containers/nextcloud/Dockerfile b/Containers/nextcloud/Dockerfile index dd749aa8..3e6e115e 100644 --- a/Containers/nextcloud/Dockerfile +++ b/Containers/nextcloud/Dockerfile @@ -107,7 +107,7 @@ RUN set -ex; \ echo 'max_input_time=${PHP_MAX_TIME}'; \ } > /usr/local/etc/php/conf.d/nextcloud.ini; \ \ - mkdir /var/www/data; \ + mkdir -p /var/www/data; \ chown -R www-data:root /var/www; \ chmod -R g=u /var/www; \ \ @@ -209,7 +209,6 @@ RUN set -ex; \ chown www-data:root -R /usr/local/etc/php/conf.d && \ chown www-data:root -R /usr/local/etc/php-fpm.d && \ rm -r /usr/src/nextcloud/apps/updatenotification; \ - chown www-data:www-data /mnt/ncdata; \ \ mkdir -p /nc-updater; \ chown -R www-data:www-data /nc-updater; \