refactor(docker): separate core and optional compose services
Heimdall Gitea / Detect CI scope (pull_request) Successful in 5s
Heimdall Gitea / Build and tests (pull_request) Successful in 13m35s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Successful in 6m28s
Heimdall Gitea / Build and scan server image (pull_request) Successful in 8m24s
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Successful in 3s
Heimdall Gitea / Detect CI scope (pull_request) Successful in 5s
Heimdall Gitea / Build and tests (pull_request) Successful in 13m35s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Successful in 6m28s
Heimdall Gitea / Build and scan server image (pull_request) Successful in 8m24s
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Successful in 3s
This commit is contained in:
1 parent
25dc4869d2
commit
88033e8e26
25 files changed
+507
-714
No files matched your search
@@ -1,70 +1,51 @@
|
||||
# ─── Heimdall — Backup Cron Service ──────────────────────────────
|
||||
# Overlay for docker-compose.yml: adds a cron container that runs
|
||||
# PostgreSQL backups daily and RustFS mirrors weekly.
|
||||
#
|
||||
# Usage:
|
||||
# docker compose -f docker/docker-compose.yml -f docker/docker-compose.backup.yml up -d
|
||||
#
|
||||
# The cron service mounts the scripts directory and a backup volume.
|
||||
# PostgreSQL dumps are uploaded to RustFS/S3 when configured.
|
||||
#
|
||||
# Requires: .env with DATABASE_URL, S3 credentials (optional for local-only backups)
|
||||
# ──────────────────────────────────────────────────────────────────
|
||||
# Optional scheduled backup container. Requires the core PostgreSQL service
|
||||
# and its shared heimdall-net to be running first.
|
||||
services:
|
||||
backup:
|
||||
image: postgres:17-alpine
|
||||
container_name: heimdall-backup
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
# Pass through all env vars needed by backup scripts
|
||||
POSTGRES_HOST: postgresql
|
||||
POSTGRES_PORT: "5432"
|
||||
POSTGRES_DB: ${POSTGRES_DB:-heimdall}
|
||||
POSTGRES_USER: ${POSTGRES_USER:-heimdall}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required}
|
||||
# S3/RustFS config (optional — backup works local-only without these)
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
|
||||
RUSTFS_ENDPOINT: ${RUSTFS_ENDPOINT:-http://rustfs:9000}
|
||||
RUSTFS_ACCESS_KEY: ${RUSTFS_ACCESS_KEY:-${S3_ACCESS_KEY:-}}
|
||||
RUSTFS_SECRET_KEY: ${RUSTFS_SECRET_KEY:-${S3_SECRET_KEY:-}}
|
||||
RUSTFS_BUCKET: ${RUSTFS_BUCKET:-${S3_BUCKET:-heimdall}}
|
||||
# Backup config
|
||||
RUSTFS_ACCESS_KEY: ${RUSTFS_ACCESS_KEY:-}
|
||||
RUSTFS_SECRET_KEY: ${RUSTFS_SECRET_KEY:-}
|
||||
RUSTFS_BUCKET: ${RUSTFS_BUCKET:-heimdall}
|
||||
BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-30}
|
||||
BACKUP_RETENTION_WEEKS: ${BACKUP_RETENTION_WEEKS:-12}
|
||||
BACKUP_LOCAL_DIR: /backups
|
||||
# Timezone
|
||||
TZ: Europe/Paris
|
||||
TZ: ${TZ:-Europe/Paris}
|
||||
secrets:
|
||||
- db_password
|
||||
volumes:
|
||||
- ./scripts:/scripts:ro
|
||||
- backup_data:/backups
|
||||
depends_on:
|
||||
postgresql:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- heimdall-net
|
||||
entrypoint: ["/bin/sh", "-c"]
|
||||
command:
|
||||
- |
|
||||
# Install mc (MinIO client) for S3 uploads
|
||||
apk add --no-cache curl bash > /dev/null 2>&1 || true
|
||||
curl -sSL https://dl.min.io/client/mc/release/linux-amd64/mc -o /usr/local/bin/mc 2>/dev/null || true
|
||||
export POSTGRES_PASSWORD="$$(cat /run/secrets/db_password)"
|
||||
apk add --no-cache curl bash >/dev/null 2>&1 || true
|
||||
curl -fsSL https://dl.min.io/client/mc/release/linux-amd64/mc -o /usr/local/bin/mc || true
|
||||
chmod +x /usr/local/bin/mc 2>/dev/null || true
|
||||
chmod +x /scripts/*.sh
|
||||
|
||||
# Create crontab
|
||||
echo "# Daily PostgreSQL backup at 02:00 UTC" > /tmp/crontab.txt
|
||||
echo "0 2 * * * /scripts/backup.sh >> /var/log/backup.log 2>&1" >> /tmp/crontab.txt
|
||||
echo "# Weekly RustFS mirror on Sundays at 03:00 UTC" >> /tmp/crontab.txt
|
||||
echo "0 3 * * 0 /scripts/backup-rustfs.sh >> /var/log/backup-rustfs.log 2>&1" >> /tmp/crontab.txt
|
||||
echo "# Log rotation weekly" >> /tmp/crontab.txt
|
||||
echo "0 4 * * 0 if [ -f /var/log/backup.log ]; then mv /var/log/backup.log /var/log/backup.log.\$$(date +\%Y\%W); fi" >> /tmp/crontab.txt
|
||||
|
||||
echo '0 2 * * * /scripts/backup.sh >> /var/log/backup.log 2>&1' > /tmp/crontab.txt
|
||||
echo '0 3 * * 0 /scripts/backup-rustfs.sh >> /var/log/backup-rustfs.log 2>&1' >> /tmp/crontab.txt
|
||||
crontab /tmp/crontab.txt
|
||||
echo "Crontab installed:"
|
||||
crontab -l
|
||||
|
||||
# Run crond in foreground
|
||||
exec crond -f -l 2
|
||||
|
||||
volumes:
|
||||
backup_data:
|
||||
driver: local
|
||||
|
||||
secrets:
|
||||
db_password:
|
||||
file: ./secrets/db_password
|
||||
|
||||
networks:
|
||||
heimdall-net:
|
||||
name: heimdall-net
|
||||
external: true
|
||||
Reference in new issue
Block a user