Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rules_distroless only supports repositories with xz-compressed indices #39

Closed
mortenmj opened this issue Apr 26, 2024 · 1 comment · Fixed by #40
Closed

rules_distroless only supports repositories with xz-compressed indices #39

mortenmj opened this issue Apr 26, 2024 · 1 comment · Fixed by #40

Comments

@mortenmj
Copy link
Contributor

When attempting to resolve a repository with a Packages.gz file, the resolver fails to download the index as it only looks for Packages.xz files.

@mortenmj
Copy link
Contributor Author

Something like this could work:

diff --git apt/private/package_index.bzl apt/private/package_index.bzl
index 620a021..e4e5636 100644
--- apt/private/package_index.bzl
+++ apt/private/package_index.bzl
@@ -4,17 +4,25 @@ load(":util.bzl", "util")
 
 def _fetch_package_index(rctx, url, dist, comp, arch, integrity):
     target_triple = "{dist}/{comp}/{arch}".format(dist = dist, comp = comp, arch = arch)
-    output = "{}/Packages.xz".format(target_triple)
-    r = rctx.download(
-        url = "{}/dists/{}/{}/binary-{}/Packages.xz".format(url, dist, comp, arch),
-        output = output,
-        integrity = integrity,
-    )
-    rctx.execute([
-        "xz",
-        "--decompress",
-        output,
-    ])
+
+    file_types = {"xz": ["xz", "--decompress"], "gz": ["gzip", "-d"]}
+    success = False
+    for file_type, tool in file_types.items():
+        output = "{}/Packages.{}".format(target_triple, file_type)
+        r = rctx.download(
+            url = "{}/dists/{}/{}/binary-{}/Packages.{}".format(url, dist, comp, arch, file_type),
+            output = output,
+            integrity = integrity,
+            allow_fail=True,
+        )
+        if r.success:
+            rctx.execute(tool + [output])
+            success = True
+            break
+
+    if not success:
+        fail("unable to download package index")
+
     return ("{}/Packages".format(target_triple), r.integrity)
 
 def _parse_package_index(state, contents, arch, root):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant