forked from bazelbuild/rules_docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.bzl
98 lines (88 loc) · 2.95 KB
/
image.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Copyright 2020 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A rule for creating a kotlin container image.
The signature of kt_jvm_image is compatible with kt_jvm_binary.
"""
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_binary", "kt_jvm_library")
load(
"//java:image.bzl",
"DEFAULT_JAVA_BASE",
"jar_app_layer",
"jar_dep_layer",
_repositories = "repositories",
)
def kt_jvm_image(
name,
base = None,
main_class = None,
srcs = [],
deps = [],
layers = [],
jvm_flags = [],
**kwargs):
"""Builds a container image overlaying the kt_jvm_binary.
Args:
name: Name of the kt_jvm_image target.
base: Base image to use for the kt_jvm_image.
main_class: The main entrypoint class in the kotlin image.
srcs: List of kotlin source files that will be used to build the binary
to be included in the kt_jvm_image.
deps: The dependencies of the kt_jvm_image target.
jvm_flags: The flags to pass to the JVM when running the kotlin image.
layers: Augments "deps" with dependencies that should be put into
their own layers.
**kwargs: See kt_jvm_binary.
"""
binary_name = name + ".binary"
# This is an inlined copy of kt_jvm_binary so that we properly collect
# the JARs relevant to the kt_jvm_library.
if srcs:
kt_jvm_library(
name = binary_name + "-lib",
srcs = srcs,
deps = deps + layers,
)
deps = deps + [binary_name + "-lib"]
kt_jvm_binary(
name = binary_name,
main_class = main_class,
deps = deps + layers,
srcs = srcs,
**kwargs
)
index = 0
base = base or DEFAULT_JAVA_BASE
for dep in layers:
this_name = "%s.%d" % (name, index)
jar_dep_layer(name = this_name, base = base, dep = dep)
base = this_name
index += 1
visibility = kwargs.get("visibility", None)
tags = kwargs.get("tags", None)
jar_app_layer(
name = name,
base = base,
binary = binary_name,
main_class = main_class,
jvm_flags = jvm_flags,
deps = deps,
jar_layers = layers,
visibility = visibility,
tags = tags,
args = kwargs.get("args"),
data = kwargs.get("data"),
testonly = kwargs.get("testonly"),
)
def repositories():
_repositories()