ci: backup DB before every deploy, fix deploy conflict error
- Add "Backup database" step that copies drsousan.db out of the running container to /opt/drsousan-backups/ before any container changes, keeping the last 10 backups - Replace --force-recreate (broken on this Docker version) with explicit docker stop + docker rm before docker compose up Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -90,6 +90,22 @@ jobs:
|
||||
env:
|
||||
DOCKER_BUILDKIT: 1
|
||||
|
||||
- name: Backup database
|
||||
run: |
|
||||
BACKUP_DIR="/opt/drsousan-backups"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
STAMP=$(date +%Y%m%d-%H%M%S)
|
||||
# Copy DB out of volume before any container changes
|
||||
if docker ps -q --filter name=drsousan_api | grep -q .; then
|
||||
docker cp drsousan_api:/data/drsousan.db "$BACKUP_DIR/drsousan-$STAMP.db" && \
|
||||
echo "✅ DB backed up → $BACKUP_DIR/drsousan-$STAMP.db" || \
|
||||
echo "⚠️ DB backup failed (non-fatal)"
|
||||
else
|
||||
echo "ℹ️ Container not running — skipping backup"
|
||||
fi
|
||||
# Keep last 10 backups only
|
||||
ls -t "$BACKUP_DIR"/*.db 2>/dev/null | tail -n +11 | xargs -r rm
|
||||
|
||||
- name: Deploy
|
||||
run: |
|
||||
docker stop drsousan_api 2>/dev/null || true
|
||||
|
||||
Reference in New Issue
Block a user