test: replace MinIO with SeaweedFS for S3 backups

This commit is contained in:
daniel.radl 2026-09-17 15:08:55 +02:00
parent 4be0566743
commit 047d6dc30b
6 changed files with 109 additions and 51 deletions

View File

@ -1,19 +0,0 @@
import os
import boto3
def main() -> int:
resource = boto3.resource(
service_name="s3",
endpoint_url="http://minio:9000",
region_name="us-east-1",
aws_access_key_id=os.getenv("S3_ACCESS_KEY"),
aws_secret_access_key=os.getenv("S3_SECRET_KEY"),
)
resource.create_bucket(Bucket="frappe")
return 0
if __name__ == "__main__":
raise SystemExit(main())

55
tests/_wait_for_s3.py Normal file
View File

@ -0,0 +1,55 @@
import os
import time
import boto3
from botocore.config import Config
from botocore.exceptions import (
ClientError,
ConnectionClosedError,
ConnectTimeoutError,
EndpointConnectionError,
ReadTimeoutError,
)
def main() -> int:
endpoint_url = os.environ["S3_ENDPOINT_URL"]
bucket = os.environ["S3_BUCKET"]
client = boto3.client(
"s3",
endpoint_url=endpoint_url,
region_name="us-east-1",
config=Config(
connect_timeout=2,
read_timeout=2,
retries={"max_attempts": 0},
s3={"addressing_style": "path"},
),
)
deadline = time.monotonic() + 60
while True:
try:
# Check credentials and bucket readiness from the backup client's network.
client.head_bucket(Bucket=bucket)
return 0
except ClientError as exc:
status = exc.response["ResponseMetadata"]["HTTPStatusCode"]
if status != 404 and status < 500:
raise
error = exc
except (
ConnectionClosedError,
ConnectTimeoutError,
EndpointConnectionError,
ReadTimeoutError,
) as exc:
error = exc
if time.monotonic() >= deadline:
raise RuntimeError(
f"S3 bucket {bucket!r} at {endpoint_url} was not ready within 60 seconds"
) from error
time.sleep(1)
if __name__ == "__main__":
raise SystemExit(main())

5
tests/compose.s3.yaml Normal file
View File

@ -0,0 +1,5 @@
services:
s3:
image: chrislusf/seaweedfs:latest
profiles: [backup]
command: [mini, -dir=/data]

View File

@ -126,43 +126,57 @@ def python_path():
@dataclass @dataclass
class S3ServiceResult: class S3ServiceResult:
endpoint_url: str
bucket: str
access_key: str access_key: str
secret_key: str secret_key: str
@pytest.fixture @pytest.fixture
def s3_service(python_path: str, compose: Compose): def s3_service(python_path: str, compose: Compose):
endpoint_url = "http://s3:8333"
bucket = "frappe"
access_key = "AKIAIOSFODNN7EXAMPLE" access_key = "AKIAIOSFODNN7EXAMPLE"
secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
cmd = ( container_name = f"{compose.project_name}-s3"
"docker", try:
"run", compose(
"--name", "run",
"minio", "--detach",
"-d", "--no-deps",
"-e", "--use-aliases",
f"MINIO_ACCESS_KEY={access_key}", "--name",
"-e", container_name,
f"MINIO_SECRET_KEY={secret_key}", "-e",
"--network", f"AWS_ACCESS_KEY_ID={access_key}",
f"{compose.project_name}_default", "-e",
"minio/minio", f"AWS_SECRET_ACCESS_KEY={secret_key}",
"server", "-e",
"/data", f"S3_BUCKET={bucket}",
) "s3",
subprocess.check_call(cmd) )
compose("cp", "tests/_wait_for_s3.py", "backend:/tmp")
compose.exec("backend", "bench", "pip", "install", "boto3~=1.34.143")
compose.exec(
"-e",
f"S3_ENDPOINT_URL={endpoint_url}",
"-e",
f"S3_BUCKET={bucket}",
"-e",
f"AWS_ACCESS_KEY_ID={access_key}",
"-e",
f"AWS_SECRET_ACCESS_KEY={secret_key}",
"backend",
python_path,
"/tmp/_wait_for_s3.py",
)
compose("cp", "tests/_create_bucket.py", "backend:/tmp") yield S3ServiceResult(
compose.exec("backend", "bench", "pip", "install", "boto3~=1.34.143") endpoint_url=endpoint_url,
compose.exec( bucket=bucket,
"-e", access_key=access_key,
f"S3_ACCESS_KEY={access_key}", secret_key=secret_key,
"-e", )
f"S3_SECRET_KEY={secret_key}", finally:
"backend", subprocess.call(("docker", "logs", "--tail", "100", container_name))
python_path, subprocess.call(("docker", "rm", "-fv", container_name))
"/tmp/_create_bucket.py",
)
yield S3ServiceResult(access_key=access_key, secret_key=secret_key)
subprocess.call(("docker", "rm", "minio", "-f"))

View File

@ -129,7 +129,7 @@ def test_push_backup(
restic_password = "secret" restic_password = "secret"
compose.bench("--site", frappe_site, "backup", "--with-files") compose.bench("--site", frappe_site, "backup", "--with-files")
restic_args = [ restic_args = [
"--env=RESTIC_REPOSITORY=s3:http://minio:9000/frappe", f"--env=RESTIC_REPOSITORY=s3:{s3_service.endpoint_url}/{s3_service.bucket}",
f"--env=AWS_ACCESS_KEY_ID={s3_service.access_key}", f"--env=AWS_ACCESS_KEY_ID={s3_service.access_key}",
f"--env=AWS_SECRET_ACCESS_KEY={s3_service.secret_key}", f"--env=AWS_SECRET_ACCESS_KEY={s3_service.secret_key}",
f"--env=RESTIC_PASSWORD={restic_password}", f"--env=RESTIC_PASSWORD={restic_password}",
@ -137,6 +137,7 @@ def test_push_backup(
compose.exec(*restic_args, "backend", "restic", "init") compose.exec(*restic_args, "backend", "restic", "init")
compose.exec(*restic_args, "backend", "restic", "backup", "sites") compose.exec(*restic_args, "backend", "restic", "backup", "sites")
compose.exec(*restic_args, "backend", "restic", "snapshots") compose.exec(*restic_args, "backend", "restic", "snapshots")
compose.exec(*restic_args, "backend", "restic", "check", "--read-data")
def test_https(frappe_site: str, compose: Compose): def test_https(frappe_site: str, compose: Compose):

View File

@ -34,6 +34,8 @@ class Compose:
"overrides/compose.mariadb.yaml", "overrides/compose.mariadb.yaml",
"-f", "-f",
"overrides/compose.redis.yaml", "overrides/compose.redis.yaml",
"-f",
"tests/compose.s3.yaml",
] ]
if CI: if CI:
file_args += ("-f", "tests/compose.ci.yaml") file_args += ("-f", "tests/compose.ci.yaml")