-
Notifications
You must be signed in to change notification settings - Fork 50
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
Implement Docker/OCI layer index file support #69
Comments
One thing that might be nice would be to have a |
Thanks for feedback. We also use rules_docker to package up our springboot apps, and have had good success with it. I am a little worried about building too much into the rules_spring repo, so I am not sold on springboot_image. But it is worth looking into it for sure. We are finding that external rules that bring in other dependencies (e.g. if rules_spring depended on rules_docker) are a pain to deal with. Bazel Federation just didn't take off unfortunately. What I have on the books right now is Issue #94 which is to just provide an example of how to build the docker image by combining springboot rule with rules_docker rules. But, once we implement this layer support, there may be a useful reason to also provide a springboot_image rule so we should consider it. |
@plaird do you have an example of that just for yourself? is it as easy adding the target and main to a container_image? |
@Marcus-Rosti we use
where
|
and @chrismgrayftsinc foo-service.jar is the output of
|
In this case, it looks like it would be the output of the springboot rule (which would need a different name from your library). Assuming you named the springboot rule "mrosti-service", then "foo-service.jar" would be replaced by "mrosti-service.jar". |
@chrismgrayftsinc that worked like a charm! thanks! |
Thanks @Marcus-Rosti for the question, and @chrismgrayftsinc for providing the example. Internally we do some additional fancy pants stuff around custom entrypoints, but what Chris provided covers the 95% case. |
@plaird I went ahead and started a small repo that does this. I heavily modified the springboot.bzl file to do it. I will need to clean it up, but for now it appears to work for our use case. Check it out at https://github.com/chrismgrayftsinc/rules_spring_image |
@chrismgrayftsinc I am looking forward to look at your solution. This week is crazy, but I am hoping to get to this soon. Thanks! |
@chrismgrayftsinc I think you are underselling what you have done - it is more than just layer file support. You also have done a bunch of the needful of migrating off of bash #3 which is the oldest open issue in the project. :) I have a bunch of things in flight right now outside of rules_spring, but I will try to prioritize finding a way to merge your work. I was thinking of using Java based on singlejar for the new rule impl in #3, but if we can get there with Starlark all the better. |
Spring Boot 2.3 added the ability to supply a layer index file that optimizes the writing of the Spring Boot jar for container use cases. It splits the jar into multiple layers such that the base layers contains the mostly static stuff (dependencies, etc) while the top layer contains the stuff that you change a lot more (the app code). This reduces time to download the image, as the base layers are already cached on your host.
This is important because Spring Boot jars often drag in hundreds of dependency jars. It is not uncommon to have 400MB+ Spring Boot jars. Written as a single layer, a single code line change will require hosts that use the image to pull down a full 400MB again.
Overview: https://spring.io/blog/2020/01/27/creating-docker-images-with-spring-boot-2-3-0-m1
(Unfortunately the code snippets in the article lost their line endings, so the examples are hard to read)
Details:
Exploration:
Explore these features with a simple spring boot app and Maven:
Implementation:
After we understand the features and options, we can decide how to implement for the Bazel build system. Guessing at the Bazel implementation, I think it will go something like this:
Much like the classpath index file #33, we need to add a springboot() rule attribute (e.g. layer_index_file) so the user can supply the layer index file. I don't think we should do anything magical here (i.e. auto-generating these files). Just allow the user to specify an existing workspace file via the attribute in the rule. This would be optional as the default layout seems sufficient for most use cases. From there, we will have to figure out the fancy work of splitting the written outputs into the layers. From there, we will need to provide examples of rules_oci building the image in layers.
This work may require changing the springboot rule signature in some incompatible way, so assigning to a major release for now.
The text was updated successfully, but these errors were encountered: