add postgres db (#26)
continuous-integration/drone/push Build is failing Details

This PR moves the db service into two override files `compose.mariadb.yml` and `compose.postgres.yml`.

Existing installations need to add:
```
COMPOSE_FILE="compose.yml"
COMPOSE_FILE="$COMPOSE_FILE:compose.mariadb.yml"
```
to their .env file to ensure mariadb is still used.

Co-authored-by: Philipp Rothmann <philipprothmann@posteo.de>
Reviewed-on: #26
This commit is contained in:
yksflip 2022-05-18 08:36:26 +00:00
parent c4eed9d8ea
commit 12eea19cab
5 changed files with 93 additions and 28 deletions

View File

@ -5,6 +5,10 @@ DOMAIN=nextcloud.example.com
#EXTRA_DOMAINS=', `www.nextcloud.example.com`'
LETS_ENCRYPT_ENV=production
COMPOSE_FILE="compose.yml"
COMPOSE_FILE="$COMPOSE_FILE:compose.mariadb.yml"
#COMPOSE_FILE="$COMPOSE_FILE:compose.postgres.yml"
ADMIN_USER=admin
SECRET_DB_ROOT_PASSWORD_VERSION=v1

40
compose.mariadb.yml Normal file
View File

@ -0,0 +1,40 @@
version: "3.8"
services:
app:
environment:
- MYSQL_HOST=db
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD_FILE=/run/secrets/db_password
db:
image: "mariadb:10.5"
environment:
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD_FILE=/run/secrets/db_password
- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db_root_password
configs:
- source: my_tune
target: /etc/mysql/conf.d/my-tune.cnf
secrets:
- db_root_password
- db_password
volumes:
- "mariadb:/var/lib/mysql"
networks:
- internal
deploy:
labels:
backupbot.backup: "true"
backupbot.backup.pre-hook: 'mkdir -p /tmp/backup/ && mysqldump --single-transaction -u root -p"$$(cat /run/secrets/db_root_password)" nextcloud > /tmp/backup/backup.sql'
backupbot.backup.post-hook: "rm -rf /tmp/backup"
backupbot.backup.path: "/tmp/backup/"
configs:
my_tune:
name: ${STACK_NAME}_my_cnf_${MY_CNF_VERSION}
file: my-tune.cnf
volumes:
mariadb:

38
compose.postgres.yml Normal file
View File

@ -0,0 +1,38 @@
version: '3.8'
services:
app:
entrypoint: "sh -c 'sleep 10 && /entrypoint.sh php-fpm'" # tries to mitigate this error with postgres https://github.com/nextcloud/docker/issues/1204
environment:
- POSTGRES_HOST=db
- POSTGRES_DB=nextcloud
- POSTGRES_USER=nextcloud
- POSTGRES_PASSWORD_FILE=/run/secrets/db_password
- NEXTCLOUD_UPDATE=1
db:
image: "postgres:12"
volumes:
- "postgres:/var/lib/postgresql/data"
networks:
- internal
environment:
POSTGRES_USER: nextcloud
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
POSTGRES_DB: nextcloud
secrets:
- db_password
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
deploy:
labels:
backupbot.backup: "true"
backupbot.backup.pre-hook: "mkdir -p /tmp/backup/ && PGPASSWORD=$$(cat $${POSTGRES_PASSWORD_FILE}) pg_dump -U $${POSTGRES_USER} $${POSTGRES_DB} > /tmp/backup/backup.sql"
backupbot.backup.post-hook: "rm -rf /tmp/backup"
backupbot.backup.path: "/tmp/backup/"
volumes:
postgres:

View File

@ -33,7 +33,7 @@ services:
- "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLHost=${DOMAIN}"
app:
image: nextcloud:23.0.1-fpm
image: nextcloud:23.0.3-fpm
depends_on:
- db
configs:
@ -45,10 +45,6 @@ services:
environment:
- DOMAIN
- STACK_NAME
- MYSQL_HOST=db
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD_FILE=/run/secrets/db_password
- NEXTCLOUD_ADMIN_USER=${ADMIN_USER}
- NEXTCLOUD_ADMIN_PASSWORD_FILE=/run/secrets/admin_password
- NEXTCLOUD_TRUSTED_DOMAINS=${DOMAIN}
@ -73,28 +69,13 @@ services:
failure_action: rollback
order: start-first
labels:
- "coop-cloud.${STACK_NAME}.version=1.0.0+23.0.1-fpm"
- "coop-cloud.${STACK_NAME}.version=2.0.0+23.0.3-fpm"
- "backupbot.backup=true"
- "backupbot.backup.path=/var/www/html/config/,/var/www/html/data/,/var/www/html/custom_apps/"
db:
image: "mariadb:10.5"
environment:
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD_FILE=/run/secrets/db_password
- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db_root_password
configs:
- source: my_tune
target: /etc/mysql/conf.d/my-tune.cnf
secrets:
- db_root_password
- db_password
volumes:
- "mariadb:/var/lib/mysql"
networks:
- internal
cron:
image: nextcloud:23.0.1-fpm
image: nextcloud:23.0.3-fpm
volumes:
- nextcloud:/var/www/html/
- nextapps:/var/www/html/custom_apps:cached
@ -128,7 +109,6 @@ volumes:
nextapps:
nextdata:
nextconfig:
mariadb:
redis:
configs:
@ -139,9 +119,6 @@ configs:
fpm_tune:
name: ${STACK_NAME}_fpm_tune_${FPM_TUNE_VERSION}
file: fpm-tune.ini
my_tune:
name: ${STACK_NAME}_my_cnf_${MY_CNF_VERSION}
file: my-tune.cnf
networks:
proxy:

View File

@ -0,0 +1,6 @@
2.0.0 introduces a minor nextcloud update to 23.0.3 and moves the database service to a seperate override.yml file to support different database types (mariadb / postgres). This might break your installation. Please add the following snippet to your config .env to ensure the right db is used:
```
COMPOSE_FILE="compose.yml"
COMPOSE_FILE="$COMPOSE_FILE:compose.mariadb.yml"
```