Skip to content

Commit

Permalink
Make jar_app_layer._classpath_as_file public (#1947)
Browse files Browse the repository at this point in the history
* Rename jar_app_layer._classpath_as_file to classpath_as_file

This is being done to make this attribute public so that callers can
specify it.

* Add classpath_as_file as argument to java_image

* Add classpath_as_file as argument to groovy_image

* Add classpath_as_file as argument to kt_jvm_image

* Add classpath_as_file as argument to scala_image

* Adds test for scala_image with classpath_as_file=True

* Adds test for java_image with classpath_as_file = True

* Adds test for groovy_image with classpath_as_file = True

* Adds test for kt_jvm_image with classpath_as_file = True

* Ignore new image tests under macos

* Trigger build

* Trigger build
  • Loading branch information
jakemcc authored Nov 10, 2021
1 parent 4887961 commit 8f6a2aa
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ tasks:
- -//tests/container/go:go_image_test
- -//tests/container/go:go_static_image_test
- -//tests/container/groovy:groovy_image_test
- -//tests/container/groovy:groovy_classpath_as_file_image_test
- -//tests/container/java:java_image_test
- -//tests/container/java:java_classpath_as_file_image_test
- -//tests/container/java:java_partial_entrypoint_image_test
- -//tests/container/java:java_runfiles_as_lib_image_test
- -//tests/container/java:java_runfiles_image_test
- -//tests/container/java:simple_java_entrypoint_image_test
- -//tests/container/kotlin:kotlin_image_test
- -//tests/container/kotlin:kotlin_classpath_as_file_image_test
- -//tests/container/nodejs:nodejs_image_custom_binary_test
- -//tests/container/nodejs:nodejs_image_custom_binary_with_args_test
- -//tests/container/nodejs:nodejs_image_empty_list_args_test
Expand All @@ -86,6 +89,7 @@ tasks:
- -//tests/container/python3:py3_image_test
- -//tests/container/rust:rust_image_test
- -//tests/container/scala:scala_image_test
- -//tests/container/scala:scala_classpath_as_file_image_test
- -//tests/contrib:derivative_with_volume_repro_test
- -//tests/contrib:random_file_img_non_repro_test
- -//tests/contrib:rbe-test-xenial_repro_test
Expand Down
2 changes: 2 additions & 0 deletions groovy/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def groovy_image(
deps = [],
layers = [],
jvm_flags = [],
classpath_as_file = None,
**kwargs):
"""Builds a container image overlaying the groovy_binary.
Expand Down Expand Up @@ -93,6 +94,7 @@ def groovy_image(
args = kwargs.get("args"),
data = kwargs.get("data"),
testonly = kwargs.get("testonly"),
classpath_as_file = classpath_as_file,
)

def repositories():
Expand Down
6 changes: 4 additions & 2 deletions java/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _jar_app_layer_impl(ctx):
"/usr/bin/java",
"-cp",
# Support optionally passing the classpath as a file.
"@" + classpath_path if ctx.attr._classpath_as_file else classpath,
"@" + classpath_path if ctx.attr.classpath_as_file else classpath,
] + jvm_flags + ([ctx.attr.main_class] + args if ctx.attr.main_class != "" else [])

file_map = {
Expand Down Expand Up @@ -245,7 +245,7 @@ jar_app_layer = rule(
"workdir": attr.string(default = ""),

# Whether the classpath should be passed as a file.
"_classpath_as_file": attr.bool(default = False),
"classpath_as_file": attr.bool(default = False),
"_jdk": attr.label(
default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
providers = [java_common.JavaRuntimeInfo],
Expand All @@ -265,6 +265,7 @@ def java_image(
runtime_deps = [],
layers = [],
jvm_flags = [],
classpath_as_file = None,
**kwargs):
"""Builds a container image overlaying the java_binary.
Expand Down Expand Up @@ -327,6 +328,7 @@ def java_image(
args = kwargs.get("args"),
data = kwargs.get("data"),
testonly = kwargs.get("testonly"),
classpath_as_file = classpath_as_file,
)

def _war_dep_layer_impl(ctx):
Expand Down
2 changes: 2 additions & 0 deletions kotlin/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def kt_jvm_image(
deps = [],
layers = [],
jvm_flags = [],
classpath_as_file = None,
**kwargs):
"""Builds a container image overlaying the kt_jvm_binary.
Expand Down Expand Up @@ -92,6 +93,7 @@ def kt_jvm_image(
args = kwargs.get("args"),
data = kwargs.get("data"),
testonly = kwargs.get("testonly"),
classpath_as_file = classpath_as_file,
)

def repositories():
Expand Down
2 changes: 2 additions & 0 deletions scala/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def scala_image(
runtime_deps = [],
layers = [],
jvm_flags = [],
classpath_as_file = None,
**kwargs):
"""Builds a container image overlaying the scala_binary.
Expand Down Expand Up @@ -85,6 +86,7 @@ def scala_image(
args = kwargs.get("args"),
data = kwargs.get("data"),
testonly = kwargs.get("testonly"),
classpath_as_file = classpath_as_file,
)

def repositories():
Expand Down
21 changes: 21 additions & 0 deletions tests/container/groovy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,29 @@ groovy_image(
main_class = "examples.images.Binary",
)

groovy_image(
name = "groovy_classpath_as_file_image",
srcs = ["//testdata:Binary.groovy"],
args = [
"arg0",
"arg1",
"$(location :BUILD)",
],
classpath_as_file = True,
data = [":BUILD"],
jvm_flags = ["-Dbuild.location=$(location :BUILD)"],
layers = [":groovy_image_library"],
main_class = "examples.images.Binary",
)

container_test(
name = "groovy_image_test",
configs = ["//tests/container/groovy/configs:groovy_image.yaml"],
image = ":groovy_image",
)

container_test(
name = "groovy_classpath_as_file_image_test",
configs = ["//tests/container/groovy/configs:groovy_classpath_as_file_image.yaml"],
image = ":groovy_classpath_as_file_image",
)
13 changes: 13 additions & 0 deletions tests/container/groovy/configs/groovy_classpath_as_file_image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
schemaVersion: 2.0.0

metadataTest:
entrypoint: [
'/usr/bin/java',
'-cp',
'@/app/io_bazel_rules_docker/tests/container/groovy/groovy_classpath_as_file_image.classpath',
'-Dbuild.location=tests/container/groovy/BUILD',
'examples.images.Binary',
'arg0',
'arg1',
'tests/container/groovy/BUILD',
]
23 changes: 23 additions & 0 deletions tests/container/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ java_image(
main_class = "examples.images.Binary",
)

java_image(
name = "java_classpath_as_file_image",
srcs = ["//testdata:Binary.java"],
args = [
"arg0",
"arg1",
"$(location :BUILD)",
],
classpath_as_file = True,
data = [":BUILD"],
jvm_flags = [
"-Dbuild.location=$(location :BUILD)",
],
layers = [":java_image_library"],
main_class = "examples.images.Binary",
)

java_image(
name = "java_runfiles_image",
srcs = ["//testdata:Runfiles.java"],
Expand Down Expand Up @@ -91,6 +108,12 @@ container_test(
image = ":java_image",
)

container_test(
name = "java_classpath_as_file_image_test",
configs = ["//tests/container/java/configs:java_classpath_as_file_image.yaml"],
image = ":java_classpath_as_file_image",
)

container_test(
name = "java_runfiles_image_test",
configs = ["//tests/container/java/configs:java_runfiles_image.yaml"],
Expand Down
15 changes: 15 additions & 0 deletions tests/container/java/configs/java_classpath_as_file_image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
schemaVersion: 2.0.0

metadataTest:
env:
- key: JAVA_RUNFILES
value: "/app"
entrypoint: [
'/usr/bin/java',
'-cp',
'@/app/io_bazel_rules_docker/tests/container/java/java_classpath_as_file_image.classpath',
'-Dbuild.location=tests/container/java/BUILD',
'examples.images.Binary',
'arg0',
'arg1',
'tests/container/java/BUILD']
24 changes: 24 additions & 0 deletions tests/container/kotlin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,32 @@ kt_jvm_image(
deps = [],
)

kt_jvm_image(
name = "kt_jvm_classpath_as_file_image",
srcs = [
"//testdata:Binary.kt",
"//testdata:Library.kt",
],
args = [
"arg0",
"arg1",
"$(location :BUILD)",
],
classpath_as_file = True,
data = [":BUILD"],
jvm_flags = ["-Dbuild.location=$(location :BUILD)"],
main_class = "examples.images.Binary",
deps = [],
)

container_test(
name = "kotlin_image_test",
configs = ["//tests/container/kotlin/configs:kt_jvm_image.yaml"],
image = ":kt_jvm_image",
)

container_test(
name = "kotlin_classpath_as_file_image_test",
configs = ["//tests/container/kotlin/configs:kt_jvm_classpath_as_file_image.yaml"],
image = ":kt_jvm_classpath_as_file_image",
)
13 changes: 13 additions & 0 deletions tests/container/kotlin/configs/kt_jvm_classpath_as_file_image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
schemaVersion: 2.0.0

metadataTest:
entrypoint: [
'/usr/bin/java',
'-cp',
'@/app/io_bazel_rules_docker/tests/container/kotlin/kt_jvm_classpath_as_file_image.classpath',
'-Dbuild.location=tests/container/kotlin/BUILD',
'examples.images.Binary',
'arg0',
'arg1',
'tests/container/kotlin/BUILD',
]
21 changes: 21 additions & 0 deletions tests/container/scala/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,24 @@ container_test(
configs = ["//tests/container/scala/configs:scala_image.yaml"],
image = ":scala_image",
)

scala_image(
name = "scala_classpath_as_file_image",
srcs = ["//testdata:Binary.scala"],
args = [
"arg0",
"arg1",
"$(location :BUILD)",
],
classpath_as_file = True,
data = [":BUILD"],
jvm_flags = ["-Dbuild.location=$(location :BUILD)"],
layers = [":scala_image_library"],
main_class = "examples.images.Binary",
)

container_test(
name = "scala_classpath_as_file_image_test",
configs = ["//tests/container/scala/configs:scala_classpath_as_file_image.yaml"],
image = ":scala_classpath_as_file_image",
)
13 changes: 13 additions & 0 deletions tests/container/scala/configs/scala_classpath_as_file_image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
schemaVersion: 2.0.0

metadataTest:
entrypoint: [
'/usr/bin/java',
'-cp',
'@/app/io_bazel_rules_docker/tests/container/scala/scala_classpath_as_file_image.classpath',
'-Dbuild.location=tests/container/scala/BUILD',
'examples.images.Binary',
'arg0',
'arg1',
'tests/container/scala/BUILD',
]

0 comments on commit 8f6a2aa

Please sign in to comment.