Skip to content

Commit

Permalink
Upgrade to GraalVM for JDK 23
Browse files Browse the repository at this point in the history
  • Loading branch information
olyagpl committed Oct 10, 2024
1 parent 489d8df commit 9e853a9
Show file tree
Hide file tree
Showing 30 changed files with 1,510 additions and 8 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/github-actions-spring-boot-webserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ jobs:
- name: Set up GraalVM
uses: graalvm/setup-graalvm@v1
with:
java-version: '23-ea'
java-version: '23'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Spring Boot Web Server
# working-directory: native-image/spring-boot-webserver
run: |
# Prepapre static resources
pwd
unzip native-image/spring-boot-webserver/src/main/resources/static.zip
cd /home/runner/work/workshops/workshops/native-image/spring-boot-webserver
#
# Build JAR (Debian Slim)
./build-jar.sh
#
Expand Down Expand Up @@ -59,6 +66,9 @@ jobs:
# Compare file sizes
ls -lh target/webserver*
docker images webserver
# Restore defaults
git clean -fd static/
- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ GraalVM as a Java runtime.
<a href="https://github.com/graalvm/workshops/actions/workflows/github-actions-spring-boot-webserver.yml">
<img alt="native-image-quickstart" src="https://github.com/graalvm/workshops/actions/workflows/github-actions-spring-boot-webserver.yml/badge.svg" /></a>

> Workshop is for developers looking to understand better how to build **size-optimized** Java applications using [GraalVM Native Image](https://www.graalvm.org/reference-manual/native-image/). In the workshop you will:
> Compile a Spring Boot web server, hosting GraalVM documentation pages, ahead of time into a native executable and optimize it for file size
> See how to use the [GraalVM Native Image Maven Plugin](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html)
> Create native executables and run them inside different base containers, including Paketo Buildpacks
> Shrink a container image size by taking advantage of different Native Image containerisation and linking options
> Workshop for developers looking to understand better how to build **size-optimized** Java applications using [GraalVM Native Image](https://www.graalvm.org/reference-manual/native-image/). In the workshop you will:
> - Compile a Spring Boot web server, hosting GraalVM documentation pages, ahead of time into a native executable and optimize it for file size
> - See how to use the [GraalVM Native Image Maven Plugin](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html)
> - Create native executables and run them inside different base containers, including Paketo Buildpacks
> - Shrink a container image size by taking advantage of different Native Image containerisation and linking options
> Run on an Oracle-owned tenancy (Luna Labs): [https://luna.oracle.com/lab/b644a03a-8238-4293-a586-55e5b0ec6186](https://luna.oracle.com/lab/b644a03a-8238-4293-a586-55e5b0ec6186)
> You can also run this workshop for free on Oracle Cloud Infrastructure (Luna Labs): [https://luna.oracle.com/lab/b644a03a-8238-4293-a586-55e5b0ec6186](https://luna.oracle.com/lab/b644a03a-8238-4293-a586-55e5b0ec6186)
### ![Lab Flask](./images/lab-flask.png) [Understanding Reflection with GraalVM Native Image](native-image/reflection/)
<a href="https://github.com/graalvm/workshops/actions/workflows/github-actions-native-image-reflection.yml">
Expand Down
1 change: 0 additions & 1 deletion native-image/spring-boot-webserver
Submodule spring-boot-webserver deleted from f2326b
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM container-registry.oracle.com/graalvm/jdk:23 AS build
COPY . /webserver
WORKDIR /webserver
RUN ./mvnw clean package

FROM gcr.io/distroless/java21-debian12
COPY --from=build /webserver/target/webserver-0.0.1-SNAPSHOT.jar webserver-0.0.1-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "webserver-0.0.1-SNAPSHOT.jar"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM gcr.io/distroless/base-debian12
COPY target/webserver.mostly-static /
EXPOSE 8080
ENTRYPOINT ["/webserver.mostly-static"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM gcr.io/distroless/java-base-debian12
COPY target/webserver /
EXPOSE 8080
ENTRYPOINT ["/webserver"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM gcr.io/distroless/java-base-debian12
COPY target/webserver.dynamic-optimized /
EXPOSE 8080
ENTRYPOINT ["/webserver.dynamic-optimized"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM container-registry.oracle.com/graalvm/jdk:23 AS build
COPY . /webserver
WORKDIR /webserver
RUN ./mvnw clean package
RUN ./mvnw dependency:build-classpath -Dmdep.outputFile=cp.txt
RUN jdeps --ignore-missing-deps -q --recursive --multi-release 23 --print-module-deps --class-path $(cat cp.txt) target/webserver-0.0.1-SNAPSHOT.jar
RUN jlink \
--module-path ${JAVA_HOME}/jmods \
--add-modules java.base,java.compiler,java.desktop,java.instrument,java.management,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.security.jgss,java.sql,jdk.jfr,jdk.unsupported,org.graalvm.nativeimage \
--verbose \
--strip-debug \
--compress zip-9 \
--no-header-files \
--no-man-pages \
--strip-java-debug-attributes \
--output jlink-jre

FROM gcr.io/distroless/java-base-debian12
COPY --from=build /webserver/target/webserver-0.0.1-SNAPSHOT.jar webserver-0.0.1-SNAPSHOT.jar
COPY --from=build /webserver/jlink-jre jlink-jre
EXPOSE 8080
ENTRYPOINT ["jlink-jre/bin/java", "-jar", "webserver-0.0.1-SNAPSHOT.jar"]
5 changes: 5 additions & 0 deletions native-image/spring-boot-webserver/Dockerfile.scratch.static
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
WORKDIR /tmp
COPY target/webserver.static /
EXPOSE 8080
ENTRYPOINT ["/webserver.static"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
WORKDIR /tmp
COPY target/webserver.static-upx /
EXPOSE 8080
ENTRYPOINT ["/webserver.static-upx"]
Loading

0 comments on commit 9e853a9

Please sign in to comment.