diff --git a/Dockerfile-alpine.template b/Dockerfile-alpine.template index 0840ade0..eb77397a 100644 --- a/Dockerfile-alpine.template +++ b/Dockerfile-alpine.template @@ -90,7 +90,6 @@ RUN { \ chown -R www-data:root /var/www; \ chmod -R g=u /var/www -VOLUME /var/www/html %%VARIANT_EXTRAS%% ENV NEXTCLOUD_VERSION %%VERSION%% @@ -109,17 +108,22 @@ RUN set -ex; \ # gpg key from https://nextcloud.com/nextcloud.asc gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys 28806A878AE423A28372792ED75899B9A724937A; \ gpg --batch --verify nextcloud.tar.bz2.asc nextcloud.tar.bz2; \ - tar -xjf nextcloud.tar.bz2 -C /usr/src/; \ + tar -xjf nextcloud.tar.bz2 -C /var/www/; \ + rm -rf /var/www/html; \ + mv /var/www/nextcloud /var/www/html; \ gpgconf --kill all; \ - rm -r "$GNUPGHOME" nextcloud.tar.bz2.asc nextcloud.tar.bz2; \ - rm -rf /usr/src/nextcloud/updater; \ - mkdir -p /usr/src/nextcloud/data; \ - mkdir -p /usr/src/nextcloud/custom_apps; \ - chmod +x /usr/src/nextcloud/occ; \ - apk del .fetch-deps + rm -r "$GNUPGHOME"; \ + rm -rf /var/www/html/updater; \ + mkdir -p /var/www/html/data; \ + mkdir -p /var/www/html/custom_apps; \ + chmod +x /var/www/html/occ; \ + apk del .fetch-deps; \ + touch /var/www/html/data/.ocdata; \ + touch /var/www/html/config/config.php; \ + chown -R www-data:root /var/www/html -COPY *.sh upgrade.exclude / -COPY config/* /usr/src/nextcloud/config/ +COPY *.sh / +COPY --chown=www-data:root config/* /var/www/html/config/ ENTRYPOINT ["/entrypoint.sh"] CMD ["%%CMD%%"] diff --git a/Dockerfile-debian.template b/Dockerfile-debian.template index 9345d2ef..16934971 100644 --- a/Dockerfile-debian.template +++ b/Dockerfile-debian.template @@ -103,7 +103,6 @@ RUN { \ chown -R www-data:root /var/www; \ chmod -R g=u /var/www -VOLUME /var/www/html %%VARIANT_EXTRAS%% ENV NEXTCLOUD_VERSION %%VERSION%% @@ -124,19 +123,23 @@ RUN set -ex; \ # gpg key from https://nextcloud.com/nextcloud.asc gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys 28806A878AE423A28372792ED75899B9A724937A; \ gpg --batch --verify nextcloud.tar.bz2.asc nextcloud.tar.bz2; \ - tar -xjf nextcloud.tar.bz2 -C /usr/src/; \ + tar -xjf nextcloud.tar.bz2 -C /var/www/; \ + rm -rf /var/www/html; \ + mv /var/www/nextcloud /var/www/html; \ gpgconf --kill all; \ - rm -r "$GNUPGHOME" nextcloud.tar.bz2.asc nextcloud.tar.bz2; \ - rm -rf /usr/src/nextcloud/updater; \ - mkdir -p /usr/src/nextcloud/data; \ - mkdir -p /usr/src/nextcloud/custom_apps; \ - chmod +x /usr/src/nextcloud/occ; \ - \ + rm -r "$GNUPGHOME"; \ + rm -rf /var/www/html/updater; \ + mkdir -p /var/www/html/data; \ + mkdir -p /var/www/html/custom_apps; \ + chmod +x /var/www/html/occ; \ + touch /var/www/html/data/.ocdata; \ + touch /var/www/html/config/config.php; \ + chown -R www-data:root /var/www/html; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps; \ rm -rf /var/lib/apt/lists/* -COPY *.sh upgrade.exclude / -COPY config/* /usr/src/nextcloud/config/ +COPY *.sh / +COPY --chown=www-data:root config/* /var/www/html/config/ ENTRYPOINT ["/entrypoint.sh"] CMD ["%%CMD%%"] diff --git a/README.md b/README.md index 8721eb66..a8196935 100644 --- a/README.md +++ b/README.md @@ -48,17 +48,9 @@ As the fastCGI-Process is not capable of serving static files (style sheets, ima By default, this container uses SQLite for data storage but the Nextcloud setup wizard (appears on first run) allows connecting to an existing MySQL/MariaDB or PostgreSQL database. You can also link a database container, e. g. `--link my-mysql:mysql`, and then use `mysql` as the database host on setup. More info is in the docker-compose section. ## Persistent data -The Nextcloud installation and all data beyond what lives in the database (file uploads, etc) are stored in the [unnamed docker volume](https://docs.docker.com/engine/tutorials/dockervolumes/#adding-a-data-volume) volume `/var/www/html`. The docker daemon will store that data within the docker directory `/var/lib/docker/volumes/...`. That means your data is saved even if the container crashes, is stopped or deleted. +By default, there is no persistency, that means your data is not saved. -A named Docker volume or a mounted host directory should be used for upgrades and backups. To achieve this, you need one volume for your database container and one for Nextcloud. - -Nextcloud: -- `/var/www/html/` folder where all nextcloud data lives -```console -$ docker run -d \ --v nextcloud:/var/www/html \ -nextcloud -``` +A named Docker volume or a mounted host directory should be used. To achieve this, first, you need one volume for your database containe. Database: - `/var/lib/mysql` MySQL / MariaDB Data @@ -69,21 +61,19 @@ $ docker run -d \ mariadb ``` -If you want to get fine grained access to your individual files, you can mount additional volumes for data, config, your theme and custom apps. +Then, you need to configure access to your individual files, you have to mount additional volumes for data, config, your theme (optional) and custom apps. The `data`, `config` files are stored in respective subfolders inside `/var/www/html/`. The apps are split into core `apps` (which are shipped with Nextcloud and you don't need to take care of) and a `custom_apps` folder. If you use a custom theme it would go into the `themes` subfolder. Overview of the folders that can be mounted as volumes: -- `/var/www/html` Main folder, needed for updating - `/var/www/html/custom_apps` installed / modified apps - `/var/www/html/config` local configuration - `/var/www/html/data` the actual data of your Nextcloud -- `/var/www/html/themes/` theming/branding +- `/var/www/html/themes/` theming/branding (optional) If you want to use named volumes for all of these, it would look like this: ```console $ docker run -d \ --v nextcloud:/var/www/html \ -v apps:/var/www/html/custom_apps \ -v config:/var/www/html/config \ -v data:/var/www/html/data \ diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 61637079..ad0eb222 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,16 +1,6 @@ #!/bin/sh set -eu -# version_greater A B returns whether A > B -version_greater() { - [ "$(printf '%s\n' "$@" | sort -t '.' -n -k1,1 -k2,2 -k3,3 -k4,4 | head -n 1)" != "$1" ] -} - -# return true if specified directory is empty -directory_empty() { - [ -z "$(ls -A "$1/")" ] -} - run_as() { if [ "$(id -u)" = 0 ]; then su -p www-data -s /bin/sh -c "$1" @@ -41,100 +31,69 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP } > /usr/local/etc/php/conf.d/redis-session.ini fi - installed_version="0.0.0.0" - if [ -f /var/www/html/version.php ]; then - # shellcheck disable=SC2016 - installed_version="$(php -r 'require "/var/www/html/version.php"; echo implode(".", $OC_Version);')" - fi - # shellcheck disable=SC2016 - image_version="$(php -r 'require "/usr/src/nextcloud/version.php"; echo implode(".", $OC_Version);')" + #upgrade + if php occ status | grep installed | grep true; then + run_as 'php /var/www/html/occ upgrade' + #install + else + echo "New nextcloud instance" - 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 - echo "Initializing nextcloud $image_version ..." - if [ "$(id -u)" = 0 ]; then - rsync_options="-rlDog --chown www-data:root" - else - rsync_options="-rlD" - fi - rsync $rsync_options --delete --exclude-from=/upgrade.exclude /usr/src/nextcloud/ /var/www/html/ - - for dir in config data custom_apps themes; do - if [ ! -d "/var/www/html/$dir" ] || directory_empty "/var/www/html/$dir"; then - rsync $rsync_options --include "/$dir/" --exclude '/*' /usr/src/nextcloud/ /var/www/html/ - fi - done - rsync $rsync_options --include '/version.php' --exclude '/*' /usr/src/nextcloud/ /var/www/html/ - echo "Initializing finished" - - #install - if [ "$installed_version" = "0.0.0.0" ]; then - echo "New nextcloud instance" - - if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; then + if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; then + # shellcheck disable=SC2016 + install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"' + if [ -n "${NEXTCLOUD_TABLE_PREFIX+x}" ]; then # shellcheck disable=SC2016 - install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"' - if [ -n "${NEXTCLOUD_TABLE_PREFIX+x}" ]; then - # shellcheck disable=SC2016 - install_options=$install_options' --database-table-prefix "$NEXTCLOUD_TABLE_PREFIX"' - fi - if [ -n "${NEXTCLOUD_DATA_DIR+x}" ]; then - # shellcheck disable=SC2016 - install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"' - fi - - install=false - if [ -n "${SQLITE_DATABASE+x}" ]; then - echo "Installing with SQLite database" - # shellcheck disable=SC2016 - install_options=$install_options' --database-name "$SQLITE_DATABASE"' - install=true - elif [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_USER+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ]; then - echo "Installing with MySQL database" - # shellcheck disable=SC2016 - install_options=$install_options' --database mysql --database-name "$MYSQL_DATABASE" --database-user "$MYSQL_USER" --database-pass "$MYSQL_PASSWORD" --database-host "$MYSQL_HOST"' - install=true - elif [ -n "${POSTGRES_DB+x}" ] && [ -n "${POSTGRES_USER+x}" ] && [ -n "${POSTGRES_PASSWORD+x}" ] && [ -n "${POSTGRES_HOST+x}" ]; then - echo "Installing with PostgreSQL database" - # shellcheck disable=SC2016 - install_options=$install_options' --database pgsql --database-name "$POSTGRES_DB" --database-user "$POSTGRES_USER" --database-pass "$POSTGRES_PASSWORD" --database-host "$POSTGRES_HOST"' - install=true - fi - - if [ "$install" = true ]; then - echo "starting nextcloud installation" - max_retries=10 - try=0 - until run_as "php /var/www/html/occ maintenance:install $install_options" || [ "$try" -gt "$max_retries" ] - do - echo "retrying install..." - try=$((try+1)) - sleep 10s - done - if [ "$try" -gt "$max_retries" ]; then - echo "installing of nextcloud failed!" - exit 1 - fi - if [ -n "${NEXTCLOUD_TRUSTED_DOMAINS+x}" ]; then - echo "setting trusted domains…" - NC_TRUSTED_DOMAIN_IDX=1 - for DOMAIN in $NEXTCLOUD_TRUSTED_DOMAINS ; do - DOMAIN=$(echo "$DOMAIN" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - run_as "php /var/www/html/occ config:system:set trusted_domains $NC_TRUSTED_DOMAIN_IDX --value=$DOMAIN" - NC_TRUSTED_DOMAIN_IDX=$(($NC_TRUSTED_DOMAIN_IDX+1)) - done - fi - else - echo "running web-based installer on first connect!" - fi + install_options=$install_options' --database-table-prefix "$NEXTCLOUD_TABLE_PREFIX"' + fi + if [ -n "${NEXTCLOUD_DATA_DIR+x}" ]; then + # shellcheck disable=SC2016 + install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"' + fi + + install=false + if [ -n "${SQLITE_DATABASE+x}" ]; then + echo "Installing with SQLite database" + # shellcheck disable=SC2016 + install_options=$install_options' --database-name "$SQLITE_DATABASE"' + install=true + elif [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_USER+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ]; then + echo "Installing with MySQL database" + # shellcheck disable=SC2016 + install_options=$install_options' --database mysql --database-name "$MYSQL_DATABASE" --database-user "$MYSQL_USER" --database-pass "$MYSQL_PASSWORD" --database-host "$MYSQL_HOST"' + install=true + elif [ -n "${POSTGRES_DB+x}" ] && [ -n "${POSTGRES_USER+x}" ] && [ -n "${POSTGRES_PASSWORD+x}" ] && [ -n "${POSTGRES_HOST+x}" ]; then + echo "Installing with PostgreSQL database" + # shellcheck disable=SC2016 + install_options=$install_options' --database pgsql --database-name "$POSTGRES_DB" --database-user "$POSTGRES_USER" --database-pass "$POSTGRES_PASSWORD" --database-host "$POSTGRES_HOST"' + install=true + fi + + if [ "$install" = true ]; then + echo "starting nextcloud installation" + max_retries=10 + try=0 + until run_as "php /var/www/html/occ maintenance:install $install_options" || [ "$try" -gt "$max_retries" ] + do + echo "retrying install..." + try=$((try+1)) + sleep 10s + done + if [ "$try" -gt "$max_retries" ]; then + echo "installing of nextcloud failed!" + exit 1 + fi + if [ -n "${NEXTCLOUD_TRUSTED_DOMAINS+x}" ]; then + echo "setting trusted domains…" + NC_TRUSTED_DOMAIN_IDX=1 + for DOMAIN in $NEXTCLOUD_TRUSTED_DOMAINS ; do + DOMAIN=$(echo "$DOMAIN" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + run_as "php /var/www/html/occ config:system:set trusted_domains $NC_TRUSTED_DOMAIN_IDX --value=$DOMAIN" + NC_TRUSTED_DOMAIN_IDX=$(($NC_TRUSTED_DOMAIN_IDX+1)) + done + fi + else + echo "running web-based installer on first connect!" fi - #upgrade - else - run_as 'php /var/www/html/occ upgrade' fi fi fi diff --git a/update.sh b/update.sh index 890b54f1..9786bbc1 100755 --- a/update.sh +++ b/update.sh @@ -141,9 +141,6 @@ function create_variant() { cp "docker-$name.sh" "$dir/$name.sh" done - # Copy the upgrade.exclude - cp upgrade.exclude "$dir/" - # Copy the config directory cp -rT .config "$dir/config" diff --git a/upgrade.exclude b/upgrade.exclude deleted file mode 100644 index 354864da..00000000 --- a/upgrade.exclude +++ /dev/null @@ -1,5 +0,0 @@ -/config/ -/data/ -/custom_apps/ -/themes/ -/version.php