Skip to content

Commit

Permalink
Add a new workshop: Multi-Cloud Apps with GraalVM - Up and Running
Browse files Browse the repository at this point in the history
  • Loading branch information
olyagpl committed Sep 27, 2024
1 parent 09c1173 commit 73a57fd
Show file tree
Hide file tree
Showing 530 changed files with 119,961 additions and 0 deletions.
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"]
585 changes: 585 additions & 0 deletions native-image/spring-boot-webserver/README.md

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions native-image/spring-boot-webserver/build-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

./build-jar.sh
./build-jlink.sh
./build-dynamic-image.sh
./build-mostly-static-image.sh
./build-static-image.sh
./build-static-upx-image.sh

echo "Generated Executables"
ls -lh target/webserver*

echo "Generated Docker Container Images"
docker images webserver
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# Compile with fully dynamically linked shared libraries; optimize for size
./mvnw -Dmaven.test.skip=true -Pdynamic-size-optimized native:compile

# Distroless Java Base-provides glibc and other libraries needed by the JDK
docker build . -f Dockerfile.distroless-java-base.dynamic-optimized -t webserver:distroless-java-base.dynamic-optimized
7 changes: 7 additions & 0 deletions native-image/spring-boot-webserver/build-dynamic-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# Compile with fully dynamically linked shared libraries
./mvnw -Dmaven.test.skip=true native:compile

# Distroless Java Base-provides glibc and other libraries needed by the JDK
docker build . -f Dockerfile.distroless-java-base.dynamic -t webserver:distroless-java-base.dynamic
4 changes: 4 additions & 0 deletions native-image/spring-boot-webserver/build-jar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

# Distroless Java Base-provides glibc and other libraries needed by the JDK
docker build . -f Dockerfile.debian-slim.uber-jar -t webserver:debian-slim.jar
6 changes: 6 additions & 0 deletions native-image/spring-boot-webserver/build-jlink.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

rm -rf jlink-jre cp.txt

# Distroless Java Base-provides glibc and other libraries needed by the JDK
docker build . -f Dockerfile.distroless-java-base.jlink -t webserver:distroless-java-base.jlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# Compile linking zlib and JDK shared libraries except the standard C library (libc); optimize for size
./mvnw -Dmaven.test.skip=true -Pnative,mostly-static native:compile

# Distroless Base (provides glibc)
docker build . -f Dockerfile.distroless-base.mostly -t webserver:distroless-base.mostly-static
12 changes: 12 additions & 0 deletions native-image/spring-boot-webserver/build-static-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

TOOLCHAIN_DIR=${SCRIPT_DIR}/musl-toolchain
PATH=${TOOLCHAIN_DIR}/bin:${PATH}

# Create a statically linked binary that can be used without any additional library dependencies; optimize for size
./mvnw -Dmaven.test.skip=true -Pnative,fully-static native:compile

# Scratch-nothing
docker build . -f Dockerfile.scratch.static -t webserver:scratch.static
9 changes: 9 additions & 0 deletions native-image/spring-boot-webserver/build-static-upx-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

rm -f target/webserver.static-upx

# Compress with UPX
./upx --lzma --best -o target/webserver.static-upx target/webserver.static

# Scratch--fully static and compressed
docker build . -f Dockerfile.scratch.static-upx -t webserver:scratch.static-upx
6 changes: 6 additions & 0 deletions native-image/spring-boot-webserver/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set +e

./mvnw clean
rm -rf jlink-jre cp.txt
docker images webserver -q | grep -v TAG | awk '{print($1)}' | xargs docker rmi
Loading

0 comments on commit 73a57fd

Please sign in to comment.