Skip to content

Commit

Permalink
Enable GraalVM
Browse files Browse the repository at this point in the history
  • Loading branch information
electrocucaracha committed Dec 6, 2024
1 parent e30ebee commit 3318fc0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
24 changes: 24 additions & 0 deletions Dockerfile.graalvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM ghcr.io/graalvm/native-image-community:23 AS build

RUN microdnf install -y maven

WORKDIR /app

COPY . /app

RUN mvn -Pnative package

RUN mkdir -p /out && ldd /app/target/server | awk 'NF == 4 { system("cp --parents " $3 " /out") }'

FROM scratch

WORKDIR /app

COPY --from=build /out /
COPY --from=build /app/target/server ./
COPY --from=build /usr/lib/ld-linux-*.so.* /lib/

USER 10000
EXPOSE 8080

ENTRYPOINT ["./server"]
19 changes: 6 additions & 13 deletions demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,16 @@ function _get_stats {
}

# Deploy initial version
info "Deploy initial version of java web server"
info "Deploy version 1 of java web server"
kubectl create deployment java-server --image "$(sudo docker images --filter=reference='*/java-server:v1' --format "{{.Repository}}"):v1" --replicas 20
_get_stats

# Deploy distroless image
info "Upgrade the version of java web server"
# Deploy distroless jdeps/jlink image
info "Upgrade java web server to version 2"
kubectl set image deployments/java-server java-server="$(sudo docker images --filter=reference='*/java-server:v2' --format "{{.Repository}}"):v2"
_get_stats

# Warm-up stats

# Roll back previous image
info "Roll back the version of java web server"
kubectl set image deployments/java-server java-server="$(sudo docker images --filter=reference='*/java-server:v1' --format "{{.Repository}}"):v1"
_get_stats

# Roll back to distroless image
info "Roll back the version of java web server"
kubectl set image deployments/java-server java-server="$(sudo docker images --filter=reference='*/java-server:v2' --format "{{.Repository}}"):v2"
# Deploy distroless graalvm image
info "Upgrade java web server to version 3"
kubectl set image deployments/java-server java-server="$(sudo docker images --filter=reference='*/java-server:v2' --format "{{.Repository}}"):v3"
_get_stats
30 changes: 30 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand All @@ -23,4 +30,27 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
1 change: 1 addition & 0 deletions scripts/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function _build_imgs {

_build_img v1
_build_img v2 Dockerfile.distroless "true"
_build_img v3 Dockerfile.graalvm "true"
registry_name="$(sudo docker ps --filter ancestor=electrocucaracha/nginx:vts --format "{{.Names}}")"
registry_ip="$(sudo docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{"\n"}}{{end}}' "$registry_name" | awk 'NR==1{print $1}')"
curl -s "http://${registry_ip}:5001/v2/java-server/tags/list" | jq -r .
Expand Down

0 comments on commit 3318fc0

Please sign in to comment.