Merge pull request #317 from linuxserver/internal

Move Nextcloud installation inside container
This commit is contained in:
Eric Nemchik 2023-06-25 12:16:57 -05:00 committed by GitHub
commit 405337b30e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 241 additions and 104 deletions

View File

@ -45,42 +45,54 @@ RUN \
php82-sqlite3 \
php82-sysvsem \
php82-xmlreader \
rsync \
samba-client \
sudo && \
apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing \
php82-pecl-mcrypt && \
echo "**** configure php and nginx for nextcloud ****" && \
echo 'apc.enable_cli=1' >> /etc/php82/conf.d/apcu.ini && \
sed -i \
-e 's/;opcache.enable.*=.*/opcache.enable=1/g' \
-e 's/;opcache.interned_strings_buffer.*=.*/opcache.interned_strings_buffer=16/g' \
-e 's/;opcache.max_accelerated_files.*=.*/opcache.max_accelerated_files=10000/g' \
-e 's/;opcache.memory_consumption.*=.*/opcache.memory_consumption=128/g' \
-e 's/;opcache.save_comments.*=.*/opcache.save_comments=1/g' \
-e 's/;opcache.revalidate_freq.*=.*/opcache.revalidate_freq=1/g' \
-e 's/;always_populate_raw_post_data.*=.*/always_populate_raw_post_data=-1/g' \
-e 's/memory_limit.*=.*128M/memory_limit=512M/g' \
-e 's/max_execution_time.*=.*30/max_execution_time=120/g' \
-e 's/upload_max_filesize.*=.*2M/upload_max_filesize=1024M/g' \
-e 's/post_max_size.*=.*8M/post_max_size=1024M/g' \
-e 's/output_buffering.*=.*/output_buffering=0/g' \
/etc/php82/php.ini && \
sed -i \
'/opcache.enable=1/a opcache.enable_cli=1' \
/etc/php82/php.ini && \
echo "**** configure php-fpm to pass env vars ****" && \
sed -E -i 's/^;?clear_env ?=.*$/clear_env = no/g' /etc/php82/php-fpm.d/www.conf && \
grep -qxF 'clear_env = no' /etc/php82/php-fpm.d/www.conf || echo 'clear_env = no' >> /etc/php82/php-fpm.d/www.conf && \
echo "env[PATH] = /usr/local/bin:/usr/bin:/bin" >> /etc/php82/php-fpm.conf && \
echo "**** set version tag ****" && \
echo "**** configure php for nextcloud ****" && \
{ \
echo 'apc.enable_cli=1'; \
} >> /etc/php82/conf.d/apcu.ini && \
{ \
echo 'opcache.enable=1'; \
echo 'opcache.interned_strings_buffer=32'; \
echo 'opcache.max_accelerated_files=10000'; \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.save_comments=1'; \
echo 'opcache.revalidate_freq=60'; \
echo 'opcache.jit=1255'; \
echo 'opcache.jit_buffer_size=128M'; \
} >> "/etc/php82/conf.d/00_opcache.ini" && \
{ \
echo 'memory_limit=512M'; \
echo 'upload_max_filesize=16G'; \
echo 'post_max_size=16G'; \
echo 'max_input_time=3600'; \
echo 'max_execution_time=3600'; \
echo 'output_buffering=0'; \
echo 'always_populate_raw_post_data=-1'; \
} >> "/etc/php82/conf.d/nextcloud.ini" && \
echo "**** install nextcloud ****" && \
mkdir -p \
/app/www/src/ && \
if [ -z ${NEXTCLOUD_RELEASE+x} ]; then \
NEXTCLOUD_RELEASE=$(curl -sX GET https://api.github.com/repos/nextcloud/server/releases \
| jq -r '.[] | select(.prerelease != true) | .tag_name' \
| sed 's|^v||g' | sort -rV | head -1); \
fi && \
echo "**** download nextcloud ****" && \
curl -o /app/nextcloud.tar.bz2 -L \
curl -o \
/tmp/nextcloud.tar.bz2 -L \
https://download.nextcloud.com/server/releases/nextcloud-${NEXTCLOUD_RELEASE}.tar.bz2 && \
echo "**** test tarball ****" && \
tar xvf /app/nextcloud.tar.bz2 -C \
/tmp && \
tar xf /tmp/nextcloud.tar.bz2 -C \
/app/www/src --strip-components=1 && \
rm -rf /app/www/src/updater && \
mkdir -p /app/www/src/data && \
chmod +x /app/www/src/occ && \
echo "**** cleanup ****" && \
rm -rf \
/tmp/*

View File

@ -45,42 +45,54 @@ RUN \
php82-sqlite3 \
php82-sysvsem \
php82-xmlreader \
rsync \
samba-client \
sudo && \
apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing \
php82-pecl-mcrypt && \
echo "**** configure php and nginx for nextcloud ****" && \
echo 'apc.enable_cli=1' >> /etc/php82/conf.d/apcu.ini && \
sed -i \
-e 's/;opcache.enable.*=.*/opcache.enable=1/g' \
-e 's/;opcache.interned_strings_buffer.*=.*/opcache.interned_strings_buffer=16/g' \
-e 's/;opcache.max_accelerated_files.*=.*/opcache.max_accelerated_files=10000/g' \
-e 's/;opcache.memory_consumption.*=.*/opcache.memory_consumption=128/g' \
-e 's/;opcache.save_comments.*=.*/opcache.save_comments=1/g' \
-e 's/;opcache.revalidate_freq.*=.*/opcache.revalidate_freq=1/g' \
-e 's/;always_populate_raw_post_data.*=.*/always_populate_raw_post_data=-1/g' \
-e 's/memory_limit.*=.*128M/memory_limit=512M/g' \
-e 's/max_execution_time.*=.*30/max_execution_time=120/g' \
-e 's/upload_max_filesize.*=.*2M/upload_max_filesize=1024M/g' \
-e 's/post_max_size.*=.*8M/post_max_size=1024M/g' \
-e 's/output_buffering.*=.*/output_buffering=0/g' \
/etc/php82/php.ini && \
sed -i \
'/opcache.enable=1/a opcache.enable_cli=1' \
/etc/php82/php.ini && \
echo "**** configure php-fpm to pass env vars ****" && \
sed -E -i 's/^;?clear_env ?=.*$/clear_env = no/g' /etc/php82/php-fpm.d/www.conf && \
grep -qxF 'clear_env = no' /etc/php82/php-fpm.d/www.conf || echo 'clear_env = no' >> /etc/php82/php-fpm.d/www.conf && \
echo "env[PATH] = /usr/local/bin:/usr/bin:/bin" >> /etc/php82/php-fpm.conf && \
echo "**** set version tag ****" && \
echo "**** configure php for nextcloud ****" && \
{ \
echo 'apc.enable_cli=1'; \
} >> /etc/php82/conf.d/apcu.ini && \
{ \
echo 'opcache.enable=1'; \
echo 'opcache.interned_strings_buffer=32'; \
echo 'opcache.max_accelerated_files=10000'; \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.save_comments=1'; \
echo 'opcache.revalidate_freq=60'; \
echo 'opcache.jit=1255'; \
echo 'opcache.jit_buffer_size=128M'; \
} >> "/etc/php82/conf.d/00_opcache.ini" && \
{ \
echo 'memory_limit=512M'; \
echo 'upload_max_filesize=16G'; \
echo 'post_max_size=16G'; \
echo 'max_input_time=3600'; \
echo 'max_execution_time=3600'; \
echo 'output_buffering=0'; \
echo 'always_populate_raw_post_data=-1'; \
} >> "/etc/php82/conf.d/nextcloud.ini" && \
echo "**** install nextcloud ****" && \
mkdir -p \
/app/www/src/ && \
if [ -z ${NEXTCLOUD_RELEASE+x} ]; then \
NEXTCLOUD_RELEASE=$(curl -sX GET https://api.github.com/repos/nextcloud/server/releases \
| jq -r '.[] | select(.prerelease != true) | .tag_name' \
| sed 's|^v||g' | sort -rV | head -1); \
fi && \
echo "**** download nextcloud ****" && \
curl -o /app/nextcloud.tar.bz2 -L \
curl -o \
/tmp/nextcloud.tar.bz2 -L \
https://download.nextcloud.com/server/releases/nextcloud-${NEXTCLOUD_RELEASE}.tar.bz2 && \
echo "**** test tarball ****" && \
tar xvf /app/nextcloud.tar.bz2 -C \
/tmp && \
tar xf /tmp/nextcloud.tar.bz2 -C \
/app/www/src --strip-components=1 && \
rm -rf /app/www/src/updater && \
mkdir -p /app/www/src/data && \
chmod +x /app/www/src/occ && \
echo "**** cleanup ****" && \
rm -rf \
/tmp/*

View File

@ -64,21 +64,13 @@ The architectures supported by this image are:
Access the webui at `https://<your-ip>:443`, for more information check out [Nextcloud](https://nextcloud.com/).
Docker image update and recreation of container alone won't update nextcloud version.
### Updating Nextcloud
In order to update nextcloud version, you have two options, firstly make sure you are using the latest docker image,then either
Updating Nextcloud is done by pulling the new image, and recreating the container with it.
1. Perform the in app gui update.
2. Use the CLI version by running `docker exec -it nextcloud updater.phar`
(Both of these are described [here](https://docs.nextcloud.com/server/latest/admin_manual/maintenance/update.html))
It is only possible to upgrade one major version at a time. For example, if you want to upgrade from version 14 to 16, you will have to upgrade from version 14 to 15, then from 15 to 16.
Note: Both `occ` and `updater.phar` can be run without prepending with `sudo -u abc php` or `sudo -u www-data php`
If you are not customizing our default nginx configuration you will need to remove the file:
```
/config/nginx/site-confs/default.conf
```
Then restart the container to replace it with the latest one.
Since all data is stored in the `/config` and `/data` volumes, nothing gets lost. The startup script will check for the version in your volume and the installed docker version. If it finds a mismatch, it automatically starts the upgrade process.
### Collaborative Editing
@ -254,6 +246,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
## Versions
* **25.06.23:** - Move Nextcloud installation inside container. Remove CLI updater. [See changes announcement](https://info.linuxserver.io/issues/2023-06-25-nextcloud/).
* **21.06.23:** - Existing users should update `/config/nginx/site-confs/default.conf` - Security fix for real ip settings.
* **25.05.23:** - Rebase to Alpine 3.18, deprecate armhf.
* **13.04.23:** - Move ssl.conf include to default.conf.

View File

@ -51,22 +51,14 @@ app_setup_block_enabled: true
app_setup_block: |
Access the webui at `https://<your-ip>:443`, for more information check out [Nextcloud]({{ project_url }}).
Docker image update and recreation of container alone won't update nextcloud version.
### Updating Nextcloud
In order to update nextcloud version, you have two options, firstly make sure you are using the latest docker image,then either
Updating Nextcloud is done by pulling the new image, and recreating the container with it.
It is only possible to upgrade one major version at a time. For example, if you want to upgrade from version 14 to 16, you will have to upgrade from version 14 to 15, then from 15 to 16.
Since all data is stored in the `/config` and `/data` volumes, nothing gets lost. The startup script will check for the version in your volume and the installed docker version. If it finds a mismatch, it automatically starts the upgrade process.
1. Perform the in app gui update.
2. Use the CLI version by running `docker exec -it nextcloud updater.phar`
(Both of these are described [here](https://docs.nextcloud.com/server/latest/admin_manual/maintenance/update.html))
Note: Both `occ` and `updater.phar` can be run without prepending with `sudo -u abc php` or `sudo -u www-data php`
If you are not customizing our default nginx configuration you will need to remove the file:
```
/config/nginx/site-confs/default.conf
```
Then restart the container to replace it with the latest one.
### Collaborative Editing
Nextcloud's built-in collaborative editing packages (Collabora/CODE and OnlyOffice) only work on x86_64 systems with glibc, and therefore they are not compatible with our images. You should create separate containers for them and set them up in Nextcloud with their respective connector addons.
@ -76,6 +68,7 @@ app_setup_block: |
# changelog
changelogs:
- { date: "25.06.23:", desc: "Move Nextcloud installation inside container. Remove CLI updater. [See changes announcement](https://info.linuxserver.io/issues/2023-06-25-nextcloud/)." }
- { date: "21.06.23:", desc: "Existing users should update `/config/nginx/site-confs/default.conf` - Security fix for real ip settings." }
- { date: "25.05.23:", desc: "Rebase to Alpine 3.18, deprecate armhf." }
- { date: "13.04.23:", desc: "Move ssl.conf include to default.conf." }

4
root/app/upgrade.exclude Normal file
View File

@ -0,0 +1,4 @@
/apps/
/config/
/data/
/themes/

View File

@ -1,6 +0,0 @@
<?php
$CONFIG = array (
'memcache.local' => '\OC\Memcache\APCu',
'datadirectory' => '/data',
);

View File

@ -1,4 +1,4 @@
## Version 2023/06/21 - Changelog: https://github.com/linuxserver/docker-nextcloud/commits/master/root/defaults/nginx/site-confs/default.conf.sample
## Version 2023/06/23 - Changelog: https://github.com/linuxserver/docker-nextcloud/commits/master/root/defaults/nginx/site-confs/default.conf.sample
# Set the `immutable` cache control options only for assets with a cache busting `v` argument
map $arg_v $asset_immutable {
@ -17,7 +17,7 @@ server {
include /config/nginx/ssl.conf;
root /config/www/nextcloud/;
root /app/www/public;
# display real ip in nginx logs when connected through reverse proxy via docker network
set_real_ip_from 172.16.0.0/12;

View File

@ -6,4 +6,4 @@
0 3 * * 6 run-parts /etc/periodic/weekly
0 5 1 * * run-parts /etc/periodic/monthly
# nextcloud cron
*/5 * * * * s6-setuidgid abc php -f /config/www/nextcloud/cron.php
*/5 * * * * s6-setuidgid abc php -f /app/www/public/cron.php

View File

@ -17,7 +17,7 @@ if [[ ! -f /config/crontabs/root ]]; then
# copy crontab from included defaults (using -n, do not overwrite an existing file)
cp -n /etc/crontabs/root /config/crontabs/
fi
sed -i "s|s6-setuidgid abc php[78] -f /config/www/nextcloud/cron.php|s6-setuidgid abc php -f /config/www/nextcloud/cron.php|" /config/crontabs/root
sed -i "s|s6-setuidgid abc php[0-9]* -f /config/www/nextcloud/cron.php|s6-setuidgid abc php -f /app/www/public/cron.php|" /config/crontabs/root
# set permissions and import user crontabs
lsiown root:root /config/crontabs/root
crontab -u root /config/crontabs/root

View File

@ -3,27 +3,149 @@
# create folders
mkdir -p \
/config/www/nextcloud \
/app/www/public/apps \
/app/www/public/config \
/app/www/public/themes \
/config/www/nextcloud/apps \
/config/www/nextcloud/config \
/config/www/nextcloud/themes \
/data
# install app
if [ ! -e /config/www/nextcloud/index.php ]; then
tar xf /app/nextcloud.tar.bz2 -C \
/config/www/nextcloud --strip-components=1
lsiown abc:abc -R \
/config/www/nextcloud
chmod +x /config/www/nextcloud/occ
# migrate legacy install (copy inside container)
if [ -f /config/www/nextcloud/version.php ]; then
echo "Migrating legacy install (this can take a while) ...)"
rsync -rlD --remove-source-files --exclude-from=/app/upgrade.exclude /config/www/nextcloud/ /app/www/public/
rm -rf /config/www/nextcloud/updater/
find \
/config/www/nextcloud/ \
-type d -empty \
! -path "/config/www/nextcloud/apps" \
! -path "/config/www/nextcloud/config" \
! -path "/config/www/nextcloud/themes" \
-delete
sed -i "s|/config/www/nextcloud/cron.php|/app/www/public/cron.php|g" /config/crontabs/root
touch /config/www/nextcloud/config/needs_migration
fi
# copy config
if [[ ! -f /config/www/nextcloud/config/config.php ]]; then
cp /defaults/config.php /config/www/nextcloud/config/config.php
# symlink config folders
for dir in apps config themes; do
if [ "$(readlink /app/www/public/${dir})" != "/config/www/nextcloud/${dir}" ]; then
rm -rf "/app/www/public/${dir}"
ln -s "/config/www/nextcloud/${dir}" "/app/www/public/${dir}"
lsiown abc:abc "/config/www/nextcloud/${dir}" "/app/www/public/${dir}"
fi
done
# symlink data folder
if [ "$(readlink /app/www/public/data)" != "/data" ]; then
rm -rf /app/www/public/data
ln -s /data /app/www/public/data
lsiown abc:abc /data /app/www/public/data
fi
# get versions
image_version=$(php -r "require '/app/www/src/version.php'; echo implode('.', \$OC_Version);" 2>/dev/null)
installed_version=$(php -r "require '/config/www/nextcloud/config/config.php'; echo \$CONFIG['version'];" 2>/dev/null)
if [ "${installed_version}" = "" ]; then
installed_version="0.0.0.0"
fi
image_major="${image_version%%.*}"
installed_major="${installed_version%%.*}"
((max_upgrade = installed_major + 1))
# compare versions
vergte() { printf '%s\n%s' "${2}" "${1}" | sort -C -V; }
vergt() { ! vergte "${2}" "${1}"; }
verlte() { printf '%s\n%s' "${1}" "${2}" | sort -C -V; }
verlt() { ! verlte "${2}" "${1}"; }
if vergt "${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?"
sleep infinity
fi
if [ "${installed_version}" != "0.0.0.0" ] && vergt "${image_major}" "${max_upgrade}"; then
echo "Can't start Nextcloud because the version of the data (${installed_version}) is more than one major version behind the docker image version (${image_version}) and upgrading more than one major version is not supported. Please run an image tagged for the major version ${max_upgrade} first."
sleep infinity
fi
if [ "${installed_version}" = "0.0.0.0" ] || [ ! -f /app/www/public/version.php ]; then
touch /tmp/needs_install
fi
if [ "${installed_version}" != "0.0.0.0" ] && vergt "${image_version}" "${installed_version}"; then
touch /tmp/needs_upgrade
fi
# initialize nextcloud
if [ -f /config/www/nextcloud/config/needs_migration ] || [ -f /tmp/needs_install ] || [ -f /tmp/needs_upgrade ]; then
echo "Initializing nextcloud ${image_version} (this can take a while) ..."
if [ -f /config/www/nextcloud/config/needs_migration ] || [ -f /tmp/needs_upgrade ]; then
echo "Upgrading nextcloud from ${installed_version} ..."
occ app:list | sed -n "/Enabled:/,/Disabled:/p" >/tmp/list_before
fi
rsync -rlD --exclude-from=/app/upgrade.exclude /app/www/src/ /app/www/public/
for dir in apps config themes; do
if [ -f /config/www/nextcloud/config/needs_migration ] || [ -f /tmp/needs_upgrade ] || [ -z "$(ls -A /app/www/public/${dir}/ 2>/dev/null)" ]; then
rsync -rlD --include "/${dir}" --exclude '/*' /app/www/src/ /config/www/nextcloud/
fi
done
if [ -z "$(ls -A /app/www/public/data/ 2>/dev/null)" ]; then
rsync -rlD --include "/data" --exclude '/*' /app/www/src/ /
fi
echo "Setting permissions"
lsiown abc:abc -R \
/app/www/public \
/config/www/nextcloud
if [ -f /config/www/nextcloud/config/needs_migration ] || [ -f /tmp/needs_upgrade ]; then
# Upgrade
occ upgrade
occ app:list | sed -n "/Enabled:/,/Disabled:/p" >/tmp/list_after
echo "The following apps have been disabled:"
diff /tmp/list_before /tmp/list_after | grep '<' | cut -d- -f2 | cut -d: -f1
else
if [ "${installed_version}" = "0.0.0.0" ]; then
# Install
echo "New nextcloud instance"
echo "Please run the web-based installer on first connect!"
fi
fi
rm -f /tmp/list_before /tmp/list_after
echo "Initializing finished"
fi
rm -f \
/config/www/nextcloud/config/needs_migration \
/tmp/needs_install \
/tmp/needs_upgrade
# permissions
lsiown abc:abc \
/config/www/nextcloud/config/config.php \
/data
/app/www/public \
/config/www/nextcloud
# setup config
if occ config:system:get installed >/dev/null 2>&1; then
if ! occ config:system:get memcache.local >/dev/null 2>&1; then
occ config:system:set memcache.local --value='\\OC\\Memcache\\APCu'
fi
if ! occ config:system:get filelocking.enabled >/dev/null 2>&1; then
occ config:system:set filelocking.enabled --value=true
fi
if ! occ config:system:get memcache.locking >/dev/null 2>&1; then
occ config:system:set memcache.locking --value='\\OC\\Memcache\\APCu'
fi
else
echo "After completing the web-based installer, restart the Nextcloud container to apply default memory caching and transactional file locking configurations."
echo "Alternatively, you can apply your own configurations by editing /config/www/nextcloud/config/config.php following the documentation:"
echo "https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/caching_configuration.html"
echo "https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/files_locking_transactional.html"
fi
if (occ app:list --no-interaction | grep -q richdocumentscode) 2>/dev/null; then
echo "Removing CODE Server"

View File

@ -0,0 +1,11 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
DEFAULT_CONF="/config/nginx/site-confs/default.conf"
OLD_ROOT="root /config/www/nextcloud/;"
NEW_ROOT="root /app/www/public;"
if grep -q "${OLD_ROOT}" "${DEFAULT_CONF}"; then
echo "updating root in ${DEFAULT_CONF}"
sed -i "s|${OLD_ROOT}|${NEW_ROOT}|" "${DEFAULT_CONF}"
fi

View File

@ -1,4 +1,4 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
sudo -u abc -s /bin/bash -c "php /config/www/nextcloud/occ $*"
sudo -u abc -s /bin/bash -c "php /app/www/public/occ $*"

View File

@ -1,4 +0,0 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
sudo -u abc -s /bin/bash -c "php /config/www/nextcloud/updater/updater.phar $*"