0
0
Fork 0
mirror of https://github.com/nextcloud/docker.git synced 2025-06-16 16:14:47 +02:00

Removes VOLUME directive.

In a kubernetes env, this is causing a lot of issues.
We want a read only docker image. And this helps.
And as you see it removes a lot of logic that is always a good things to remove lines ;)

The last logic piece that is needed, is to know if the Nc is installed or not, and we can get this from `occ status`.

In term of upgrade Nobody will lost the data.
There is just one thing, for people relying on /var/www/html/ is that the Nextcloud will not update anymore.
But I guess people will realize and search what is happening.
For convenience, we could put a warning in the entrypoint, and detect this case.
What do you think? I know it is tricky to update these things, but I think we agree that we have to get rid of this old logic.

Signed-off-by: pierreozoux <pierre@ozoux.net>
This commit is contained in:
pierreozoux 2020-01-17 15:45:38 +01:00
parent c4ccb67a0d
commit e33f20dc92
6 changed files with 91 additions and 143 deletions

View file

@ -90,7 +90,6 @@ RUN { \
chown -R www-data:root /var/www; \ chown -R www-data:root /var/www; \
chmod -R g=u /var/www chmod -R g=u /var/www
VOLUME /var/www/html
%%VARIANT_EXTRAS%% %%VARIANT_EXTRAS%%
ENV NEXTCLOUD_VERSION %%VERSION%% ENV NEXTCLOUD_VERSION %%VERSION%%
@ -109,17 +108,22 @@ RUN set -ex; \
# gpg key from https://nextcloud.com/nextcloud.asc # gpg key from https://nextcloud.com/nextcloud.asc
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys 28806A878AE423A28372792ED75899B9A724937A; \ gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys 28806A878AE423A28372792ED75899B9A724937A; \
gpg --batch --verify nextcloud.tar.bz2.asc nextcloud.tar.bz2; \ 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; \ gpgconf --kill all; \
rm -r "$GNUPGHOME" nextcloud.tar.bz2.asc nextcloud.tar.bz2; \ rm -r "$GNUPGHOME"; \
rm -rf /usr/src/nextcloud/updater; \ rm -rf /var/www/html/updater; \
mkdir -p /usr/src/nextcloud/data; \ mkdir -p /var/www/html/data; \
mkdir -p /usr/src/nextcloud/custom_apps; \ mkdir -p /var/www/html/custom_apps; \
chmod +x /usr/src/nextcloud/occ; \ chmod +x /var/www/html/occ; \
apk del .fetch-deps 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 *.sh /
COPY config/* /usr/src/nextcloud/config/ COPY --chown=www-data:root config/* /var/www/html/config/
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
CMD ["%%CMD%%"] CMD ["%%CMD%%"]

View file

@ -103,7 +103,6 @@ RUN { \
chown -R www-data:root /var/www; \ chown -R www-data:root /var/www; \
chmod -R g=u /var/www chmod -R g=u /var/www
VOLUME /var/www/html
%%VARIANT_EXTRAS%% %%VARIANT_EXTRAS%%
ENV NEXTCLOUD_VERSION %%VERSION%% ENV NEXTCLOUD_VERSION %%VERSION%%
@ -124,19 +123,23 @@ RUN set -ex; \
# gpg key from https://nextcloud.com/nextcloud.asc # gpg key from https://nextcloud.com/nextcloud.asc
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys 28806A878AE423A28372792ED75899B9A724937A; \ gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys 28806A878AE423A28372792ED75899B9A724937A; \
gpg --batch --verify nextcloud.tar.bz2.asc nextcloud.tar.bz2; \ 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; \ gpgconf --kill all; \
rm -r "$GNUPGHOME" nextcloud.tar.bz2.asc nextcloud.tar.bz2; \ rm -r "$GNUPGHOME"; \
rm -rf /usr/src/nextcloud/updater; \ rm -rf /var/www/html/updater; \
mkdir -p /usr/src/nextcloud/data; \ mkdir -p /var/www/html/data; \
mkdir -p /usr/src/nextcloud/custom_apps; \ mkdir -p /var/www/html/custom_apps; \
chmod +x /usr/src/nextcloud/occ; \ 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; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps; \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
COPY *.sh upgrade.exclude / COPY *.sh /
COPY config/* /usr/src/nextcloud/config/ COPY --chown=www-data:root config/* /var/www/html/config/
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
CMD ["%%CMD%%"] CMD ["%%CMD%%"]

View file

@ -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. 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 ## 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. A named Docker volume or a mounted host directory should be used. To achieve this, first, you need one volume for your database containe.
Nextcloud:
- `/var/www/html/` folder where all nextcloud data lives
```console
$ docker run -d \
-v nextcloud:/var/www/html \
nextcloud
```
Database: Database:
- `/var/lib/mysql` MySQL / MariaDB Data - `/var/lib/mysql` MySQL / MariaDB Data
@ -69,21 +61,19 @@ $ docker run -d \
mariadb 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. 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: 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/custom_apps` installed / modified apps
- `/var/www/html/config` local configuration - `/var/www/html/config` local configuration
- `/var/www/html/data` the actual data of your Nextcloud - `/var/www/html/data` the actual data of your Nextcloud
- `/var/www/html/themes/<YOUR_CUSTOM_THEME>` theming/branding - `/var/www/html/themes/<YOUR_CUSTOM_THEME>` theming/branding (optional)
If you want to use named volumes for all of these, it would look like this: If you want to use named volumes for all of these, it would look like this:
```console ```console
$ docker run -d \ $ docker run -d \
-v nextcloud:/var/www/html \
-v apps:/var/www/html/custom_apps \ -v apps:/var/www/html/custom_apps \
-v config:/var/www/html/config \ -v config:/var/www/html/config \
-v data:/var/www/html/data \ -v data:/var/www/html/data \

View file

@ -1,16 +1,6 @@
#!/bin/sh #!/bin/sh
set -eu 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() { run_as() {
if [ "$(id -u)" = 0 ]; then if [ "$(id -u)" = 0 ]; then
su -p www-data -s /bin/sh -c "$1" 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 } > /usr/local/etc/php/conf.d/redis-session.ini
fi fi
installed_version="0.0.0.0" #upgrade
if [ -f /var/www/html/version.php ]; then if php occ status | grep installed | grep true; then
# shellcheck disable=SC2016 run_as 'php /var/www/html/occ upgrade'
installed_version="$(php -r 'require "/var/www/html/version.php"; echo implode(".", $OC_Version);')" #install
fi else
# shellcheck disable=SC2016 echo "New nextcloud instance"
image_version="$(php -r 'require "/usr/src/nextcloud/version.php"; echo implode(".", $OC_Version);')"
if version_greater "$installed_version" "$image_version"; then if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; 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?" # shellcheck disable=SC2016
exit 1 install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"'
fi if [ -n "${NEXTCLOUD_TABLE_PREFIX+x}" ]; then
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
# shellcheck disable=SC2016 # shellcheck disable=SC2016
install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"' install_options=$install_options' --database-table-prefix "$NEXTCLOUD_TABLE_PREFIX"'
if [ -n "${NEXTCLOUD_TABLE_PREFIX+x}" ]; then fi
# shellcheck disable=SC2016 if [ -n "${NEXTCLOUD_DATA_DIR+x}" ]; then
install_options=$install_options' --database-table-prefix "$NEXTCLOUD_TABLE_PREFIX"' # shellcheck disable=SC2016
fi install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"'
if [ -n "${NEXTCLOUD_DATA_DIR+x}" ]; then fi
# shellcheck disable=SC2016
install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"' install=false
fi if [ -n "${SQLITE_DATABASE+x}" ]; then
echo "Installing with SQLite database"
install=false # shellcheck disable=SC2016
if [ -n "${SQLITE_DATABASE+x}" ]; then install_options=$install_options' --database-name "$SQLITE_DATABASE"'
echo "Installing with SQLite database" install=true
# shellcheck disable=SC2016 elif [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_USER+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ]; then
install_options=$install_options' --database-name "$SQLITE_DATABASE"' echo "Installing with MySQL database"
install=true # shellcheck disable=SC2016
elif [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_USER+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ]; then install_options=$install_options' --database mysql --database-name "$MYSQL_DATABASE" --database-user "$MYSQL_USER" --database-pass "$MYSQL_PASSWORD" --database-host "$MYSQL_HOST"'
echo "Installing with MySQL database" install=true
# shellcheck disable=SC2016 elif [ -n "${POSTGRES_DB+x}" ] && [ -n "${POSTGRES_USER+x}" ] && [ -n "${POSTGRES_PASSWORD+x}" ] && [ -n "${POSTGRES_HOST+x}" ]; then
install_options=$install_options' --database mysql --database-name "$MYSQL_DATABASE" --database-user "$MYSQL_USER" --database-pass "$MYSQL_PASSWORD" --database-host "$MYSQL_HOST"' echo "Installing with PostgreSQL database"
install=true # shellcheck disable=SC2016
elif [ -n "${POSTGRES_DB+x}" ] && [ -n "${POSTGRES_USER+x}" ] && [ -n "${POSTGRES_PASSWORD+x}" ] && [ -n "${POSTGRES_HOST+x}" ]; then install_options=$install_options' --database pgsql --database-name "$POSTGRES_DB" --database-user "$POSTGRES_USER" --database-pass "$POSTGRES_PASSWORD" --database-host "$POSTGRES_HOST"'
echo "Installing with PostgreSQL database" install=true
# shellcheck disable=SC2016 fi
install_options=$install_options' --database pgsql --database-name "$POSTGRES_DB" --database-user "$POSTGRES_USER" --database-pass "$POSTGRES_PASSWORD" --database-host "$POSTGRES_HOST"'
install=true if [ "$install" = true ]; then
fi echo "starting nextcloud installation"
max_retries=10
if [ "$install" = true ]; then try=0
echo "starting nextcloud installation" until run_as "php /var/www/html/occ maintenance:install $install_options" || [ "$try" -gt "$max_retries" ]
max_retries=10 do
try=0 echo "retrying install..."
until run_as "php /var/www/html/occ maintenance:install $install_options" || [ "$try" -gt "$max_retries" ] try=$((try+1))
do sleep 10s
echo "retrying install..." done
try=$((try+1)) if [ "$try" -gt "$max_retries" ]; then
sleep 10s echo "installing of nextcloud failed!"
done exit 1
if [ "$try" -gt "$max_retries" ]; then fi
echo "installing of nextcloud failed!" if [ -n "${NEXTCLOUD_TRUSTED_DOMAINS+x}" ]; then
exit 1 echo "setting trusted domains…"
fi NC_TRUSTED_DOMAIN_IDX=1
if [ -n "${NEXTCLOUD_TRUSTED_DOMAINS+x}" ]; then for DOMAIN in $NEXTCLOUD_TRUSTED_DOMAINS ; do
echo "setting trusted domains…" DOMAIN=$(echo "$DOMAIN" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
NC_TRUSTED_DOMAIN_IDX=1 run_as "php /var/www/html/occ config:system:set trusted_domains $NC_TRUSTED_DOMAIN_IDX --value=$DOMAIN"
for DOMAIN in $NEXTCLOUD_TRUSTED_DOMAINS ; do NC_TRUSTED_DOMAIN_IDX=$(($NC_TRUSTED_DOMAIN_IDX+1))
DOMAIN=$(echo "$DOMAIN" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') done
run_as "php /var/www/html/occ config:system:set trusted_domains $NC_TRUSTED_DOMAIN_IDX --value=$DOMAIN" fi
NC_TRUSTED_DOMAIN_IDX=$(($NC_TRUSTED_DOMAIN_IDX+1)) else
done echo "running web-based installer on first connect!"
fi
else
echo "running web-based installer on first connect!"
fi
fi fi
#upgrade
else
run_as 'php /var/www/html/occ upgrade'
fi fi
fi fi
fi fi

View file

@ -141,9 +141,6 @@ function create_variant() {
cp "docker-$name.sh" "$dir/$name.sh" cp "docker-$name.sh" "$dir/$name.sh"
done done
# Copy the upgrade.exclude
cp upgrade.exclude "$dir/"
# Copy the config directory # Copy the config directory
cp -rT .config "$dir/config" cp -rT .config "$dir/config"

View file

@ -1,5 +0,0 @@
/config/
/data/
/custom_apps/
/themes/
/version.php