-
Notifications
You must be signed in to change notification settings - Fork 34
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
max depth exceeded
when trying to load images that have many apt dependencies
#36
Comments
Thank you for filing this! |
WRT
load("@aspect_bazel_lib//lib:tar.bzl", "mtree_spec", "tar", "tar_lib")
def _dedupe_tar_impl(ctx):
"""
Remove duplicate entries in a tarball
This is kinda a hack: extract the mtree file, explode the tarball (handled
overwriting the files), then recreate the tarball from the exploded tree.
This has the effect of removing duplicate entries from the tarball
"""
bsdtar = ctx.toolchains[tar_lib.toolchain_type]
bsdtar_bin = bsdtar.template_variables.variables["BSDTAR_BIN"]
src = ctx.file.src
output_tar = ctx.actions.declare_file("%s.tar.gz" % ctx.label.name)
ctx.actions.run_shell(
outputs = [output_tar],
inputs = [src],
command = """
set -e
export TMP=$(mktemp -d || mktemp -d -t bazel-tmp)
trap "rm -rf $TMP" EXIT
mkdir $TMP/extracted
{bsdtar} --format=mtree -cf - @{src} | egrep -v '^/. ' | sed -e 's|^./||' > {mtree}
{bsdtar} -xf {src} -C $TMP/extracted
{bsdtar} -C $TMP/extracted -caf {output} @{mtree}
""".format(
bsdtar = bsdtar_bin,
src = src.path,
output = output_tar.path,
mtree = "$TMP/mtree.txt",
),
tools = [bsdtar.default.files],
)
return DefaultInfo(files = depset([output_tar]))
dedupe_tar = rule(
implementation = _dedupe_tar_impl,
attrs = {
"src": attr.label(mandatory = True, allow_single_file = True),
},
# XXX: side effect: gzipping the output
outputs = {"output_tar": "%{name}.tar.gz"},
toolchains = [tar_lib.toolchain_type],
) From the above example, I think this would probably work: flatten(
name = "linux_layers_flatten.tar",
tars = select({
"@platforms//cpu:arm64": [
"%s/arm64" % package
for package in PACKAGES
],
"@platforms//cpu:x86_64": [
"%s/amd64" % package
for package in PACKAGES
],
}),
)
dedupe_tar(
name = "linux_layers_deduped.tar",
src = "linux_layers_flatten.tar",
) |
@lazcamus Thank you for the workaround! I'm hitting exactly the same issue while trying to introduce rules_distroless + rules_oci into our builds.
|
Okay i have a PR, that does not extract files to deduplicate; #119 |
To repro:
main/examples/apt/bullseye.yaml
. I can repro this with just addingpython3-minimal
if
statement here:rules_distroless/apt/private/package_resolution.bzl
Line 105 in 789bf1d
bazel run @bullseye//:lock
bazel test //examples/apt/... --test_output=all
Expected output: test passing
Actual output: a bunch of tests failing with
Error: error setting env vars: Error creating container: no such image
From my conversations with @thesayyn , the underlying error is
{"errorDetail":{"message":"max depth exceeded"},"error":"max depth exceeded"}
Googling for that error, seems to be caused by too many docker layers. One workaround is to combine those layers into a single tar:
Then using that
tar
on the image instead of each debian package tar.Presumably, the same should be achievable using
rules_distroless
flatten
rule. However this:does not resolve it. There seems to be an issue with duplicate file paths in
flatten
:The text was updated successfully, but these errors were encountered: