Skip to content

Commit

Permalink
prow: Add ability to build arm64 images to prow_image macro
Browse files Browse the repository at this point in the history
  • Loading branch information
LorbusChris committed Jul 6, 2021
1 parent 5edb71c commit c150127
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
9 changes: 9 additions & 0 deletions def/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ def tags(targets):
outs["%s:latest-{BUILD_USER}" % img] = target
outs["%s:latest" % img] = target
return outs

def tags_arm64(targets):
outs = {}
for img, target in targets.items():
outs["%s:{DOCKER_TAG}-arm64" % img] = target
outs["%s:latest-{BUILD_USER}-arm64" % img] = target
outs["%s:latest-arm64" % img] = target
outs["%s:arm64" % img] = target
return outs
37 changes: 36 additions & 1 deletion prow/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ load("@io_bazel_rules_k8s//k8s:objects.bzl", "k8s_objects")
load(
"//def:image.bzl",
_image_tags = "tags",
_image_tags_arm64 = "tags_arm64",
)

## prow_image is a macro for creating :app and :image targets
# prow_image is a macro for creating :app and :image targets
def prow_image(
component,
name, # use "image"
base = None,
base_arm64 = None,
stamp = True, # stamp by default, but allow overrides
app_name = "app",
build_arm64 = False,
**kwargs):
go_image(
name = app_name,
Expand All @@ -48,6 +51,25 @@ def prow_image(
**kwargs
)

if build_arm64 == True:
go_image(
name = "%s-arm64" % app_name,
base = base_arm64,
embed = [":go_default_library"],
goarch = "arm64",
goos = "linux",
pure = "on",
x_defs = {"k8s.io/test-infra/prow/version.Name": component},
)

container_image(
name = name,
base = ":%s-arm64" % app_name,
architecture = "arm64",
stamp = stamp,
**kwargs
)

# prow_push creates a bundle of container images, and a target to push them.
def prow_push(
name,
Expand Down Expand Up @@ -90,6 +112,12 @@ def edge_prefix(cmd):
def target(cmd):
return "//prow/cmd/%s:image" % cmd

# target_arm64 returns the arm64 image target for the command.
#
# Concretely, target("foo") returns "//prow/cmd/foo:image-arm64"
def target_arm64(cmd):
return "//prow/cmd/%s:image-arm64" % cmd

# tags returns a {image: target} map for each cmd or {name: target} kwarg.
#
# In particular it will prefix the cmd image name with {STABLE_PROW_REPO} and {EDGE_PROW_REPO}
Expand Down Expand Up @@ -119,6 +147,13 @@ def tags(cmds, targets):
cmd_targets.update({edge_prefix(p): t for (p, t) in targets.items()})
return _image_tags(cmd_targets)

# tags_arm64 returns a {image: target-arm64} map for each cmd kwarg.
def tags_arm64(cmds):
cmd_targets = {prefix(cmd): target_arm64(cmd) for cmd in cmds}
if EDGE_PROW_REPO:
cmd_targets.update({edge_prefix(cmd): target_arm64(cmd) for cmd in cmds})
return _image_tags_arm64(cmd_targets)

def object(name, cluster = CORE_CLUSTER, **kwargs):
k8s_object(
name = name,
Expand Down

0 comments on commit c150127

Please sign in to comment.