From 047d6dc30b4b6f636e900a6383035363351617a3 Mon Sep 17 00:00:00 2001 From: "daniel.radl" Date: Thu, 17 Sep 2026 15:08:55 +0200 Subject: [PATCH 1/2] test: replace MinIO with SeaweedFS for S3 backups --- tests/_create_bucket.py | 19 ---------- tests/_wait_for_s3.py | 55 +++++++++++++++++++++++++++ tests/compose.s3.yaml | 5 +++ tests/conftest.py | 76 ++++++++++++++++++++++--------------- tests/test_frappe_docker.py | 3 +- tests/utils.py | 2 + 6 files changed, 109 insertions(+), 51 deletions(-) delete mode 100644 tests/_create_bucket.py create mode 100644 tests/_wait_for_s3.py create mode 100644 tests/compose.s3.yaml diff --git a/tests/_create_bucket.py b/tests/_create_bucket.py deleted file mode 100644 index e0b55cb..0000000 --- a/tests/_create_bucket.py +++ /dev/null @@ -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()) diff --git a/tests/_wait_for_s3.py b/tests/_wait_for_s3.py new file mode 100644 index 0000000..fe1c9ce --- /dev/null +++ b/tests/_wait_for_s3.py @@ -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()) diff --git a/tests/compose.s3.yaml b/tests/compose.s3.yaml new file mode 100644 index 0000000..9a770ee --- /dev/null +++ b/tests/compose.s3.yaml @@ -0,0 +1,5 @@ +services: + s3: + image: chrislusf/seaweedfs:latest + profiles: [backup] + command: [mini, -dir=/data] diff --git a/tests/conftest.py b/tests/conftest.py index 63169e3..132da08 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -126,43 +126,57 @@ def python_path(): @dataclass class S3ServiceResult: + endpoint_url: str + bucket: str access_key: str secret_key: str @pytest.fixture def s3_service(python_path: str, compose: Compose): + endpoint_url = "http://s3:8333" + bucket = "frappe" access_key = "AKIAIOSFODNN7EXAMPLE" secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" - cmd = ( - "docker", - "run", - "--name", - "minio", - "-d", - "-e", - f"MINIO_ACCESS_KEY={access_key}", - "-e", - f"MINIO_SECRET_KEY={secret_key}", - "--network", - f"{compose.project_name}_default", - "minio/minio", - "server", - "/data", - ) - subprocess.check_call(cmd) + container_name = f"{compose.project_name}-s3" + try: + compose( + "run", + "--detach", + "--no-deps", + "--use-aliases", + "--name", + container_name, + "-e", + f"AWS_ACCESS_KEY_ID={access_key}", + "-e", + f"AWS_SECRET_ACCESS_KEY={secret_key}", + "-e", + f"S3_BUCKET={bucket}", + "s3", + ) + 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") - compose.exec("backend", "bench", "pip", "install", "boto3~=1.34.143") - compose.exec( - "-e", - f"S3_ACCESS_KEY={access_key}", - "-e", - f"S3_SECRET_KEY={secret_key}", - "backend", - python_path, - "/tmp/_create_bucket.py", - ) - - yield S3ServiceResult(access_key=access_key, secret_key=secret_key) - subprocess.call(("docker", "rm", "minio", "-f")) + yield S3ServiceResult( + endpoint_url=endpoint_url, + bucket=bucket, + access_key=access_key, + secret_key=secret_key, + ) + finally: + subprocess.call(("docker", "logs", "--tail", "100", container_name)) + subprocess.call(("docker", "rm", "-fv", container_name)) diff --git a/tests/test_frappe_docker.py b/tests/test_frappe_docker.py index 6eadeb5..ca4d2df 100644 --- a/tests/test_frappe_docker.py +++ b/tests/test_frappe_docker.py @@ -129,7 +129,7 @@ def test_push_backup( restic_password = "secret" compose.bench("--site", frappe_site, "backup", "--with-files") 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_SECRET_ACCESS_KEY={s3_service.secret_key}", 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", "backup", "sites") compose.exec(*restic_args, "backend", "restic", "snapshots") + compose.exec(*restic_args, "backend", "restic", "check", "--read-data") def test_https(frappe_site: str, compose: Compose): diff --git a/tests/utils.py b/tests/utils.py index a58be1b..dc0fd1f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -34,6 +34,8 @@ class Compose: "overrides/compose.mariadb.yaml", "-f", "overrides/compose.redis.yaml", + "-f", + "tests/compose.s3.yaml", ] if CI: file_args += ("-f", "tests/compose.ci.yaml") From 8c927fc996e8e524975b6e5aa8326d523f6dbc8a Mon Sep 17 00:00:00 2001 From: "daniel.radl" Date: Thu, 17 Sep 2026 15:29:33 +0200 Subject: [PATCH 2/2] test: start SeaweedFS directly with docker run --- tests/compose.s3.yaml | 5 ----- tests/conftest.py | 36 ++++++++++++++++++++++-------------- tests/utils.py | 2 -- 3 files changed, 22 insertions(+), 21 deletions(-) delete mode 100644 tests/compose.s3.yaml diff --git a/tests/compose.s3.yaml b/tests/compose.s3.yaml deleted file mode 100644 index 9a770ee..0000000 --- a/tests/compose.s3.yaml +++ /dev/null @@ -1,5 +0,0 @@ -services: - s3: - image: chrislusf/seaweedfs:latest - profiles: [backup] - command: [mini, -dir=/data] diff --git a/tests/conftest.py b/tests/conftest.py index 132da08..450d42d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -140,20 +140,28 @@ def s3_service(python_path: str, compose: Compose): secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" container_name = f"{compose.project_name}-s3" try: - compose( - "run", - "--detach", - "--no-deps", - "--use-aliases", - "--name", - container_name, - "-e", - f"AWS_ACCESS_KEY_ID={access_key}", - "-e", - f"AWS_SECRET_ACCESS_KEY={secret_key}", - "-e", - f"S3_BUCKET={bucket}", - "s3", + subprocess.check_call( + ( + "docker", + "run", + "--detach", + "--pull=always", + "--name", + container_name, + "--network", + f"{compose.project_name}_default", + "--network-alias", + "s3", + "-e", + f"AWS_ACCESS_KEY_ID={access_key}", + "-e", + f"AWS_SECRET_ACCESS_KEY={secret_key}", + "-e", + f"S3_BUCKET={bucket}", + "chrislusf/seaweedfs:latest", + "mini", + "-dir=/data", + ) ) compose("cp", "tests/_wait_for_s3.py", "backend:/tmp") compose.exec("backend", "bench", "pip", "install", "boto3~=1.34.143") diff --git a/tests/utils.py b/tests/utils.py index dc0fd1f..a58be1b 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -34,8 +34,6 @@ class Compose: "overrides/compose.mariadb.yaml", "-f", "overrides/compose.redis.yaml", - "-f", - "tests/compose.s3.yaml", ] if CI: file_args += ("-f", "tests/compose.ci.yaml")