1313# limitations under the License.
1414
1515load ("@io_bazel_rules_docker//container:container.bzl" , "container_bundle" , "container_image" )
16+ load ("@io_bazel_rules_docker//contrib:push-all.bzl" , "docker_push" )
1617load ("//build:platforms.bzl" , "go_platform_constraint" )
1718
1819# multi_arch_container produces a private internal container_image, multiple
1920# arch-specific tagged container_bundles (named NAME-ARCH) and aliases
2021# from NAME and NAME.tar to the appropriately NAME-ARCH container_bundle target
2122# for the currently-configured architecture.
23+ # Additionally, if docker_push_tags is provided, uses multi_arch_container_push
24+ # to create container_bundles named push-NAME-ARCH with the provided push tags,
25+ # along with a push-NAME docker_push target.
2226# Args:
2327# name: name used for the alias; the internal container_image and
2428# container_bundles are based on this name
@@ -29,7 +33,10 @@ load("//build:platforms.bzl", "go_platform_constraint")
2933# docker_tags: list of docker tags to apply to the image. The format string
3034# {ARCH} will be replaced with the configured GOARCH; any stamping variables
3135# should be escaped, e.g. {{STABLE_MY_VAR}}.
32- # tags: will be applied to all rules
36+ # docker_push_tags: list of docker tags to apply to the image for pushing.
37+ # The format string {ARCH} will be replaced with the configured GOARCH;
38+ # any stamping variables should be escaped, e.g. {{STABLE_MY_VAR}}.
39+ # tags: will be applied to all targets
3340# visiblity: will be applied only to the container_bundles; the internal
3441# container_image is private
3542# All other args will be applied to the internal container_image.
@@ -38,6 +45,7 @@ def multi_arch_container(
3845 architectures ,
3946 base ,
4047 docker_tags ,
48+ docker_push_tags = None ,
4149 tags = None ,
4250 visibility = None ,
4351 ** kwargs ):
@@ -70,3 +78,45 @@ def multi_arch_container(
7078 for arch in architectures
7179 }),
7280 )
81+
82+ if docker_push_tags :
83+ multi_arch_container_push (
84+ name = name ,
85+ architectures = architectures ,
86+ docker_tags_images = {docker_push_tag : ":%s-internal" % name for docker_push_tag in docker_push_tags },
87+ tags = tags ,
88+ )
89+
90+ # multi_arch_container_push creates container_bundles named push-NAME-ARCH for
91+ # the provided architectures, populating them with the images directory.
92+ # It additionally creates a push-NAME docker_push rule which can be run to
93+ # push the images to a Docker repository.
94+ # Args:
95+ # name: name used for targets created by this macro; the internal
96+ # container_bundles are based on this name
97+ # architectures: list of architectures (in GOARCH naming parlance) to
98+ # configure
99+ # docker_tags_images: dictionary mapping docker tag to the corresponding
100+ # container_image target. The format string {ARCH} will be replaced
101+ # in tags with the configured GOARCH; any stamping variables should be
102+ # escaped, e.g. {{STABLE_MY_VAR}}.
103+ # tags: applied to container_bundle targets
104+ def multi_arch_container_push (
105+ name ,
106+ architectures ,
107+ docker_tags_images ,
108+ tags = None ):
109+ for arch in architectures :
110+ container_bundle (
111+ name = "push-%s-%s" % (name , arch ),
112+ images = {tag .format (ARCH = arch ): image for tag , image in docker_tags_images .items ()},
113+ tags = tags ,
114+ visibility = ["//visibility:private" ],
115+ )
116+ docker_push (
117+ name = "push-%s" % name ,
118+ bundle = select ({
119+ go_platform_constraint (os = "linux" , arch = arch ): "push-%s-%s" % (name , arch )
120+ for arch in architectures
121+ }),
122+ )
0 commit comments