From 4f7e489bab3328e460ad01c9ba84de6aac39daa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Sun, 1 Nov 2026 00:02:25 +0100 Subject: [PATCH] fix rustup --- Dockerfile | 1 - make_zip.py | 70 +++++++++++++++++++++++++++++++++++++++++ scripts/lib.sh | 2 +- tests/test_packaging.py | 8 +++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 make_zip.py diff --git a/Dockerfile b/Dockerfile index e2b052a..a807981 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,7 +43,6 @@ RUN set -eux; \ cargo --version ENV DATA_DIR=/var/lib/rustbox-package-builder \ - CARGO_HOME=/var/lib/rustbox-package-builder/cargo \ CARGO_TARGET_DIR=/var/lib/rustbox-package-builder/cargo/target COPY scripts/ /opt/rustbox-package-builder/scripts/ diff --git a/make_zip.py b/make_zip.py new file mode 100644 index 0000000..892fab3 --- /dev/null +++ b/make_zip.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +import os +import sys +import zipfile +import subprocess +from pathlib import Path + + +def run_git_command(args, repo_path: Path) -> bytes: + result = subprocess.run( + ["git", *args], + cwd=repo_path, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + check=True, + ) + return result.stdout + + +def get_files_to_archive(repo_path: Path) -> list[str]: + output = run_git_command( + ["ls-files", "--cached", "--others", "--exclude-standard", "-z"], + repo_path, + ) + files = output.decode("utf-8", errors="surrogateescape").split("\0") + return [f for f in files if f] + + +def make_zip(repo_path: Path, output_zip: Path) -> None: + files = get_files_to_archive(repo_path) + + output_zip = output_zip.resolve() + if output_zip.exists(): + output_zip.unlink() + + with zipfile.ZipFile(output_zip, "w", compression=zipfile.ZIP_DEFLATED) as zf: + for rel_path in files: + abs_path = repo_path / rel_path + + if not abs_path.exists(): + continue + + if abs_path.resolve() == output_zip: + continue + + zf.write(abs_path, arcname=rel_path) + + print(f"Created: {output_zip}") + print(f"Added files: {len(files)}") + + +def main(): + repo_path = Path.cwd() + + if len(sys.argv) > 1: + output_zip = Path(sys.argv[1]) + else: + output_zip = repo_path / f"{repo_path.name}.zip" + + try: + run_git_command(["rev-parse", "--show-toplevel"], repo_path) + except subprocess.CalledProcessError: + print("Error: this directory is not a Git repository.", file=sys.stderr) + sys.exit(1) + + make_zip(repo_path, output_zip) + + +if __name__ == "__main__": + main() diff --git a/scripts/lib.sh b/scripts/lib.sh index 1741fdc..6cdfdce 100755 --- a/scripts/lib.sh +++ b/scripts/lib.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -Eeuo pipefail -PACKAGING_REVISION=1 +PACKAGING_REVISION=2 DATA_DIR=${DATA_DIR:-/var/lib/rustbox-package-builder} log() { printf '%s %s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ')" "$*"; } diff --git a/tests/test_packaging.py b/tests/test_packaging.py index 8cd56dc..9544271 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -78,3 +78,11 @@ def test_all_three_linux_families_are_always_published(): for name in ("DEBIAN-BUILD-INFO.txt", "RHEL-BUILD-INFO.txt", "SUSE-BUILD-INFO.txt"): assert name in build assert name in init + + +def test_rustup_installation_and_runtime_cargo_home_are_consistent(): + dockerfile = (ROOT / "Dockerfile").read_text() + assert "CARGO_HOME=/opt/cargo" in dockerfile + runtime_env = dockerfile.split("ENV DATA_DIR=/var/lib/rustbox-package-builder", 1)[1] + assert "CARGO_HOME=/var/lib/rustbox-package-builder/cargo" not in runtime_env + assert "CARGO_TARGET_DIR=/var/lib/rustbox-package-builder/cargo/target" in runtime_env