Skip to content

Support compressed layers in image tarball #1695

Closed

Description

@jonjohnsonjr

I'd like to test an optimization and need a way to signal container_image to write slightly different tarballs.

I will start by adding experimental_tarball_format to container_image, with all kinds of warnings that people should not depend on it, but let's revisit the overall API after I've validated my hypothesis.

Mostly opening this as a stub so I can TODO(#${issue}) it.

Activity

  1. jonjohnsonjr commented on Dec 14, 2020

    @jonjohnsonjr
    ContributorAuthor

    In terms of landing this "for real", would it make sense to have a new rule called container_save that is the dual of container_load and handles serializing container_image to disk?

    We could have (at least) three formats:

    1. "legacy"
    2. "compressed"
    3. "layout"

    I'm not sure if this is bazel-idiomatic or not (cc @smukherj1)?

    I don't have the context for why the way this currently works is via :container-image.tar, maybe @mattmoor can shed light on that?

  2. jonjohnsonjr commented on Dec 14, 2020

    @jonjohnsonjr
    ContributorAuthor

    @alexeagle Matt pointed me at you when I asked for "someone who cares about idiomatic bazel stuff", sorry 😉

    I'm trying to figure out what is more bazel-y an option. Currently, you can serialize a container_image to a tarball by building it with .tar appended to the target name. This made sense in 2015, when there was one form of docker tarball, but there are now three tarball formats in common use. I was experimenting with this by just adding an attribute to container_image to control the tarball format (see linked PR), but this feels kind of gross, because the attribute only applies when building the .tar.

    In my head, it seems reasonable to have a separate container_save rule that is exclusively concerned with serializing other container_* things to disk.

    Which of those options feels better to you?

    Also, if you're willing to let me waste more of your time, and if you care about container images in general, I'd love it if you could tear apart my strawman proposal for rules for assembling multi-platform images in #300 (comment). I know a bit about containers, but not much at all about bazel.

  3. alexeagle commented on Dec 18, 2020

    @alexeagle
    Contributor

    hi! That's nice of Matt to think of me ;)

    feels to me that if the container_image can produce three different tarballs, there should be three different predeclared outputs so you can request the one you want. They'd have to have distinct paths in the output tree as well (thing.formatA.tgz or sth). Bazel semantics are that it only runs actions needed to produce the requested outputs, and by predeclaring them the user can ask for the one they want.

    Adding another rule is maybe useful if there's some novel composition users need where they use a container_save in conjunction with something other than container_image but my guess is you just want to declare more outputs.

  4. jonjohnsonjr commented on Dec 18, 2020

    @jonjohnsonjr
    ContributorAuthor

    First of all, thank you for your time 😄 a lot of this is me just thinking out loud, and I would of course appreciate your guidance on any of it, but I've tried to only mention folks in places where I have specific questions.

    there should be three different predeclared outputs so you can request the one you want. They'd have to have distinct paths in the output tree as well (thing.formatA.tgz or sth). Bazel semantics are that it only runs actions needed to produce the requested outputs, and by predeclaring them the user can ask for the one they want.

    This makes some sense to me. In fact, we were thinking about punning this "compressed" form as thing.tar.gz, but it actually would make more sense to be thing.gz.tar (or something) to avoid confusing people into thinking the output tarball is compressed (instead of the inner tarballs). So with this approach, we'd have thing.tar, thing.gz.tar, and thing.oci.tar. I'd be okay with this, but...

    Adding another rule is maybe useful if there's some novel composition users need where they use a container_save in conjunction with something other than container_image

    So, I think there is actually a novel composition here with other rules, and you've made me think of another argument for a new rule. The end result is that I'd like to write stuff out to a tarball in a new, incompatible format that is more generic than the currentdocker save tarballs. With the linked PR, we basically just compress the tarballs and name things slightly differently, but most clients that can read the legacy tarballs still work with these compressed tarballs, so nothing really breaks.

    I want to write things out in this format which isn't readable by older clients that don't understand it (though... we can massage things a bit to trick them into reading it, which I might end up doing).

    This new format would work with both single images, a collection of images (e.g. container_bundle -- though they would do roughly the same thing...), layers (container_layer), or really any arbitrary thing that has a media type (this ties in with #300 a bit, actually, since they share data structures, and we could use container_descriptor to hack a media type onto anything). You can see in the example at the bottom writing an application/xml file into this makes sense, so maybe container_save is too specific and this should be oci_layout or something... though I primarily want to use it to save containers :)

    tl;dr, I'm thinking that because:

    1. this would (usually) be a breaking change, and
    2. we can compose this with any number of other rules,

    it would make sense to promote this from just an attribute on a few rules to a full-blown new rule.

    but my guess is you just want to declare more outputs.

    @alexeagle Given the above, do you still think this would be the right approach? I might even be more confused now...

    My thinking, in the fullness of time:

    1. We drop the experimental_tarball_format attribute and just add a new ${IMAGE_TARGET}.gz.tar output, probably also make this work for container_bundle.
    2. Implement a new rule that handles writing to an OCI image layout, which will just write to a directory by default (not sure how to reconcile with the intermediate form) with bazel build $OCI_TARGET, but can be bundled into a tar with bazel build ${OCI_TARGET}.tar. I'm not sure if calling this oci_layout or container_save is better 🤷
      1. We could have an attribute that signals bazel to write more files (see Include manifest in the v1 tarball? Or latest OCI image-spec? google/go-containerregistry#651 for way more details, cc @deitch) into this to trick older clients into loading it as a normal docker save tarball, which makes me lean towards container_save, if we're going to have conainer-specific options, but now I'm going in circles...
      2. Maybe this rule should just be called container_index so we don't end up with another rule when I go to implement multi-arch support.

    Lots to consider :) perhaps an interim step (1.5) will be having thing.tar, thing.gz.tar, and thing.oci.tar on container_image and container_bundle, since that requires less design up front, then create a separate issue for a new rule.

    @smukherj1 what do you think? Step 1 seems uncontroversial and you will probably see a PR from me to do this. Step 1.5 probably require a small amount of code review, but does that seem reasonable? Step 2, I imagine, would require some design review, but I'm happy to punt on that for now.

    If I ever get around to doing the new rule, we could make the bazel build thing.oci.tar output essentially just be an alias for bazel build :thing_index.tar where:

    container_index(
      name = "thing_index",
      manifests = [
        ":thing",
      ],
    )

    And we can do the same for container_bundle, but the tag keys would become org.opencontainers.image.ref.name annotations on the descriptors.

  5. github-actions commented on Jun 22, 2021

    @github-actions

    This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.
    Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_docker!

  6. added
    Can Close?
    on Jun 22, 2021
  7. removed
    Can Close?
    on Jun 22, 2021
  8. jonjohnsonjr commented on Jun 22, 2021

    @jonjohnsonjr
    ContributorAuthor

    So, #1696 had fantastic results for our use case, so I see a couple options:

    1. Make this the default
    2. Drop the experimental_ prefix and make tarball_format a "real" thing, but I'm not sure what the most idiomatic approach would be, as described above.
  9. andyliuliming commented on Sep 12, 2021

    @andyliuliming

    any plans to support this for "container_bundle"?

  10. jonjohnsonjr commented on Sep 13, 2021

    @jonjohnsonjr
    ContributorAuthor

    I believe it's just a matter of plumbing the property through, which would be straightforward. Long term, I'd want to just remove this property and make compressed the default as part of switching over to OCI image layout as the on-disk and tarball format, but that's a bit more work.

  11. github-actions commented on Mar 13, 2022

    @github-actions

    This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.
    Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_docker!

  12. added
    Can Close?
    on Mar 13, 2022
  13. github-actions commented on Apr 12, 2022

    @github-actions

    This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Can Close?

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions