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

Add a way to leverage external cache source in Docker export #7687

Open
themightychris opened this issue May 15, 2020 · 7 comments
Open

Add a way to leverage external cache source in Docker export #7687

themightychris opened this issue May 15, 2020 · 7 comments
Labels
Focus:Exporter Type: Bug Issues that describe broken functionality

Comments

@themightychris
Copy link
Contributor

themightychris commented May 15, 2020

The new --multi-layer option for hab pkg export docker is really powerful, but it can't be taken advantage of in a CI environment where the Docker build cache isn't persisted between builds. Instead you end up with 90+ layer images that share nothing.

Docker has a means of using "external cache sources" that can solve this. It involves passing --build-arg BUILDKIT_INLINE_CACHE=1 to docker build to trigger some additional metadata being written into the image, and then next time you rebuild the same image in a new environment, you can docker pull the previous image and specify it via --cache-from during the next docker build.

Currently, there is no way to pass either of these options to the underlying docker build call when using hab pkg export docker --multi-layer. Please either add a way to pass additional arbitrary params to docker build (like HAB_DOCKER_OPTS does for studios) or add higher-level options for enabling an external caching workflow

I haven't been able to identify any downside of BUILDKIT_INLINE_CACHE, other than it only being available in newer engines. Given that --multi-layer is a newer feature behind an option, it might be worth considering having it set BUILDKIT_INLINE_CACHE by default since the whole point of the feature is to maximize cache efficiency, so its output would always include caching metadata. The user should be able to specify --cache-from manually as it will be the user's responsibility in a CI environment to pull a previous build into the local docker cache ahead of time, but it might also make sense for --multi-layer to apply some magic when it's not manually specified like assuming a :latest tag its about to update is a good cache source if it exists already

@themightychris
Copy link
Contributor Author

I misunderstood some things initially, it appears that BUILDKIT_INLINE_CACHE is only necessary when Docker's new build engine BuildKit is enabled with DOCKER_BUILDKIT in the env.

So without buildkit being activated, we really only need a way to pass --cache-from through -- or a general path to append arbitrary docker build args

@themightychris
Copy link
Contributor Author

Another note: it is significant that --cache-from can be passed multiple times

@themightychris
Copy link
Contributor Author

Is this roughly the changes needed?

  1. Add add_cache_arg around here:
    let mut cli = Cli::new(name, about).add_base_packages_args()
  2. Insert one or more --cache-from args around here:
  3. Figure out if buildah has an equivalent, or bail if someone tries to use them together around here:
    cmd.arg("build-using-dockerfile")

@christophermaier christophermaier added Type: Bug Issues that describe broken functionality and removed C-bug labels Jul 24, 2020
@stale
Copy link

stale bot commented Jul 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

@stale stale bot added the Stale label Jul 26, 2021
@themightychris
Copy link
Contributor Author

This is still a major limitation of the feature that could be addressed with a simple passthrough flag

@stale stale bot removed the Stale label Jul 26, 2021
@stale
Copy link

stale bot commented Jul 31, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

1 similar comment
@stale
Copy link

stale bot commented Aug 12, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Focus:Exporter Type: Bug Issues that describe broken functionality
Projects
None yet
Development

No branches or pull requests

2 participants