Compare commits

..
Author SHA1 Message Date
stevensting dbc7c53dea add tinyauth protection as an option
continuous-integration/drone/pr Build is failing
2026-11-20 09:39:28 +01:00
moosemower eba27271d2 chore: publish 5.2.1+v3.0.20 release
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is failing
2026-08-24 20:29:28 -07:00
stevensting 86fd81a825 fix postgres backup (#30)
continuous-integration/drone/push Build is failing
<!--
Thank you for doing recipe maintenance work!
Please mark all checklist items which are relevant for your changes.
Please remove the checklist items which are not relevant for your changes.
Feel free to remove this comment.
-->

* [x] I have deployed and tested my changes
* [x] I have [updated relevant versions in `abra.sh`](https://docs.coopcloud.tech/maintainers/upgrade/#updating-versions-in-the-abrash)
* [x] I have made my environment variable changes [backwards compatible](https://docs.coopcloud.tech/maintainers/upgrade/#backwards-compatible-environment-variable-changes)
* [x] I have added a [release note entry](https://docs.coopcloud.tech/maintainers/upgrade/#creating-new-release-notes)

Info for release notes:

> Up until now the backups only worked sporadically, as they used the database volume and not the dump due to wring path. Upgrading to this version will start produce reliable backups. Older backups cannot be restored with backup bot anymore, and should be copied manually. (In case there is a working one)

Reviewed-on: #30
Reviewed-by: Jackie Makdah <jackiemak22@proton.me>
Co-authored-by: stevensting <stefan@klasse-methode.it>
Co-committed-by: stevensting <stefan@klasse-methode.it>
2026-07-17 11:08:45 +00:00
7 changed files with 126 additions and 71 deletions
+4
View File
@@ -26,6 +26,10 @@ REPLY_HOSTNAME=$DOMAIN
RAILS_ENV=production
# Secure page via tiny auth
# COMPOSE_FILE="$COMPOSE_FILE:compose.tinyauth.yml"
# TINY_MIDDLEWARE="sub_example_com"
# Number of webserver processes and threads
# threads are per worker. See https://github.com/puma/puma
PUMA_WORKERS=2
+2 -1
View File
@@ -1,4 +1,5 @@
export LOOMIO_ENTRYPOINT_VERSION=v9
export LOOMIO_ENTRYPOINT_VERSION=v8
export PG_BACKUP_VERSION=v1
# cannot be integrated into entrypoint.sh as it requires the operator to create a user first
function make_last_user_admin()
+6
View File
@@ -0,0 +1,6 @@
version: "3.8"
services:
app:
deploy:
labels:
- "traefik.http.routers.${STACK_NAME}.middlewares=${TINY_MIDDLEWARE}"
+16 -39
View File
@@ -32,7 +32,7 @@ x-environment: &default-env
services:
app:
image: loomio/loomio:3.1
image: loomio/loomio:v3.0.20
configs:
- source: entrypoint
target: /entrypoint.sh
@@ -70,16 +70,15 @@ services:
- "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`${EXTRA_DOMAINS})"
- "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure"
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}"
- "coop-cloud.${STACK_NAME}.version=5.2.0+v3.0.20"
- "coop-cloud.${STACK_NAME}.version=5.2.1+v3.0.20"
- "backupbot.backup:=${ENABLE_BACKUPS:-true}"
- "traefik.http.routers.${STACK_NAME}.middlewares=${STACK_NAME}"
- "traefik.http.middlewares.${STACK_NAME}.headers.accesscontrolallowmethods=GET,OPTIONS,PUT"
- "traefik.http.middlewares.${STACK_NAME}.headers.accesscontrolallowheaders=*"
- "traefik.http.middlewares.${STACK_NAME}.headers.accessControlAllowOriginList=https://*.${DOMAIN}"
- "traefik.http.middlewares.${STACK_NAME}.headers.accesscontrolmaxage=100"
- "traefik.http.middlewares.${STACK_NAME}.headers.addvaryheader=true"
worker:
image: loomio/loomio:3.1
image: loomio/loomio:v3.0.0
configs:
- source: entrypoint
target: /entrypoint.sh
@@ -90,7 +89,7 @@ services:
- secret_cookie_token
- db_password
networks:
- backend
- backend
environment:
!!merge <<: *default-env
TASK: worker
@@ -115,12 +114,14 @@ services:
PGDATA: /pgdata
deploy:
labels:
backupbot.backup: "${ENABLE_BACKUPS:-true}"
backupbot.backup.pre-hook: sh -c 'pg_dump -U "$$POSTGRES_USER" -Fc "$$POSTGRES_DB" | gzip > "/postgres.dump.gz"'
backupbot.backup.path: "/postgres.dump.gz"
backupbot.backup.post-hook: "rm -f /postgres.dump.gz"
backupbot.restore: "true"
backupbot.restore.post-hook: sh -c 'gzip -d /postgres.dump.gz && pg_restore --clean -U "$$POSTGRES_USER" --dbname="$$POSTGRES_DB" < /postgres.dump && rm -f /postgres.dump'
backupbot.backup: ${ENABLE_BACKUPS:-true}
backupbot.backup.volumes.pgdata.path: "backup.sql"
backupbot.backup.pre-hook: "/pg_backup.sh backup"
backupbot.restore.post-hook: '/pg_backup.sh restore'
configs:
- source: pg_backup
target: /pg_backup.sh
mode: 0555
redis:
image: redis:8.0
networks:
@@ -157,7 +158,7 @@ services:
- "traefik.http.routers.channels${STACK_NAME}.entrypoints=web-secure"
cron:
image: loomio/loomio:3.1
image: loomio/loomio:v3.0.0
configs:
- source: entrypoint
target: /entrypoint.sh
@@ -187,33 +188,6 @@ services:
- "swarm.cronjob.schedule=0 * * * *"
restart_policy:
condition: none
haraka:
# container_name: loomio-haraka
image: loomio/haraka-rails-docker:stable
deploy:
restart_policy:
condition: on-failure
networks:
- backend
ports:
- "25:25"
hocuspocus:
# container_name: loomio-hocuspocus
image: loomio/loomio:3.1
deploy:
restart_policy:
condition: on-failure
networks:
- backend
environment:
- TASK=hocuspocus
- VIRTUAL_HOST=hocuspocus.loomio.hackyjackie.com
- LETSENCRYPT_HOST=hocuspocus.loomio.hackyjackie.com
networks:
backend:
proxy:
@@ -230,6 +204,9 @@ configs:
entrypoint:
name: ${STACK_NAME}_entrypoint_${LOOMIO_ENTRYPOINT_VERSION}
file: entrypoint.sh
pg_backup:
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
file: pg_backup.sh
secrets:
devise_secret:
+27 -31
View File
@@ -39,37 +39,33 @@ if [ -n "$1" ]; then
else
echo "starting loomio!"
# if [ "$TASK" = "worker" ]; then
# bundle exec sidekiq
# else
mkdir -p /loomio/public/client3
cp -r /loomio/client3-build/* /loomio/public/client3/
sudo apt update -y && sudo apt install -y postgresql-client
bundle install
# running this code instaed of db:prepare in docker_start.sh in loomio container
# as postgres container creates empty db, somehow db:prepare cannot cope.
# therefore we run db:setup or db:migrate individually
if PGPASSWORD=$(cat /run/secrets/db_password) psql -U "$POSTGRES_USER" -h "$DB_HOST" -lqt | cut -d \| -f 1 | grep -wq "$POSTGRES_DB"; then
echo "database '$POSTGRES_DB' exists."
# check if the database contains tables
TABLE_COUNT=$(PGPASSWORD=$(cat /run/secrets/db_password) psql -U "$POSTGRES_USER" -h "$DB_HOST" -d "$POSTGRES_DB" -t -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';")
if [ "$TABLE_COUNT" -eq 0 ]; then
echo "Database '$POSTGRES_DB' is empty, running db:setup."
bundle exec rake db:setup
else
echo "database '$POSTGRES_DB' not empty, running migrations."
bundle exec rake db:migrate
fi
if [ "$TASK" = "worker" ]; then
bundle exec sidekiq
else
echo "database '$POSTGRES_DB' does not exist, running db:setup."
bundle exec rake db:setup
fi
sudo apt update -y && sudo apt install -y postgresql-client
bundle install
bundle exec puma -C config/puma.rb
# running this code instaed of db:prepare in docker_start.sh in loomio container
# as postgres container creates empty db, somehow db:prepare cannot cope.
# therefore we run db:setup or db:migrate individually
if PGPASSWORD=$(cat /run/secrets/db_password) psql -U "$POSTGRES_USER" -h "$DB_HOST" -lqt | cut -d \| -f 1 | grep -wq "$POSTGRES_DB"; then
echo "database '$POSTGRES_DB' exists."
# check if the database contains tables
TABLE_COUNT=$(PGPASSWORD=$(cat /run/secrets/db_password) psql -U "$POSTGRES_USER" -h "$DB_HOST" -d "$POSTGRES_DB" -t -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';")
if [ "$TABLE_COUNT" -eq 0 ]; then
echo "Database '$POSTGRES_DB' is empty, running db:setup."
bundle exec rake db:setup
else
echo "database '$POSTGRES_DB' not empty, running migrations."
bundle exec rake db:migrate
fi
else
echo "database '$POSTGRES_DB' does not exist, running db:setup."
bundle exec rake db:setup
fi
bundle exec puma -C config/puma.rb
fi
fi
#fi
Executable
+70
View File
@@ -0,0 +1,70 @@
#!/bin/bash
set -e
BACKUP_PATH="/pgdata"
LATEST_BACKUP_FILE="${BACKUP_PATH}/backup.sql"
function backup {
FILE_WITH_DATE="${BACKUP_PATH}/backup_$(date +%F).sql"
if [ -f "$POSTGRES_PASSWORD_FILE" ]; then
export PGPASSWORD=$(cat "$POSTGRES_PASSWORD_FILE")
fi
echo "Creating backup at ${FILE_WITH_DATE}..."
pg_dump -U "${POSTGRES_USER:-postgres}" "${POSTGRES_DB:-postgres}" > "${FILE_WITH_DATE}"
echo "Copying to ${LATEST_BACKUP_FILE}..."
cp -f "${FILE_WITH_DATE}" "${LATEST_BACKUP_FILE}"
echo "Backup done. You will find it at ${LATEST_BACKUP_FILE}"
}
function restore {
echo "Restoring database from ${LATEST_BACKUP_FILE}..."
cd ${BACKUP_PATH}
function restore_config {
echo "Restoring original pg_hba.conf configuration..."
cat pg_hba.conf.bak > pg_hba.conf
su postgres -c 'pg_ctl reload'
}
# Don't allow any other connections than local
echo "Setting up temporary pg_hba.conf to only allow local connections..."
cp pg_hba.conf pg_hba.conf.bak
echo "local all all trust" > pg_hba.conf
su postgres -c 'pg_ctl reload'
trap restore_config EXIT INT TERM
# Recreate Database
echo "Dropping existing database ${POSTGRES_DB:-postgres}..."
psql -U "${POSTGRES_USER:-postgres}" -d postgres -c "DROP DATABASE \"${POSTGRES_DB:-postgres}\" WITH (FORCE);"
echo "Creating fresh database ${POSTGRES_DB:-postgres}..."
createdb -U "${POSTGRES_USER:-postgres}" "${POSTGRES_DB:-postgres}"
echo "Restoring data from ${LATEST_BACKUP_FILE}..."
psql -U "${POSTGRES_USER:-postgres}" -d "${POSTGRES_DB:-postgres}" -1 -f "${LATEST_BACKUP_FILE}"
trap - EXIT INT TERM
restore_config
echo "Database restore completed successfully."
}
# Execute the function passed as argument
case "$1" in
backup)
backup
;;
restore)
restore
;;
*)
echo "Usage: $0 {backup|restore}"
exit 1
;;
esac
+1
View File
@@ -0,0 +1 @@
Backup script improvements contributed by stevensting