Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Forward architecture from language rules to layers #2150

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions go/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ STATIC_DEFAULT_BASE = select({
"//conditions:default": "@go_image_static//image",
})

def go_image(name, base = None, deps = [], layers = [], env = {}, binary = None, **kwargs):
def go_image(name, base = None, deps = [], layers = [], env = {}, binary = None, architecture = None, **kwargs):
"""Constructs a container image wrapping a go_binary target.

Args:
Expand All @@ -99,6 +99,7 @@ def go_image(name, base = None, deps = [], layers = [], env = {}, binary = None,
layers: Augments "deps" with dependencies that should be put into their own layers.
env: Environment variables for the go_image.
binary: An alternative binary target to use instead of generating one.
architecture: The target architecture.
**kwargs: See go_binary.
"""
if layers:
Expand All @@ -115,8 +116,8 @@ def go_image(name, base = None, deps = [], layers = [], env = {}, binary = None,

tags = kwargs.get("tags", None)
for index, dep in enumerate(layers):
base = app_layer(name = "%s.%d" % (name, index), base = base, dep = dep, tags = tags)
base = app_layer(name = "%s.%d-symlinks" % (name, index), base = base, dep = dep, binary = binary, tags = tags)
base = app_layer(name = "%s.%d" % (name, index), base = base, dep = dep, tags = tags, architecture = architecture)
base = app_layer(name = "%s.%d-symlinks" % (name, index), base = base, dep = dep, binary = binary, tags = tags, architecture = architecture)

visibility = kwargs.get("visibility", None)
restricted_to = kwargs.get("restricted_to", None)
Expand All @@ -133,4 +134,5 @@ def go_image(name, base = None, deps = [], layers = [], env = {}, binary = None,
testonly = kwargs.get("testonly"),
restricted_to = restricted_to,
compatible_with = compatible_with,
architecture = architecture,
)
5 changes: 4 additions & 1 deletion java/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def java_image(
env = {},
jvm_flags = [],
classpath_as_file = None,
architecture = None,
**kwargs):
"""Builds a container image overlaying the java_binary.

Expand All @@ -295,6 +296,7 @@ def java_image(
construction of the container entrypoint. Omitting main_class
allows the user to specify additional arguments to the JVM at
runtime.
architecture: The architecture of the target.
**kwargs: See java_binary.
"""
binary_name = name + ".binary"
Expand All @@ -320,7 +322,7 @@ def java_image(
base = base or DEFAULT_JAVA_BASE
for index, dep in enumerate(layers):
this_name = "%s.%d" % (name, index)
jar_dep_layer(name = this_name, base = base, dep = dep, tags = tags)
jar_dep_layer(name = this_name, base = base, dep = dep, tags = tags, architecture = architecture)
base = this_name

visibility = kwargs.get("visibility", None)
Expand All @@ -340,6 +342,7 @@ def java_image(
data = kwargs.get("data"),
testonly = kwargs.get("testonly"),
classpath_as_file = classpath_as_file,
architecture = architecture,
)

def _war_dep_layer_impl(ctx):
Expand Down
8 changes: 5 additions & 3 deletions python3/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ DEFAULT_BASE = select({
"//conditions:default": "@py3_image_base//image",
})

def py3_image(name, base = None, deps = [], layers = [], env = {}, **kwargs):
def py3_image(name, base = None, deps = [], layers = [], env = {}, architecture = None, **kwargs):
"""Constructs a container image wrapping a py_binary target.

Args:
Expand All @@ -83,6 +83,7 @@ def py3_image(name, base = None, deps = [], layers = [], env = {}, **kwargs):
layers: Augments "deps" with dependencies that should be put into
their own layers.
env: Environment variables for the py_image.
architecture: The target architecture.
**kwargs: See py_binary.
"""
binary_name = name + ".binary"
Expand All @@ -106,13 +107,14 @@ def py3_image(name, base = None, deps = [], layers = [], env = {}, **kwargs):
base = base or DEFAULT_BASE
tags = kwargs.get("tags", None)
for index, dep in enumerate(layers):
base = app_layer(name = "%s.%d" % (name, index), base = base, dep = dep, tags = tags)
base = app_layer(name = "%s.%d-symlinks" % (name, index), base = base, dep = dep, binary = binary_name, tags = tags)
base = app_layer(name = "%s.%d" % (name, index), base = base, dep = dep, tags = tags, architecture = architecture)
base = app_layer(name = "%s.%d-symlinks" % (name, index), base = base, dep = dep, binary = binary_name, tags = tags, architecture = architecture)

visibility = kwargs.get("visibility", None)
app_layer(
name = name,
base = base,
architecture = architecture,
entrypoint = ["/usr/bin/python"],
env = env,
binary = binary_name,
Expand Down