Skip to content

Commit 30fd0d0

Browse files
committed
#21: Since the official GraalVM Docker image was removed from DockerHub - and is published to GitHub Packages further on, we need to do the full switch to spring-native 0.8.3, which supports GraalVM 20.3.x and the release versions of Spring 2.4.x. Removed -H:+TraceClassInitialization as of oracle/graal@8c210f7
1 parent 680dfc7 commit 30fd0d0

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

.github/workflows/native-image-compile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
echo 'Install GraalVM with SDKMAN'
2323
curl -s "https://get.sdkman.io" | bash
2424
source "$HOME/.sdkman/bin/sdkman-init.sh"
25-
sdk install java 20.2.0.r11-grl
25+
sdk install java 20.3.1.2.r11-grl
2626
2727
echo 'Check if GraalVM was installed successfully'
2828
java -version

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Simple Dockerfile adding Maven and GraalVM Native Image compiler to the standard
2-
# https://hub.docker.com/r/oracle/graalvm-ce image
3-
FROM oracle/graalvm-ce:20.2.0-java11
2+
# https://github.com/orgs/graalvm/packages/container/package/graalvm-ce image
3+
FROM ghcr.io/graalvm/graalvm-ce:ol7-java11-20.3.1.2
44

55
ADD . /build
66
WORKDIR /build
@@ -20,7 +20,7 @@ RUN source "$HOME/.sdkman/bin/sdkman-init.sh" && mvn --version
2020

2121
RUN native-image --version
2222

23-
RUN source "$HOME/.sdkman/bin/sdkman-init.sh" && ./compile.sh
23+
RUN source "$HOME/.sdkman/bin/sdkman-init.sh" && mvn -B clean package -P native --no-transfer-progress
2424

2525

2626
# We use a Docker multi-stage build here in order that we only take the compiled native Spring Boot App from the first build container

