Skip to content

Commit 59cd3d4

Browse files
committed
Update Graal to 20.2 and update scripts and native-image args
1 parent c916cc7 commit 59cd3d4

File tree

7 files changed

+34
-55
lines changed

7 files changed

+34
-55
lines changed

Dockerfile

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM oracle/graalvm-ce:19.3.0-java11 as assembler
1+
FROM oracle/graalvm-ce:20.2.0-java11 as assembler
22
LABEL maintainer="Herdy Handoko <[email protected]>"
33
LABEL description="http4s GraalVM assembler"
44

@@ -14,29 +14,25 @@ RUN (SBT_VERSION=$(cat project/build.properties | cut -d '=' -f 2 | tr -
1414
COPY project/*.scala project/
1515
COPY src/ src/
1616
COPY build.sbt VERSION.txt ./
17-
RUN ./sbt/bin/sbt -mem 4096 clean assembly
17+
RUN ./sbt/bin/sbt -mem 4096 clean stage
1818

1919
# ~~~~~~
2020

21-
FROM oracle/graalvm-ce:19.3.0-java11 as packager
21+
FROM oracle/graalvm-ce:20.2.0-java11 as packager
2222
LABEL maintainer="Herdy Handoko <[email protected]>"
2323
LABEL description="http4s GraalVM native-image packager"
2424

25-
ARG APP_NAME
26-
ENV APP_NAME ${APP_NAME:-realworld-assembly}
27-
ARG APP_VERSION
28-
ENV APP_VERSION ${APP_VERSION:-1.0.0-SNAPSHOT}
29-
3025
WORKDIR packager
3126
RUN gu install native-image
32-
COPY --from=assembler /assembler/target/scala-2.13/${APP_NAME}-${APP_VERSION}.jar ./
27+
COPY --from=assembler /assembler/target/universal/stage/lib/*.jar ./
3328
RUN native-image \
3429
--no-server \
35-
-cp ${APP_NAME}-${APP_VERSION}.jar
30+
--class-path "*" \
31+
com.hhandoko.realworld.Main
3632

3733
# ~~~~~~
3834

39-
FROM ubuntu:18.04
35+
FROM ubuntu:20.04
4036
LABEL maintainer="Herdy Handoko <[email protected]>"
4137
LABEL description="http4s GraalVM native-image runtime container"
4238

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ To run the API spec tests with [newman]:
3333

3434
_Note: Node.js 8+ and globally installed [newman] package are required_
3535

36-
### Production Packaging (uber-jar)
36+
### Production Packaging (universal format)
3737

3838
To package and run it as an uber-jar:
3939

40-
1. Run `sbt assembly` to package the application into an uber-jar (`realworld-assembly-1.0.0-SNAPSHOT.jar`)
41-
1. Run `java -jar target/scala-2.13/realworld-assembly-1.0.0-SNAPSHOT.jar` to run the web application
40+
1. Run `sbt stage` to package the application into a universal distribution format (at `target/universal/stage/`)
41+
1. Run `./target/universal/stage/bin/realworld` to run the web application
4242

4343
### Production Packaging (Graal Native Image)
4444

@@ -51,7 +51,8 @@ To package and run it as a Graal native image:
5151
```shell
5252
native-image \
5353
--no-server \
54-
-cp target/scala-2.13/realworld-assembly-1.0.0-SNAPSHOT.jar
54+
--class-path "target/universal/stage/lib/*" \
55+
com.hhandoko.realworld.Main
5556
```
5657

5758
1. Run `./realworld` to run the web application
@@ -75,8 +76,8 @@ Please read [PROGRESS] for more details.
7576

7677
# Issues
7778

79+
- Native image generation sometimes fail with non-initialized charset issue error message (simply retry until succeeds)
7880
- Native image generation with `jwt-scala` fails ([oracle/graal/#1152](https://github.com/oracle/graal/issues/1152))
79-
- Native image generation with Scala 2.13 fails ([oracle/graal/#1863](https://github.com/oracle/graal/issues/1863))
8081
- JWT token decoding in native image fails ([oracle/graal/#1240](https://github.com/oracle/graal/issues/1240))
8182

8283
# Contributing

build.sbt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
enablePlugins(FlywayPlugin)
2+
enablePlugins(JavaAppPackaging)
23

34
lazy val realworld =
45
(project in file("."))

project/Common.scala

+9-18
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import scala.io.Source
44
import io.github.davidmweber.FlywayPlugin.autoImport._
55
import sbt.Keys._
66
import sbt._
7-
import sbtassembly.AssemblyKeys._
8-
import sbtassembly.MergeStrategy
97

108
object Common {
119

@@ -25,18 +23,20 @@ object Common {
2523
private val logbackVersion = "1.2.3"
2624
private val specs2Version = "4.10.2"
2725

28-
// Compiler plugin dependency versions
29-
private val kindProjectorVersion = "0.11.0"
26+
// Compiler plugin (incl. Graal) dependency versions
3027
private val betterMonadicForVersion = "0.3.1"
28+
private val kindProjectorVersion = "0.11.0"
29+
private val graalVmVersion = "20.2.0"
3130

3231
final val settings: Seq[Setting[_]] =
33-
projectSettings ++ dependencySettings ++ flywaySettings ++ compilerPlugins ++ assemblySettings
32+
projectSettings ++ dependencySettings ++ flywaySettings ++ compilerPlugins
3433

3534
private[this] def projectSettings = Seq(
3635
organization := "com.hhandoko",
3736
name := "realworld",
3837
version := using(Source.fromFile("VERSION.txt")) { _.mkString },
39-
scalaVersion := "2.13.3"
38+
scalaVersion := "2.13.3",
39+
mainClass in Compile := Some("com.hhandoko.realworld.Main")
4040
)
4141

4242
private[this] def dependencySettings = Seq(
@@ -52,12 +52,13 @@ object Common {
5252
"org.http4s" %% "http4s-circe" % http4sVersion,
5353
"org.http4s" %% "http4s-dsl" % http4sVersion,
5454
"org.postgresql" % "postgresql" % postgresVersion,
55+
"org.scalameta" %% "svm-subs" % graalVmVersion % "compile-internal",
56+
"org.specs2" %% "specs2-core" % specs2Version % Test,
5557
"org.tpolecat" %% "doobie-core" % doobieVersion,
5658
"org.tpolecat" %% "doobie-h2" % doobieVersion % Test,
5759
"org.tpolecat" %% "doobie-hikari" % doobieVersion,
5860
"org.tpolecat" %% "doobie-postgres" % doobieVersion,
59-
"org.tpolecat" %% "doobie-specs2" % doobieVersion % Test,
60-
"org.specs2" %% "specs2-core" % specs2Version % Test
61+
"org.tpolecat" %% "doobie-specs2" % doobieVersion % Test
6162
)
6263
)
6364

@@ -81,16 +82,6 @@ object Common {
8182
flywayLocations := Seq("filesystem:db/migration/postgresql", "filesystem:db/seed")
8283
)
8384

84-
private[this] def assemblySettings = Seq(
85-
assemblyMergeStrategy in assembly := {
86-
case "module-info.class" =>
87-
MergeStrategy.concat
88-
case f =>
89-
val oldStrategy = (assemblyMergeStrategy in assembly).value
90-
oldStrategy(f)
91-
}
92-
)
93-
9485
/**
9586
* Basic auto-closing implementation for closeable resource.
9687
*

project/plugins.sbt

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// See: https://github.com/mefellows/sbt-dotenv
33
addSbtPlugin("au.com.onegeek" %% "sbt-dotenv" % "2.1.146")
44

5-
// Add `assembly` task for creating uber-jar
6-
// See: https://github.com/sbt/sbt-assembly
7-
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
8-
95
// Check Maven and Ivy repositories for dependency updates
106
// See: https://github.com/rtimush/sbt-updates
117
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.5.1")
128

9+
// Build application distribution packages in native formats
10+
// See: https://github.com/sbt/sbt-native-packager
11+
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.6")
12+
1313
// Pass recommended Scala compiler flags
1414
// See: https://github.com/DavidGregory084/sbt-tpolecat
1515
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.14")

scripts/graal/bin/dist.sh

+5-15
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,13 @@ if [ $# -gt 0 ] ; then
1414
DIST_FOLDER=$1
1515
fi
1616

17-
# Set application version
18-
APP_VERSION="`cat VERSION.txt`"
19-
20-
# Set artifact name
21-
APP_NAME=realworld-assembly-${APP_VERSION}
22-
APP_JAR=${APP_NAME}.jar
23-
2417
# Graal version and path
2518
GRAAL_JAVA_VERSION=java11
2619
GRAAL_DIR=scripts/graal
2720
GRAAL_VERSION=`cat ${GRAAL_DIR}/VERSION.txt`
2821
GRAAL_HOME=${GRAAL_DIR}/sdk/graalvm-ce-${GRAAL_JAVA_VERSION}-${GRAAL_VERSION}
2922
GRAAL_BIN=''
3023

31-
# SunEC path
32-
SUNEC_PLATFORM=amd64
33-
SUNEC_PATH=${GRAAL_HOME}/jre/lib/${SUNEC_PLATFORM}
34-
3524
# Choose Graal SDK distribution for supported OSes
3625
OS_NAME="`uname`"
3726
set_graal_dist() {
@@ -59,9 +48,9 @@ clean_dist_folder() {
5948

6049
# Create an uber-jar and copy the artifact to the distribution folder
6150
create_assembly() {
62-
echo "${C_YELLOW}Packaging into uber-jar${C_RESET}"
63-
sbt -mem 4096 assembly
64-
cp target/scala-2.12/${APP_JAR} ${DIST_FOLDER}
51+
echo "${C_YELLOW}Packaging into universal distribution format${C_RESET}"
52+
sbt -mem 4096 stage
53+
cp target/universal/stage/lib/*.jar ${DIST_FOLDER}
6554
}
6655

6756
# Create native image in the distribution folder
@@ -76,7 +65,8 @@ create_native() {
7665
(cd ${DIST_FOLDER} \
7766
&& ../${GRAAL_HOME}/${GRAAL_BIN}/native-image \
7867
--no-server \
79-
-cp ${APP_JAR})
68+
--class-path "*" \
69+
com.hhandoko.realworld.Main)
8070
}
8171

8272
# Run

src/main/resources/META-INF/native-image/realworld-application/native-image.properties src/main/resources/META-INF/native-image/com.hhandoko/realworld/native-image.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Args = --allow-incomplete-classpath \
22
--enable-all-security-services \
3-
--initialize-at-build-time=ch.qos.logback,org.slf4j \
4-
--initialize-at-run-time=scala.Symbol$ \
3+
--initialize-at-build-time \
4+
--initialize-at-run-time=org.postgresql.sspi.SSPIClient \
55
-H:+ReportUnsupportedElementsAtRuntime \
66
-H:Class=com.hhandoko.realworld.Main \
77
-H:EnableURLProtocols=http,https \

0 commit comments

Comments
 (0)