Skip to content

fix: Add parent dirs to mtree #96

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rparme
Copy link

@rparme rparme commented May 20, 2025

Nested files/folders in image layers result in InvalidImage(MissingParentDirectory: Parent directory does not exist for file when deploying on AWS if the parent folders aren't listed in the layer archive mtree.


Changes are visible to end-users: no

Test plan

  • Manually built an image with aws_py_lambda with internal and external dependencies, pushed to ECR and deployed on AWS Lambda. Successfully ran code using internal and external dependencies.
  • Successfully built, deploy and tested //examples/python_lambda:tarball
    image
  • Manual testing; please provide instructions so we can reproduce:
bazel run //examples/python_lambda:tarball
# Then push, deploy and run the image on AWS Lambda

@CLAassistant
Copy link

CLAassistant commented May 20, 2025

CLA assistant check
All committers have signed the CLA.

results.append(_mtree_line(parts, type = "dir", mode = "0755"))

return results

# Copied from aspect-bazel-lib/lib/private/tar.bzl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this comment and your the code you are adding, is this something we could simplify by using some rules from https://github.com/bazel-contrib/tar.bzl/blob/main/docs/mtree.md?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What part are you looking to simplify exactly?
The mtree_spec rule simply creates an mtree file for the files passed in srcs, it won't create entries for parent dirs of these files. mtree_mutate has many properties but none that would help either except having a whole different awk_script.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look too much into the details. I just saw this comment and would have guessed that this could be implemented already somewhere else. Nevermind.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we should try to de-duplicate these if we can.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't realize this is related to the comment.
What about making _mtree_line public in @tar.bzl//tar:mtree.bzl, similarly to what is done for s3_sync in rules_aws ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's the obvious answer. However I suspect there's a somewhat more substantial code sharing possible here, since https://github.com/aspect-build/rules_py/blob/main/py/private/py_image_layer.bzl was created after this rule is sketched out. @thesayyn can confirm - or if you have a few minutes to compare the implementations, maybe it's obvious how to do it.

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 this pull request may close these issues.

4 participants