From 0b64135f988dd9d60d829303aad1a60afc2d4623 Mon Sep 17 00:00:00 2001 From: notplants <@notplants> Date: Tue, 23 Jun 2026 19:13:39 +0000 Subject: [PATCH 1/2] run migrations automatically on backend startup (AUTO_MIGRATIONS) Add a migrate.sh config (ported from lasuite-docs) that the backend entrypoint runs when AUTO_MIGRATIONS=true (default). It loads secrets, waits for the DB, and idempotently applies pending migrations via 'migrate --check' then 'migrate --noinput'. The manual 'abra app cmd backend migrate' now delegates to the same script. --- .env.sample | 6 ++++++ README.md | 3 ++- abra.sh | 4 ++-- compose.yml | 10 +++++++++- migrate.sh | 26 ++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 migrate.sh diff --git a/.env.sample b/.env.sample index 4a669dd..ca26604 100644 --- a/.env.sample +++ b/.env.sample @@ -68,6 +68,12 @@ LOGGING_LEVEL_HANDLERS_CONSOLE=INFO LOGGING_LEVEL_LOGGERS_ROOT=INFO LOGGING_LEVEL_LOGGERS_APP=INFO +############################################################################## +# MIGRATIONS +############################################################################## +# Set to false to disable automatic migrations on backend startup +# AUTO_MIGRATIONS=true + ############################################################################## # COLLABORA ADMIN PANEL ############################################################################## diff --git a/README.md b/README.md index 5ee60c6..f457c66 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,12 @@ This recipe requires four domains. One domain for drive, and one for minio which * `abra app config ` - make sure to set MINIO_DOMAIN, COLLABORA_DOMAIN, ONLY_OFFICE_DOMAIN to the domains you set up for each. * `abra app deploy ` -* `abra app cmd backend migrate` # creates database tables * `abra app restart minio-createbuckets` (Note: this will appear to fail, but probably worked! Check `abra app logs minio-createbuckets`) You should then be able to visit the landing page of your app, but not yet to login. To login, you need to deploy and integrate single sign on (described below in the "Configure Authentication" section). +* Migrations run automatically on backend startup. To trigger manually: `abra app cmd backend migrate` + Wopi discovery is supposed to happen automatically, but if collabora/onlyoffice are not connecting, you can try running: * `abra app cmd backend trigger_wopi` # connects only office & collabora (if they stop working, try running this again) diff --git a/abra.sh b/abra.sh index 5c0a8e4..aa44a01 100755 --- a/abra.sh +++ b/abra.sh @@ -4,6 +4,7 @@ export ABRA_ENTRYPOINT_VERSION=v11 export NGINX_CONF_VERSION=v6 export ONLYOFFICE_CONF_VERSION=v2 export PG_BACKUP_VERSION=v4 +export MIGRATE_VERSION=v1 environment() { # this exports all the secrets as environment variables @@ -11,8 +12,7 @@ environment() { } migrate() { - environment - python manage.py migrate --noinput + /migrate.sh } trigger_wopi() { diff --git a/compose.yml b/compose.yml index d184ed7..e249b22 100644 --- a/compose.yml +++ b/compose.yml @@ -118,9 +118,11 @@ services: user: ${DOCKER_USER:-1000} image: lasuite/drive-backend:v0.19.0 command: [ "gunicorn", "-c", "/usr/local/etc/gunicorn/drive.py", "drive.wsgi:application" ] - entrypoint: [ "/abra-entrypoint.sh", "/usr/local/bin/entrypoint" ] + entrypoint: > + sh -c "if [ \"$$AUTO_MIGRATIONS\" = \"true\" ]; then /migrate.sh; fi && exec /abra-entrypoint.sh /usr/local/bin/entrypoint \"$$@\"" -- environment: <<: [ *common-env, *postgres-env ] + AUTO_MIGRATIONS: "${AUTO_MIGRATIONS:-true}" networks: - backend depends_on: @@ -129,6 +131,9 @@ services: - source: abra_entrypoint target: /abra-entrypoint.sh mode: 0555 + - source: migrate + target: /migrate.sh + mode: 0555 secrets: - django_sk - django_sp @@ -405,6 +410,9 @@ configs: abra_entrypoint: name: ${STACK_NAME}_entrypoint_${ABRA_ENTRYPOINT_VERSION} file: abra-entrypoint.sh + migrate: + name: ${STACK_NAME}_migrate_${MIGRATE_VERSION} + file: migrate.sh onlyoffice_conf: name: ${STACK_NAME}_onlyoffice_conf_${ONLYOFFICE_CONF_VERSION} file: onlyoffice-config.json.tmpl diff --git a/migrate.sh b/migrate.sh new file mode 100644 index 0000000..52b5435 --- /dev/null +++ b/migrate.sh @@ -0,0 +1,26 @@ +#!/bin/sh +set -e + +# Load secrets into environment +source /abra-entrypoint.sh -e + +# Wait for database to be ready (up to 30 seconds) +i=0 +while ! python manage.py check --database default 2>/dev/null; do + i=$((i+1)) + if [ "$i" -ge 30 ]; then + echo "migrate: timed out waiting for database" >&2 + exit 1 + fi + sleep 1 +done + +# Idempotent: skip if no pending migrations +if python manage.py migrate --check > /dev/null 2>&1; then + echo "migrate: no pending migrations, skipping" + exit 0 +fi + +echo "migrate: applying pending migrations..." +python manage.py migrate --noinput +echo "migrate: done" From 9e4c194783ab2352d0fd8b34aae439bc9886b0f5 Mon Sep 17 00:00:00 2001 From: notplants <@notplants> Date: Tue, 23 Jun 2026 19:26:19 +0000 Subject: [PATCH 2/2] create minio bucket automatically on startup (minio-initialize.sh) Replace the one-shot minio-createbuckets service (which required a manual 'abra app restart minio-createbuckets' that appeared to hang) with a minio-initialize.sh config, ported from lasuite-docs. The minio service entrypoint runs it in the background before starting minio; it waits for minio to be ready and idempotently creates the drive-media-storage bucket with versioning. Manual trigger: 'abra app cmd minio minio_initialize'. --- README.md | 2 +- abra.sh | 5 +++++ compose.yml | 31 ++++++++----------------------- minio-initialize.sh | 29 +++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 minio-initialize.sh diff --git a/README.md b/README.md index f457c66..78244db 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,11 @@ This recipe requires four domains. One domain for drive, and one for minio which * `abra app config ` - make sure to set MINIO_DOMAIN, COLLABORA_DOMAIN, ONLY_OFFICE_DOMAIN to the domains you set up for each. * `abra app deploy ` -* `abra app restart minio-createbuckets` (Note: this will appear to fail, but probably worked! Check `abra app logs minio-createbuckets`) You should then be able to visit the landing page of your app, but not yet to login. To login, you need to deploy and integrate single sign on (described below in the "Configure Authentication" section). * Migrations run automatically on backend startup. To trigger manually: `abra app cmd backend migrate` +* Minio buckets are created automatically on first deploy. To manually trigger: `abra app cmd minio minio_initialize` Wopi discovery is supposed to happen automatically, but if collabora/onlyoffice are not connecting, you can try running: diff --git a/abra.sh b/abra.sh index aa44a01..ad1496b 100755 --- a/abra.sh +++ b/abra.sh @@ -5,6 +5,7 @@ export NGINX_CONF_VERSION=v6 export ONLYOFFICE_CONF_VERSION=v2 export PG_BACKUP_VERSION=v4 export MIGRATE_VERSION=v1 +export MINIO_INITIALIZE_VERSION=v1 environment() { # this exports all the secrets as environment variables @@ -15,6 +16,10 @@ migrate() { /migrate.sh } +minio_initialize() { + /minio-initialize.sh +} + trigger_wopi() { environment python manage.py trigger_wopi_configuration diff --git a/compose.yml b/compose.yml index e249b22..38f8474 100644 --- a/compose.yml +++ b/compose.yml @@ -228,28 +228,6 @@ services: networks: - backend - minio-createbuckets: - image: minio/minio:RELEASE.2025-09-07T16-13-09Z - environment: *minio-env - entrypoint: > - sh -c " - MINIO_ROOT_USER=\"\$$(cat /run/secrets/minio_ru)\" && - MINIO_ROOT_PASSWORD=\"\$$(cat /run/secrets/minio_rp)\" && - /usr/bin/mc alias set drive http://minio:9000 \$${MINIO_ROOT_USER} \"\$${MINIO_ROOT_PASSWORD}\" && \ - /usr/bin/mc mb drive/drive-media-storage && \ - /usr/bin/mc version enable drive/drive-media-storage && \ - exit 0;" - deploy: - mode: replicated - replicas: 0 - restart_policy: - condition: none - secrets: - - minio_rp - - minio_ru - networks: - - backend - minio: image: minio/minio:RELEASE.2025-09-07T16-13-09Z environment: *minio-env @@ -262,13 +240,17 @@ services: - backend - proxy command: minio server /data - entrypoint: ["/usr/bin/docker-entrypoint.sh"] + entrypoint: > + sh -c "/minio-initialize.sh & exec /usr/bin/docker-entrypoint.sh \"$$@\"" -- volumes: - minio:/data configs: - source: abra_entrypoint target: /abra-entrypoint.sh mode: 0555 + - source: minio_initialize + target: /minio-initialize.sh + mode: 0555 secrets: - minio_rp - minio_ru @@ -413,6 +395,9 @@ configs: migrate: name: ${STACK_NAME}_migrate_${MIGRATE_VERSION} file: migrate.sh + minio_initialize: + name: ${STACK_NAME}_minio_initialize_${MINIO_INITIALIZE_VERSION} + file: minio-initialize.sh onlyoffice_conf: name: ${STACK_NAME}_onlyoffice_conf_${ONLYOFFICE_CONF_VERSION} file: onlyoffice-config.json.tmpl diff --git a/minio-initialize.sh b/minio-initialize.sh new file mode 100644 index 0000000..cb36278 --- /dev/null +++ b/minio-initialize.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -e + +# Wait for minio to be ready (up to 60 seconds) +i=0 +while ! mc ready local 2>/dev/null; do + i=$((i+1)) + if [ "$i" -ge 60 ]; then + echo "minio-initialize: timed out waiting for minio to be ready" >&2 + exit 1 + fi + sleep 1 +done + +MINIO_ROOT_USER="$(cat /run/secrets/minio_ru)" +MINIO_ROOT_PASSWORD="$(cat /run/secrets/minio_rp)" + +mc alias set drive http://localhost:9000 "${MINIO_ROOT_USER}" "${MINIO_ROOT_PASSWORD}" + +# Idempotent: skip if bucket already exists +if mc ls drive/drive-media-storage > /dev/null 2>&1; then + echo "minio-initialize: bucket 'drive-media-storage' already exists, skipping" + exit 0 +fi + +echo "minio-initialize: creating bucket 'drive-media-storage'..." +mc mb drive/drive-media-storage +mc version enable drive/drive-media-storage +echo "minio-initialize: done"