mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2025-12-27 11:06:35 +00:00
refactor: migrate to src/ package + add DinD-based E2E runner with debug artifacts
- Replace legacy standalone scripts with a proper src-layout Python package (baudolo backup/restore/configure entrypoints via pyproject.toml) - Remove old scripts/files (backup-docker-to-local.py, recover-docker-from-local.sh, databases.csv.tpl, Todo.md) - Add Dockerfile to build the project image for local/E2E usage - Update Makefile: build image and run E2E via external runner script - Add scripts/test-e2e.sh: - start DinD + dedicated network - recreate DinD data volume (and shared /tmp volume) - pre-pull helper images (alpine-rsync, alpine) - load local baudolo:local image into DinD - run unittest E2E suite inside DinD and abort on first failure - on failure: dump host+DinD diagnostics and archive shared /tmp into artifacts/ - Add artifacts/ debug outputs produced by failing E2E runs (logs, events, tmp archive) https://chatgpt.com/share/694ec23f-0794-800f-9a59-8365bc80f435
This commit is contained in:
84
tests/e2e/test_e2e_files_full.py
Normal file
84
tests/e2e/test_e2e_files_full.py
Normal file
@@ -0,0 +1,84 @@
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from .helpers import (
|
||||
backup_run,
|
||||
backup_path,
|
||||
cleanup_docker,
|
||||
create_minimal_compose_dir,
|
||||
ensure_empty_dir,
|
||||
latest_version_dir,
|
||||
require_docker,
|
||||
unique,
|
||||
write_databases_csv,
|
||||
run,
|
||||
)
|
||||
|
||||
|
||||
class TestE2EFilesFull(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
require_docker()
|
||||
cls.prefix = unique("baudolo-e2e-files-full")
|
||||
cls.backups_dir = f"/tmp/{cls.prefix}/Backups"
|
||||
ensure_empty_dir(cls.backups_dir)
|
||||
|
||||
cls.compose_dir = create_minimal_compose_dir(f"/tmp/{cls.prefix}")
|
||||
cls.repo_name = cls.prefix
|
||||
|
||||
cls.volume_src = f"{cls.prefix}-vol-src"
|
||||
cls.volume_dst = f"{cls.prefix}-vol-dst"
|
||||
cls.containers = []
|
||||
cls.volumes = [cls.volume_src, cls.volume_dst]
|
||||
|
||||
# create source volume with a file
|
||||
run(["docker", "volume", "create", cls.volume_src])
|
||||
run([
|
||||
"docker", "run", "--rm",
|
||||
"-v", f"{cls.volume_src}:/data",
|
||||
"alpine:3.20",
|
||||
"sh", "-lc", "mkdir -p /data && echo 'hello' > /data/hello.txt",
|
||||
])
|
||||
|
||||
# databases.csv (unused, but required by CLI)
|
||||
cls.databases_csv = f"/tmp/{cls.prefix}/databases.csv"
|
||||
write_databases_csv(cls.databases_csv, [])
|
||||
|
||||
# Run backup (files should be copied)
|
||||
backup_run(
|
||||
backups_dir=cls.backups_dir,
|
||||
repo_name=cls.repo_name,
|
||||
compose_dir=cls.compose_dir,
|
||||
databases_csv=cls.databases_csv,
|
||||
database_containers=["dummy-db"],
|
||||
images_no_stop_required=["alpine", "postgres", "mariadb", "mysql"],
|
||||
)
|
||||
|
||||
cls.hash, cls.version = latest_version_dir(cls.backups_dir, cls.repo_name)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls) -> None:
|
||||
cleanup_docker(containers=cls.containers, volumes=cls.volumes)
|
||||
|
||||
def test_files_backup_exists(self) -> None:
|
||||
p = backup_path(self.backups_dir, self.repo_name, self.version, self.volume_src) / "files" / "hello.txt"
|
||||
self.assertTrue(p.is_file(), f"Expected backed up file at: {p}")
|
||||
|
||||
def test_restore_files_into_new_volume(self) -> None:
|
||||
# restore files into dst volume
|
||||
run([
|
||||
"baudolo-restore", "files",
|
||||
self.volume_dst, self.hash, self.version,
|
||||
"--backups-dir", self.backups_dir,
|
||||
"--repo-name", self.repo_name,
|
||||
"--rsync-image", "ghcr.io/kevinveenbirkenbach/alpine-rsync",
|
||||
])
|
||||
|
||||
# verify restored file exists in dst volume
|
||||
p = run([
|
||||
"docker", "run", "--rm",
|
||||
"-v", f"{self.volume_dst}:/data",
|
||||
"alpine:3.20",
|
||||
"sh", "-lc", "cat /data/hello.txt",
|
||||
])
|
||||
self.assertEqual((p.stdout or "").strip(), "hello")
|
||||
Reference in New Issue
Block a user