Skip to content

Commit

Permalink
Feature/graalvm sample (#2278)
Browse files Browse the repository at this point in the history
* WIP - Spring Boot Admin Server GraalVM sample

* Spring Boot Admin Server GraalVM sample

* Spring Boot Admin Server GraalVM sample

* Documented the Spring Boot Admin Server GraalVM sample (might be addressing #2271 and #2163)

* cleanup

* Added a hint to use a v17 BaseJDK GraalVM to build the sample within the docs.

* Extended docs regarding native build with separate profile.

* Added RuntimeHints

* WIP: RuntimeHints

* WIP: RuntimeHints

* Removed awt from implementation of converting hex to rgb since graal cannot cope with it right now

* Extended RuntimeHints

* Extended RuntimeHints

* Extended documentation

* OCI image building + documentation

* cleanup dependencies

* Corrected GraalVM version

* Added info endpoint configuration

* Cleanup

* Added build-info and general cleanup

* Cleanup

* Fixed checkstyle issues

* Fixed documentation on image builder for common x86 architectures

---------

Co-authored-by: Stephan Köninger <stephan.koeninger@codecentric.de>
  • Loading branch information
ulischulte and SteKoe committed Mar 31, 2023
1 parent 8b5a942 commit c71763a
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Spring Boot Admin GraalVM sample application

This is a sample project running a Spring Boot Admin server which works with GraalVM and Native Image Builder.

In order to show basic functionalities, the server itself is registered as a client.

## Build project

Make sure to use a GraalVM with a v17-BaseJDK to build the project (e.g. 22.3.1.r17-grl).

```
$ mvn -Pnative native:compile
```
The native application will now be build in the target folder.
```
$ cd target
$ ./spring-boot-admin-sample-servlet-graalvm
```
You should now be able to access Spring Boot Admin locally under http://localhost:8080/

## Build an OCI image that can be run with Docker

```
$ mvn spring-boot:build-image -Pnative -Dspring-boot.build-image.imageName=spring-boot-admin-sample-servlet-graalvm:latest
```
Depending on your OS, you might want to change the builder in your `pom.xml`.

Right now, `<builder>dashaun/native-builder:focal-arm64</builder>` is a good choice for ARM64.

In most other cases `<builder>paketobuildpacks/builder:tiny</builder>` should do the job.

## Running the example

```
$ docker run --rm -p 8080:8080 docker.io/library/spring-boot-admin-sample-servlet-graalvm:latest
```
You should now be able to access Spring Boot Admin locally under http://localhost:8080/

## Current limitations of Spring Boot's native image build feature

Keep in mind that currently not all Spring modules have built-in support. Therefore, you might need to tell the AOT compiler about the usage of reflection, dynamic proxies etc. There are several ways to deal with these concerns. A good starting point for specifying additional native configuration can be found in the official [Spring documentation](https://docs.spring.io/spring-framework/docs/6.0.0/reference/html/core.html#aot-hints).
Some features like gc and memory metrics are not supported by GraalVM yet. So some views (e.g. gc-details) are currently not working.
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2014-2019 the original author or authors.
~
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-admin-sample-servlet-graalvm</artifactId>
<name>Spring Boot Admin Sample Servlet GraalVM</name>
<description>Spring Boot Admin Sample Servlet</description>
<parent>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-samples</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
<native-build-tools-plugin.version>0.9.19</native-build-tools-plugin.version>
<maven.javadoc.skip>true</maven.javadoc.skip>
</properties>

<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.luben</groupId>
<artifactId>zstd-jni</artifactId>
<version>1.5.4-2</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native-build-tools-plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<image>
<!--<builder> paketobuildpacks/builder:tiny</builder> -->
<builder>dashaun/native-builder:focal-arm64</builder>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
</env>
</image>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<skipNativeTests>true</skipNativeTests>
<buildArgs>
<arg>-H:+IncludeAllLocales</arg>
<arg>-H:-CheckToolchain</arg>
<arg>-H:+ReportExceptionStackTraces</arg>
</buildArgs>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<metadataRepository>
<enabled>true</enabled>
</metadataRepository>
<requiredVersion>22.3.1</requiredVersion>
</configuration>
<executions>
<execution>
<id>add-reachability-metadata</id>
<goals>
<goal>add-reachability-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>nativeTest</id>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-test-aot</id>
<goals>
<goal>process-test-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<metadataRepository>
<enabled>true</enabled>
</metadataRepository>
<requiredVersion>22.3</requiredVersion>
</configuration>
<executions>
<execution>
<id>native-test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>

0 comments on commit c71763a

Please sign in to comment.