README.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![renovateenabled](https://img.shields.io/badge/renovate-enabled-yellow)](https://renovatebot.com)
55
[![versionspringboot](https://img.shields.io/badge/dynamic/xml?color=brightgreen&url=https://raw.githubusercontent.com/jonashackt/spring-boot-graalvm/master/pom.xml&query=%2F%2A%5Blocal-name%28%29%3D%27project%27%5D%2F%2A%5Blocal-name%28%29%3D%27parent%27%5D%2F%2A%5Blocal-name%28%29%3D%27version%27%5D&label=springboot)](https://github.com/spring-projects/spring-boot)
66
[![versionspring-graalvm-native](https://img.shields.io/badge/dynamic/xml?color=brightgreen&url=https://raw.githubusercontent.com/jonashackt/spring-boot-graalvm/master/pom.xml&query=%2F%2A%5Blocal-name%28%29%3D%27project%27%5D%2F%2A%5Blocal-name%28%29%3D%27properties%27%5D%2F%2A%5Blocal-name%28%29%3D%27spring-graalvm-native.version%27%5D&label=spring-graalvm-native)](https://github.com/spring-projects-experimental/spring-graalvm-native)
7-
[![versionjava](https://img.shields.io/badge/graalvm_ce-20.2.0_JDK11-orange.svg?logo=java)](https://www.graalvm.org/)
7+
[![versionjava](https://img.shields.io/badge/graalvm_ce-20.3.1.2_JDK11-orange.svg?logo=java)](https://www.graalvm.org/)
88
[![Deployed on Heroku](https://img.shields.io/badge/heroku-deployed-blueviolet.svg?logo=heroku&)](https://spring-boot-graal.herokuapp.com/hello)
99
[![Pushed to Docker Hub](https://img.shields.io/badge/docker_hub-released-blue.svg?logo=docker)](https://hub.docker.com/r/jonashackt/spring-boot-graalvm)
1010

@@ -57,6 +57,7 @@ This project is used as example in some articles:
5757
* [Work around the Heroku 512MB RAM cap: Building our Dockerimage with TravisCI](#work-around-the-heroku-512mb-ram-cap-building-our-dockerimage-with-travisci)
5858
* [Tackling 'Error: Image build request failed with exit status 137' with the -J-Xmx parameter](#tackling-error-image-build-request-failed-with-exit-status-137-with-the--j-xmx-parameter)
5959
* [Pushing and Releasing our Dockerized Native Spring Boot App on Heroku Container Infrastructure](#pushing-and-releasing-our-dockerized-native-spring-boot-app-on-heroku-container-infrastructure)
60+
* [Pushing and Releasing our Dockerized Native Spring Boot App on Heroku Container Infrastructure using GitHub Actions](#pushing-and-releasing-our-dockerized-native-spring-boot-app-on-heroku-container-infrastructure-using-github-actions)
6061
* [Autorelease on Docker Hub with TravisCI](#autorelease-on-docker-hub-with-travisci)
6162
* [Links](#links)
6263

@@ -1003,14 +1004,14 @@ This one does exactly what we did with TravisCI - building the native image usin
10031004

10041005
# Use Docker to compile a Spring Boot App with GraalVM
10051006

1006-
There's an [official Docker image from Oracle](https://hub.docker.com/r/oracle/graalvm-ce/tags), but this one sadyl lacks both Maven with it's `mvn` command and the `native-image` plugin also not installed.
1007+
There's an [official Docker image from Oracle](https://github.com/orgs/graalvm/packages/container/package/graalvm-ce), but this one sadyl lacks both Maven with it's `mvn` command and the `native-image` plugin also not installed.
10071008

10081009
But we can help ourselves - we just craft a simple [Dockerfile](Dockerfile) for us. We're already used to leverage SDKMAN to install Maven. Therefore we need to install `unzip` and `zip` first, since SDKMAN needs both to work properly:
10091010

10101011
```dockerfile
10111012
# Simple Dockerfile adding Maven and GraalVM Native Image compiler to the standard
1012-
# https://hub.docker.com/r/oracle/graalvm-ce image
1013-
FROM oracle/graalvm-ce:20.2.0-java11
1013+
# https://github.com/orgs/graalvm/packages/container/package/graalvm-ce image
1014+
FROM ghcr.io/graalvm/graalvm-ce:ol7-java11-20.3.1.2
10141015
10151016
# For SDKMAN to work we need unzip & zip
10161017
RUN yum install -y unzip zip
@@ -1036,7 +1037,7 @@ In order to enable the `mvn` command for a user of our Docker image, we craft a
10361037
Now let's build our Image with:
10371038

10381039
```shell script
1039-
docker build . --tag=graalvm-ce:20.2.0-java11-mvn-native-image
1040+
docker build . --tag=graalvm-ce:20.3.0-java11-mvn-native-image
10401041
```
10411042

10421043
Now we should be able to launch our GraalVM Native Image compilation inside official Oracle GraalVM image with:
@@ -1046,7 +1047,7 @@ docker run -it --rm \
10461047
--volume $(pwd):/build \
10471048
--workdir /build \
10481049
--volume "$HOME"/.m2:/root/.m2 \
1049-
graalvm-ce:20.2.0-java11-mvn-native-image ./compile.sh
1050+
graalvm-ce:20.3.0-java11-mvn-native-image ./compile.sh
10501051
```
10511052

10521053
When I first thought about a Docker usage, I wanted to pack this build into a `Dockerfile` also - but then I realized, that there's [no easy way of using Docker volumes at Docker build time](https://stackoverflow.com/questions/51086724/docker-build-using-volumes-at-build-time). But I really wanted to mount a Docker volume to my local Maven repository like `--volume "$HOME"/.m2:/root/.m2` to prevent the download of all the Spring Maven dependencies over and over again every time we start our Docker container.
@@ -1083,8 +1084,8 @@ Therefore let's refactor our Dockerfile:
10831084

10841085
```dockerfile
10851086
# Simple Dockerfile adding Maven and GraalVM Native Image compiler to the standard
1086-
# https://hub.docker.com/r/oracle/graalvm-ce image
1087-
FROM oracle/graalvm-ce:20.2.0-java11
1087+
# https://github.com/orgs/graalvm/packages/container/package/graalvm-ce image
1088+
FROM ghcr.io/graalvm/graalvm-ce:ol7-java11-20.3.1.2
10881089
10891090
ADD . /build
10901091
WORKDIR /build
@@ -1119,7 +1120,7 @@ COPY --from=0 "/build/target/native-image/spring-boot-graal" spring-boot-graal
11191120
CMD [ "sh", "-c", "./spring-boot-graal" ]
11201121
```
11211122

1122-
Additionally the second container isn't based on the `oracle/graalvm-ce` image containing a GraalVM installation, Maven and the `native-image` command - but instead uses [the base image of this image](https://github.com/oracle/docker-images/blob/master/GraalVM/CE/Dockerfile.java11), which is `oraclelinux:7-slim`.
1123+
Additionally the second container isn't based on the `ghcr.io/graalvm/graalvm-ce` image containing a GraalVM installation, Maven and the `native-image` command - but instead uses [the base image of this image](https://github.com/oracle/docker-images/blob/master/GraalVM/CE/Dockerfile.java11), which is `oraclelinux:7-slim`.
11231124

11241125
With that we reduce the resulting Docker image size from around `1.48GB` to only `186MB`!
11251126

@@ -1154,7 +1155,7 @@ user 16m32.096s
11541155
sys 1m34.441s
11551156
Removing intermediate container 151e1413ec2f
11561157
---> be671d4f237f
1157-
Step 10/13 : FROM oracle/graalvm-ce:20.2.0-java11
1158+
Step 10/13 : FROM docker pull ghcr.io/graalvm/graalvm-ce:ol7-java11-20.3.1.2
11581159
---> 364d0bb387bd
11591160
Step 11/13 : MAINTAINER Jonas Hecht
11601161
---> Using cache
@@ -1610,7 +1611,7 @@ This pulls the latest `jonashackt/spring-boot-graalvm` image and runs our app lo
16101611

16111612
# Links
16121613

1613-
### Spring / Pivotal
1614+
### Spring
16141615

16151616
Current docs: https://repo.spring.io/milestone/org/springframework/experimental/spring-graalvm-native-docs/0.7.0/spring-graalvm-native-docs-0.7.0.zip!/reference/index.html
16161617

@@ -1626,6 +1627,14 @@ https://spring.io/blog/2020/04/16/spring-tips-the-graalvm-native-image-builder-f
16261627

16271628
https://spring.io/blog/2020/06/10/the-path-towards-spring-boot-native-applications
16281629

1630+
##### 0.8.3
1631+
1632+
Spring Boot 2.4.0 Release + Oracle GraalVM 20.3.x compatibility: https://spring.io/blog/2020/11/23/spring-native-for-graalvm-0-8-3-available-now
1633+
1634+
No `-H:+TraceClassInitialization` as simple boolean anymore: https://github.com/quarkusio/quarkus/issues/12434 & https://github.com/oracle/graal/commit/8c210f7fdbba5045bfbe14b6870f98ebbff6eed7
1635+
1636+
With GraalVM 20.3.x the official Docker image moved from Docker Hub to GitHub Packages: https://github.com/orgs/graalvm/packages/container/package/graalvm-ce
1637+
16291638

16301639
### Stackoverflow
16311640

@@ -1640,7 +1649,7 @@ https://stackoverflow.com/questions/61302412/how-to-configure-the-port-of-a-spri
16401649

16411650
https://blog.softwaremill.com/graalvm-installation-and-setup-on-macos-294dd1d23ca2
16421651

1643-
https://hub.docker.com/r/oracle/graalvm-ce/
1652+
https://github.com/orgs/graalvm/packages/container/package/graalvm-ce
16441653

16451654
https://www.graalvm.org/docs/reference-manual/native-image/
16461655

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.4.0-RC1</version>
8+
<version>2.4.0</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>io.jonashackt</groupId>
@@ -17,8 +17,8 @@
1717
<properties>
1818
<java.version>8</java.version>
1919
<start-class>io.jonashackt.springbootgraal.SpringBootHelloApplication</start-class>
20-
<spring-graalvm-native.version>0.8.2</spring-graalvm-native.version>
21-
<native-image-maven-plugin.version>20.2.0</native-image-maven-plugin.version>
20+
<spring-graalvm-native.version>0.8.3</spring-graalvm-native.version>
21+
<native-image-maven-plugin.version>20.3.0</native-image-maven-plugin.version>
2222
</properties>
2323

2424
<dependencies>
@@ -90,7 +90,7 @@
9090
<artifactId>native-image-maven-plugin</artifactId>
9191
<version>${native-image-maven-plugin.version}</version>
9292
<configuration>
93-
<buildArgs>-J-Xmx4G -H:+TraceClassInitialization -H:+ReportExceptionStackTraces -Dspring.native.remove-unused-autoconfig=true -Dspring.native.remove-yaml-support=true</buildArgs>
93+
<buildArgs>-J-Xmx4G -H:+ReportExceptionStackTraces -Dspring.native.remove-unused-autoconfig=true -Dspring.native.remove-yaml-support=true</buildArgs>
9494
<imageName>${project.artifactId}</imageName>
9595
</configuration>
9696
<executions>

src/main/java/io/jonashackt/springbootgraal/SpringBootHelloApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55

6-
@SpringBootApplication(proxyBeanMethods = false)
6+
@SpringBootApplication
77
public class SpringBootHelloApplication {
88

99
public static void main(String[] args) {

0 commit comments

Comments
 (0)