-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: publish multi-arch images (#199)
- Loading branch information
Showing
7 changed files
with
103 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,54 @@ | ||
load("@io_bazel_rules_docker//container:container.bzl", "container_push") | ||
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup") | ||
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index", "oci_push") | ||
load("@rules_pkg//pkg:tar.bzl", "pkg_tar") | ||
|
||
def multiarch_go_image(name, binary): | ||
"""Create a container image with two variants of the given go_binary target. | ||
Args: | ||
name: resulting oci_image_index target | ||
binary: label of a go_binary target; it may be transitioned to another architecture | ||
""" | ||
images = [] | ||
tar_target = "_{}.tar".format(name) | ||
image_target = "_{}.image".format(name) | ||
|
||
pkg_tar( | ||
name = tar_target, | ||
srcs = [binary], | ||
include_runfiles = True, | ||
package_dir = "app", | ||
) | ||
|
||
oci_image( | ||
name = image_target, | ||
base = "@distroless_static", | ||
entrypoint = ["/app/{}".format(native.package_relative_label(binary).name)], | ||
tars = [tar_target], | ||
# Don't build un-transitioned images, as the default target architecture might be unsupported | ||
# For example when building on linux-i386. | ||
tags = ["manual"], | ||
) | ||
|
||
for arch in ["amd64", "arm64"]: | ||
arch_image_target = "{}_{}_image".format(name, arch) | ||
target_platform = "@io_bazel_rules_go//go/toolchain:linux_{}".format(arch) | ||
images.append(arch_image_target) | ||
platform_transition_filegroup( | ||
name = arch_image_target, | ||
srcs = [image_target], | ||
target_platform = target_platform, | ||
) | ||
|
||
oci_image_index( | ||
name = name, | ||
images = images, | ||
) | ||
|
||
def container_push_official(name, image, component): | ||
container_push( | ||
oci_push( | ||
name = name, | ||
format = "Docker", | ||
image = image, | ||
registry = "ghcr.io", | ||
repository = "buildbarn/" + component, | ||
tag = "{BUILD_SCM_TIMESTAMP}-{BUILD_SCM_REVISION}", | ||
repository = "ghcr.io/buildbarn/" + component, | ||
remote_tags = "@com_github_buildbarn_bb_storage//tools:stamped_tags", | ||
) |
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