Repository navigation
Expand file tree
/
Copy pathDockerfile.aot
More file actions
58 lines (47 loc) · 2.6 KB
/
Copy pathDockerfile.aot
File metadata and controls
58 lines (47 loc) · 2.6 KB
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
# syntax=docker/dockerfile:1
# Builds the GraalVM native-image variant of src/java-api on linux/arm64. Same
# project and same source as Dockerfile; the only difference is that this one
# compiles it ahead of time instead of running it on a JVM, so there is no JRE to
# carry. That is why the two live in one directory: nothing in src/main changes
# between them, only the packaging does.
#
# The -ol9 tag matters for two independent reasons. A GraalVM native binary links
# glibc dynamically, so it has to be built against 2.34 -- what Oracle Linux 9,
# and therefore Amazon Linux 2023 and the Web Function environment, ship. And
# Spring Boot 4 refuses to start in a native image built below Java 25, so the
# JDK here has to match the one in pom.xml. (Go and .NET AOT sidestep the first
# by linking statically; GraalVM does not.)
FROM ghcr.io/graalvm/native-image-community:25-ol9 AS build
# Maven from its own image: GraalVM's image has the JDK, native-image and the C
# toolchain native-image needs, but no build tool. Maven is portable shell plus
# jars, so copying it over is enough.
COPY --from=maven:3.9-eclipse-temurin-25 /usr/share/maven /opt/maven
ENV PATH=/opt/maven/bin:$PATH
# curl and zip are what smoke.sh and the packaging need.
RUN microdnf install -y zip curl \
&& microdnf clean all
WORKDIR /work
# Resolve the dependencies before the source lands, so editing a .java file does
# not re-download the world.
COPY src/java-api/pom.xml ./src/java-api/pom.xml
RUN mvn -B --no-transfer-progress -f src/java-api/pom.xml dependency:go-offline
COPY src/java-api/src ./src/java-api/src
# The smoke test the build runs before it zips the bundle.
COPY src/java-api/smoke.sh ./src/java-api/
# -Pnative turns on Spring's AOT processing; native:compile then builds the
# image. The goal is invoked rather than a `package`-bound execution so that the
# JVM build, which shares this pom, never tries to run native-image.
RUN mvn -B --no-transfer-progress -f src/java-api/pom.xml -Pnative -DskipTests native:compile
# No launcher script in this variant: the native binary is directly executable,
# so it is the `server` the shim execs.
RUN mkdir -p /var/task \
&& cp src/java-api/target/server /var/task/server \
&& chmod +x /var/task/server
# The shared execve shim. It hardcodes /var/task/server, so it lands in the zip
# root next to the binary.
COPY src/node-wrapper/index.js /var/task/index.js
RUN /work/src/java-api/smoke.sh /var/task java-aot
RUN cd /var/task && zip -q9r /java-aot-api.zip .
# The zip is the only artifact; --output type=local copies it straight out.
FROM scratch AS export
COPY --from=build /java-aot-api.zip /