forked from bazelbuild/rules_docker
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve py_image layering (bazelbuild#324)
Consider the following more complex python image that uses the pip requirement feature of rules_python: load("@pip_deps//:requirements.bzl", "requirement") py_library( name = "py_image_library_with_external_deps", srcs = ["py_image_library.py"], deps = [requirement("tensorflow")], ) py_library( name = "py_image_library", srcs = ["py_image_library.py"], deps = [":py_image_library_with_external_deps"], ) py_image( name = "py_image_complex", srcs = ["py_image.py"], layers = [ ":py_image_library_with_external_deps", ":py_image_library", ], main = "py_image.py", ) Currently, it will produce the following layers: 301M bazel-bin/testdata/py_image_complex.0-layer.tar 301M bazel-bin/testdata/py_image_complex.1-layer.tar 15M bazel-bin/testdata/py_image_complex-layer.tar This change improves the layering by fixing the following issues: 1. The middle layer does not detect that all tensorflow files were already added by the first layer. 2. The last layer is 15MB in size due to the huge symlink forest. Create a separate symlink layer for each dependency layer to avoid bloating the top layer, while still keeping the dependency layers image agnostic. 3. Getting "tensorflow" to its own layer requires the author of the "py_image" rule to know that libraries transitively depend on "tensorflow". This is not great, since library authors may add and remove dependencies without remembering to update the "layers" list. To counter this, add a new py_layer rule that can be used to select from transitive dependencies and group them to layers, without explicitly naming the transitive dependencies like "tensorflow". With these improvements, the above example can be rewritten as: load("@pip_deps//:requirements.bzl", "requirement") py_library( name = "py_image_library_with_external_deps", srcs = ["py_image_library.py"], deps = [requirement("tensorflow")], ) py_library( name = "py_image_library", srcs = ["py_image_library.py"], deps = [":py_image_library_with_external_deps"], ) py_layer( name = "external_deps", deps = [":py_image_library"], filter = "@", ) py_image( name = "py_image_complex", srcs = ["py_image.py"], layers = [ ":external_deps", ":py_image_library", ], main = "py_image.py", ) This will yield the following layer structure: 310M bazel-bin/testdata/py_image_complex.0-layer.tar (agnostic) 15M bazel-bin/testdata/py_image_complex.0-symlinks-layer.tar (non-agnostic) 10K bazel-bin/testdata/py_image_complex.1-layer.tar (agnostic) 10K bazel-bin/testdata/py_image_complex.1-symlinks-layer.tar (non-agnostic) 20K bazel-bin/testdata/py_image_complex-layer.tar (non-agnostic)
- Loading branch information
Showing
27 changed files
with
603 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.