-
Notifications
You must be signed in to change notification settings - Fork 2
/
BUILD.pants
53 lines (48 loc) · 2.46 KB
/
BUILD.pants
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
# This target invokes Bazel to produce a jar file. The example is contrived since Pants has JVM support,
# but the main focal point here is demonstrating Pants invoking a third party build tool and then
# consuming that tool's output (and not the particular details of this example).
#
# Please note that the `{chroot}` symbol is replaced with the path to a temporary directory created
# during execution to materialize Pants-supplied inputs.
#
# Moreover, the `{chroot}` directory is also used by Pants for capturing outputs from this process. (Thus,
# the jar file is copied to the `{chroot}` directory to make it visible to Pants.)
shell_command(
name="bazel-jvm-binary",
command="bazel build --java_runtime_version=remotejdk_11 :ProjectRunner && cp bazel-bin/ProjectRunner.jar {chroot} && ls {chroot}",
tools=["bazel", "gcc", "cp", "ls"],
extra_env_vars=["HOME", "PATH"],
workdir="bazel-jvm",
output_files=["ProjectRunner.jar"],
# This field sets what environment to execute the command in. The special value
# `__local_workspace__` selects whatever configured `experimental_workspace_environment`
# matches the current platform.
environment="__local_workspace__",
# The `path_env_modify` field allows you to disable modification of the PATH environment
# variable by Pants. Since Bazel incorporates the exact PATH value into its cache
# keys, this allows Bazel to actually use its cache (versus having to rebuild everything each
# time since the PATH will differ).
path_env_modify="off",
# Configure a longer timeout to give Bazel a chance to complete when necessary.
timeout=600,
)
# Build a Docker image which embeds the jar produced by Bazel via the //:bazel-jvm-binary target.
# Note: The jar file is visible to this target because it is listed as a dependency.
docker_image(
name="project_image",
instructions=[
"FROM openjdk:24-jdk-slim-bullseye",
"WORKDIR /app",
"COPY ProjectRunner.jar .",
'ENTRYPOINT ["java", "-cp", "ProjectRunner.jar", "com.example.ProjectRunner"]',
],
dependencies=[
":bazel-jvm-binary",
],
)
# This target configures in-workspace execution support. A few points of note:
# 1. This target accepts all of the same fields as any other environment target. Thus, you may customize various Pants options for just this environment.
# 2. The target address of this target must be configured in `environments-preview.names` section of `pants.toml` to be usable.
experimental_workspace_environment(
name="workspace",
)