From 305f739a0e19c363742e567b0c411c01c6ce759a Mon Sep 17 00:00:00 2001 From: Simon C Date: Thu, 3 Sep 2020 11:42:35 +0200 Subject: [PATCH] feat: Ajout du service Nextcloud --- nextcloud/.env | 25 +++++++++++ nextcloud/README.md | 25 +++++++++++ nextcloud/docker-compose.yml | 87 ++++++++++++++++++++++++++++++++++++ nextcloud/run | 47 +++++++++++++++++++ 4 files changed, 184 insertions(+) create mode 100644 nextcloud/.env create mode 100644 nextcloud/README.md create mode 100644 nextcloud/docker-compose.yml create mode 100755 nextcloud/run diff --git a/nextcloud/.env b/nextcloud/.env new file mode 100644 index 0000000..af0196b --- /dev/null +++ b/nextcloud/.env @@ -0,0 +1,25 @@ +## DOCKER + +COMPOSE_FILE=./docker-compose.yml +#DOCKER_HOST= +TRAEFIK_NETWORK_NAME=kifeart + +## APP + +NEXTCLOUD_CONTAINER_NAME=nextcloud +NEXTCLOUD_VOLUME_NAME=nextcloud +NEXTCLOUD_DOMAIN=nextcloud.cool.life +NEXTCLOUD_IMAGE=nextcloud:19.0.2 + +NEXTCLOUD_ADMIN_USER: user +NEXTCLOUD_ADMIN_PASSWORD: password + +# DATABASE +# Voir la description ../postgres/README.md + +POSTGRES_IMAGE=postgres:12.2-alpine +POSTGRES_USER=user-example +POSTGRES_PASSWORD=password-example +POSTGRES_DB=postgres-database-name-example +POSTGRES_CONTAINER_NAME=nextcloud-postgres +POSTGRES_VOLUME_NAME=nextcloud-postgres diff --git a/nextcloud/README.md b/nextcloud/README.md new file mode 100644 index 0000000..f3764d3 --- /dev/null +++ b/nextcloud/README.md @@ -0,0 +1,25 @@ +# Nextcloud + +> Nextcloud server, a safe home for all your data +> +> Nextcloud est un logiciel libre, de site d'hébergement de fichiers, et un fork +> du logiciel ownCloud. À l'origine accessible via WebDAV, n'importe quel +> navigateur web, ou des clients spécialisés, son architecture ouverte a permis +> de voir ses fonctionnalités s'étendre depuis ses origines. Fin 2018, il +> propose de nombreux services. +> +> -- [Github][github] + +On peut trouver [la documentation ici][documentation]. + +## TODO + +- [x] Mise en place d'une sauvegarde / restauration de sauvegarde +- [x] crontab https://docs.nextcloud.com//server/latest/admin_manual/configuration_server/background_jobs_configuration.html#cron +- [x] Ajouter un redis : https://www.it-connect.fr/nextcloud-activer-et-configurer-le-cache-redis/ +- [ ] Ajout des informations SMTP + +[github]: https://github.com/nextcloud/server +[documentation]: https://docs.nextcloud.com/server/latest/admin_manual/contents.html +[backup]: https://docs.nextcloud.com/server/latest/admin_manual/maintenance/backup.html +[restore]: https://docs.nextcloud.com/server/latest/admin_manual/maintenance/restore.html diff --git a/nextcloud/docker-compose.yml b/nextcloud/docker-compose.yml new file mode 100644 index 0000000..c1a0c47 --- /dev/null +++ b/nextcloud/docker-compose.yml @@ -0,0 +1,87 @@ +version: "3.8" + +networks: + default: + name: ${TRAEFIK_NETWORK_NAME} + +volumes: + nextcloud: + name: ${NEXTCLOUD_VOLUME_NAME} + nextcloud-postgres: + name: ${POSTGRES_VOLUME_NAME} + +services: + + nextcloud: + container_name: ${NEXTCLOUD_CONTAINER_NAME} + image: ${NEXTCLOUD_IMAGE} + restart: always + hostname: ${NEXTCLOUD_DOMAIN} + depends_on: + - nextcloud-postgres + - nextcloud-redis + volumes: + - nextcloud:/var/www/html + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + environment: + NEXTCLOUD_TRUSTED_DOMAINS: ${NEXTCLOUD_DOMAIN} + NEXTCLOUD_ADMIN_USER: ${NEXTCLOUD_ADMIN_USER} + NEXTCLOUD_ADMIN_PASSWORD: ${NEXTCLOUD_ADMIN_PASSWORD} + OVERWRITEPROTOCOL: 'https' + APACHE_DISABLE_REWRITE_IP: '1' + TRUSTED_PROXIES: ${TRAEFIK_NETWORK_NAME} + OVERWRITEPROTOCOL: 'https' + POSTGRES_HOST: ${POSTGRES_CONTAINER_NAME} + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_USER: ${POSTGRES_USER} + REDIS_HOST: 'nextcloud-redis' + PUID: 1001 + PGID: 119 + labels: + traefik.enable: 'true' + traefik.docker.network: ${TRAEFIK_NETWORK_NAME} + traefik.http.routers.nextcloud.rule: 'Host(`${NEXTCLOUD_DOMAIN}`)' + traefik.http.routers.nextcloud.entrypoints: 'web' + + nextcloud-postgres: + container_name: ${POSTGRES_CONTAINER_NAME} + image: ${POSTGRES_IMAGE} + restart: always + environment: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + PUID: 1001 + PGID: 119 + volumes: + - nextcloud-postgres:/var/lib/postgresql/data + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + + nextcloud-redis: + image: redis:6.0.7-alpine + container_name: nextcloud-redis + restart: always + environment: + PUID: 1001 + PGID: 119 + volumes: + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + + nextcloud-cron: + image: ${NEXTCLOUD_IMAGE} + container_name: nextcloud-cron + restart: always + depends_on: + - nextcloud + entrypoint: /cron.sh + environment: + PUID: 1001 + PGID: 119 + volumes: + - nextcloud:/var/www/html + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro diff --git a/nextcloud/run b/nextcloud/run new file mode 100755 index 0000000..2effbc1 --- /dev/null +++ b/nextcloud/run @@ -0,0 +1,47 @@ +#!/bin/bash + +set -eu + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +. $DIR/../help.sh +. $DIR/../postgres/run --only-source + +nextcloud_help() { + echo "./run backup : Lancement de la sauvegarde de Nextcloud" + echo "./run restore : Restoration de la sauvegarde de Nextcloud" +} + +nextcloud_backup() { + script_env + BACKUP_DATE_DEFAULT=`date +%Y%m%d_%H%M%S` + BACKUP_DATE=${BACKUP_DATE:-$BACKUP_DATE_DEFAULT} + backup_folder_create + + POSTGRES_BACKUP_FILE=backups/${BACKUP_DATE}_${NEXTCLOUD_DOMAIN}_postgres.sql + postgres_backup + + docker run -it --rm -v $HOME/backups/${NEXTCLOUD_DOMAIN}:/backup --volumes-from nextcloud alpine:3.11.6 ash -c "cd /var/www/html && tar cvf /backup/${BACKUP_DATE}_${NEXTCLOUD_DOMAIN}_files.tar ." +} + +nextcloud_restore() { + script_env + + #postgres_restore + docker run -it --rm -v $HOME/backups/${NEXTCLOUD_DOMAIN}:/backup -v nextcloud:/var/www/html alpine:3.11.6 ash -c "cd /var/www/html && tar xvf /backup/${BACKUP_DATE}_${NEXTCLOUD_DOMAIN}_files.tar --strip 1" +} + +if [ $# -ge 1 ]; then + if [ "${1}" == "backup" ]; then + script_start + nextcloud_backup + script_end + elif [ "${1}" == "restore" ]; then + script_start + nextcloud_restore + script_end + elif [ "${1}" != "--only-source" ]; then + nextcloud_help + fi +else + nextcloud_help +fi