diff --git a/.github/workflows/tiny-java-containers.yml b/.github/workflows/containerize-tiny-java-containers.yml similarity index 87% rename from .github/workflows/tiny-java-containers.yml rename to .github/workflows/containerize-tiny-java-containers.yml index 362557733..2ffa711c0 100644 --- a/.github/workflows/tiny-java-containers.yml +++ b/.github/workflows/containerize-tiny-java-containers.yml @@ -1,9 +1,9 @@ -name: tiny-java-containers +name: native-image/containerize/tiny-java-containers on: push: paths: - - 'tiny-java-containers/**' - - '.github/workflows/tiny-java-containers.yml' + - 'native-image/containerize/tiny-java-containers/**' + - '.github/workflows/containerize-tiny-java-containers.yml' schedule: - cron: "0 0 1 * *" # run every month workflow_dispatch: @@ -11,20 +11,23 @@ permissions: contents: read jobs: run: - name: Run 'tiny-java-containers' + name: Run 'native-image/containerize/tiny-java-containers' runs-on: ubuntu-20.04 # Docker has changed its behavior on Ubuntu 22.04 timeout-minutes: 20 + strategy: + matrix: + java-version: ['21', '24-ea'] steps: - uses: actions/checkout@v4 - uses: graalvm/setup-graalvm@v1 with: - java-version: '21' + java-version: ${{ matrix.java-version }} distribution: 'graalvm' github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Run 'tiny-java-containers' + - name: Run 'native-image/containerize/tiny-java-containers' run: | sleep_period=5 - cd tiny-java-containers + cd native-image/containerize/tiny-java-containers # Hello World # cd helloworld diff --git a/README.md b/README.md index 290fcf538..84990fcd8 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ cd graalvm-demos - tiny-java-containers
tiny-java-containers - Demonstrates how to build very small Docker container images with GraalVM Native Image and various lightweight base images.
Technologies: Native Image, musl libc
Reference: Static and Mostly Static Images + tiny-java-containers
native-image/containerize/tiny-java-containers + Demonstrates how to build very small Docker container images with GraalVM Native Image and various lightweight base images.
Technologies: Native Image, musl libc
Reference: Static and Mostly Static Images native-image/hello-world
native-image/hello-world @@ -143,7 +143,7 @@ cd graalvm-demos - native-image/containerize
native-image/containerizee + spring-boot-microservice-jibber
native-image/containerize/spring-boot-microservice-jibber Demonstrates how to compile a Spring Boot 3 application into a native executable using the Native Build Tools Maven plugin and a Maven profile
Technologies: Spring Boot, Native Image, Native Build Tools Maven plugin
Reference: Containerize a Native Executable and Run in a Container, Oracle GraalVM in OCI Cloud Shell diff --git a/native-image/containerize/spring-boot-microservice-jibber/.mvn/wrapper/maven-wrapper.properties b/native-image/containerize/spring-boot-microservice-jibber/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 000000000..a6cd062b9 --- /dev/null +++ b/native-image/containerize/spring-boot-microservice-jibber/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/native-image/containerize/spring-boot-microservice-jibber/src/main/java/com/example/benchmarks/jibber/DemoApplication.java b/native-image/containerize/spring-boot-microservice-jibber/src/main/java/com/example/benchmarks/jibber/DemoApplication.java new file mode 100644 index 000000000..c3a4f9bbd --- /dev/null +++ b/native-image/containerize/spring-boot-microservice-jibber/src/main/java/com/example/benchmarks/jibber/DemoApplication.java @@ -0,0 +1,32 @@ +/* + * Copyright © 2023, Oracle and/or its affiliates. + * Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/. + */ + +package com.example.benchmarks.jibber; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + + +@SpringBootApplication +@RestController +public class DemoApplication { + + @Autowired + Jabberwocky j; + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + + @RequestMapping(method = RequestMethod.GET, path = "/jibber") + ResponseEntity jibber() { + return ResponseEntity.ok(j.generate()); + } +} \ No newline at end of file diff --git a/native-image/containerize/spring-boot-microservice-jibber/src/main/java/com/example/benchmarks/jibber/Jabberwocky.java b/native-image/containerize/spring-boot-microservice-jibber/src/main/java/com/example/benchmarks/jibber/Jabberwocky.java new file mode 100644 index 000000000..78ee0eaaa --- /dev/null +++ b/native-image/containerize/spring-boot-microservice-jibber/src/main/java/com/example/benchmarks/jibber/Jabberwocky.java @@ -0,0 +1,68 @@ +/* + * Copyright © 2023, Oracle and/or its affiliates. + * Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/. + */ + +package com.example.benchmarks.jibber; + +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import rita.RiMarkov; + +@Service +@Scope("singleton") +public class Jabberwocky { + // + private RiMarkov r; + + public Jabberwocky() { + loadModel(); + } + + private void loadModel() { + // + String text = "’Twas brillig, and the slithy toves " + + "Did gyre and gimble in the wabe: " + + "All mimsy were the borogoves, " + + "And the mome raths outgrabe. " + + "Beware the Jabberwock, my son! " + + "The jaws that bite, the claws that catch! " + + "Beware the Jubjub bird, and shun " + + "The frumious Bandersnatch! " + + "He took his vorpal sword in hand; " + + "Long time the manxome foe he sought— " + + "So rested he by the Tumtum tree " + + "And stood awhile in thought. " + + "And, as in uffish thought he stood, " + + "The Jabberwock, with eyes of flame, " + + "Came whiffling through the tulgey wood, " + + "And burbled as it came! " + + "One, two! One, two! And through and through " + + "The vorpal blade went snicker-snack! " + + "He left it dead, and with its head " + + "He went galumphing back. " + + "And hast thou slain the Jabberwock? " + + "Come to my arms, my beamish boy! " + + "O frabjous day! Callooh! Callay! " + + "He chortled in his joy. " + + "’Twas brillig, and the slithy toves " + + "Did gyre and gimble in the wabe: " + + "All mimsy were the borogoves, " + + "And the mome raths outgrabe."; + this.r = new RiMarkov(3); + this.r.addText(text); + } + public String generate() { + String[] lines = this.r.generate(10); + StringBuilder b = new StringBuilder(); + // + for (String line : lines ) { + b.append(line); + b.append("
\n"); + } + // + return b.toString(); + } + +} \ No newline at end of file diff --git a/native-image/containerize/spring-boot-microservice-jibber/src/main/resources/application.properties b/native-image/containerize/spring-boot-microservice-jibber/src/main/resources/application.properties new file mode 100644 index 000000000..2ea5b1d98 --- /dev/null +++ b/native-image/containerize/spring-boot-microservice-jibber/src/main/resources/application.properties @@ -0,0 +1 @@ +management.endpoints.web.exposure.include=metrics,health,info,prometheus \ No newline at end of file diff --git a/tiny-java-containers/README.md b/native-image/containerize/tiny-java-containers/README.md similarity index 97% rename from tiny-java-containers/README.md rename to native-image/containerize/tiny-java-containers/README.md index f92a5f54c..44b038d39 100644 --- a/tiny-java-containers/README.md +++ b/native-image/containerize/tiny-java-containers/README.md @@ -9,7 +9,7 @@ shared libraries, an executable has to be fully statically linked with all needed libraries and resources. To support static linking of `libc`, GraalVM Native Image supports using the -"lightweight, fast, simple, free" [musl](https://musl.libc.org/) libc +"lightweight, fast, simple, free" [musl](https://musl.libc.org/) `libc` implementation. You can watch a [Devoxx 2022](https://devoxx.be/) session that walks through @@ -176,15 +176,13 @@ or ![](images/keyboard.jpg) `docker run --init --rm -p8000:8000 jwebserver:scratch.static-upx` Using `curl` or your favourite tool you can hit `http://localhost:8000` to fetch -the index.html file. +the _index.html_ file. ## Wrapping Up A fully functional, albeit minimal, Java "microservice" was compiled into a native Linux executable and packaged into Distroless, Alpine, and `scratch`-based container images thanks to GraalVM Native Image's support for -various linking options including fully static linking with the `musl` libc. +various linking options including fully static linking with `musl libc`. -To learn more about linking options check out [Static and Mostly Static -Images](https://www.graalvm.org/latest/reference-manual/native-image/guides/build-static-executables/) -in the GraalVM docs. \ No newline at end of file +To learn more about linking options check out [Static and Mostly Static Images](https://www.graalvm.org/latest/reference-manual/native-image/guides/build-static-executables/) in the GraalVM docs. \ No newline at end of file diff --git a/tiny-java-containers/clean.sh b/native-image/containerize/tiny-java-containers/clean.sh similarity index 100% rename from tiny-java-containers/clean.sh rename to native-image/containerize/tiny-java-containers/clean.sh diff --git a/tiny-java-containers/helloworld/Dockerfile b/native-image/containerize/tiny-java-containers/helloworld/Dockerfile similarity index 100% rename from tiny-java-containers/helloworld/Dockerfile rename to native-image/containerize/tiny-java-containers/helloworld/Dockerfile diff --git a/tiny-java-containers/helloworld/Hello.java b/native-image/containerize/tiny-java-containers/helloworld/Hello.java similarity index 100% rename from tiny-java-containers/helloworld/Hello.java rename to native-image/containerize/tiny-java-containers/helloworld/Hello.java diff --git a/tiny-java-containers/helloworld/build.sh b/native-image/containerize/tiny-java-containers/helloworld/build.sh similarity index 100% rename from tiny-java-containers/helloworld/build.sh rename to native-image/containerize/tiny-java-containers/helloworld/build.sh diff --git a/tiny-java-containers/helloworld/clean.sh b/native-image/containerize/tiny-java-containers/helloworld/clean.sh similarity index 100% rename from tiny-java-containers/helloworld/clean.sh rename to native-image/containerize/tiny-java-containers/helloworld/clean.sh diff --git a/tiny-java-containers/images/keyboard.jpg b/native-image/containerize/tiny-java-containers/images/keyboard.jpg similarity index 100% rename from tiny-java-containers/images/keyboard.jpg rename to native-image/containerize/tiny-java-containers/images/keyboard.jpg diff --git a/tiny-java-containers/images/linkingoptions.png b/native-image/containerize/tiny-java-containers/images/linkingoptions.png similarity index 100% rename from tiny-java-containers/images/linkingoptions.png rename to native-image/containerize/tiny-java-containers/images/linkingoptions.png diff --git a/tiny-java-containers/images/youtube.png b/native-image/containerize/tiny-java-containers/images/youtube.png similarity index 100% rename from tiny-java-containers/images/youtube.png rename to native-image/containerize/tiny-java-containers/images/youtube.png diff --git a/tiny-java-containers/jwebserver/Dockerfile.alpine.static b/native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.alpine.static similarity index 100% rename from tiny-java-containers/jwebserver/Dockerfile.alpine.static rename to native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.alpine.static diff --git a/tiny-java-containers/jwebserver/Dockerfile.distroless-base.mostly b/native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.distroless-base.mostly similarity index 100% rename from tiny-java-containers/jwebserver/Dockerfile.distroless-base.mostly rename to native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.distroless-base.mostly diff --git a/tiny-java-containers/jwebserver/Dockerfile.distroless-java-base.dynamic b/native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.distroless-java-base.dynamic similarity index 100% rename from tiny-java-containers/jwebserver/Dockerfile.distroless-java-base.dynamic rename to native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.distroless-java-base.dynamic diff --git a/tiny-java-containers/jwebserver/Dockerfile.distroless-java-base.jlink b/native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.distroless-java-base.jlink similarity index 100% rename from tiny-java-containers/jwebserver/Dockerfile.distroless-java-base.jlink rename to native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.distroless-java-base.jlink diff --git a/tiny-java-containers/jwebserver/Dockerfile.distroless-static.static b/native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.distroless-static.static similarity index 100% rename from tiny-java-containers/jwebserver/Dockerfile.distroless-static.static rename to native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.distroless-static.static diff --git a/tiny-java-containers/jwebserver/Dockerfile.jvm-debian-slim b/native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.jvm-debian-slim similarity index 100% rename from tiny-java-containers/jwebserver/Dockerfile.jvm-debian-slim rename to native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.jvm-debian-slim diff --git a/tiny-java-containers/jwebserver/Dockerfile.jvm-distroless-java b/native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.jvm-distroless-java similarity index 100% rename from tiny-java-containers/jwebserver/Dockerfile.jvm-distroless-java rename to native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.jvm-distroless-java diff --git a/tiny-java-containers/jwebserver/Dockerfile.jvm-eclipse-temurin b/native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.jvm-eclipse-temurin similarity index 100% rename from tiny-java-containers/jwebserver/Dockerfile.jvm-eclipse-temurin rename to native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.jvm-eclipse-temurin diff --git a/tiny-java-containers/jwebserver/Dockerfile.scratch.static b/native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.scratch.static similarity index 100% rename from tiny-java-containers/jwebserver/Dockerfile.scratch.static rename to native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.scratch.static diff --git a/tiny-java-containers/jwebserver/Dockerfile.scratch.static-upx b/native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.scratch.static-upx similarity index 100% rename from tiny-java-containers/jwebserver/Dockerfile.scratch.static-upx rename to native-image/containerize/tiny-java-containers/jwebserver/Dockerfile.scratch.static-upx diff --git a/tiny-java-containers/jwebserver/build-all.sh b/native-image/containerize/tiny-java-containers/jwebserver/build-all.sh similarity index 100% rename from tiny-java-containers/jwebserver/build-all.sh rename to native-image/containerize/tiny-java-containers/jwebserver/build-all.sh diff --git a/tiny-java-containers/jwebserver/build-dynamic.sh b/native-image/containerize/tiny-java-containers/jwebserver/build-dynamic.sh similarity index 100% rename from tiny-java-containers/jwebserver/build-dynamic.sh rename to native-image/containerize/tiny-java-containers/jwebserver/build-dynamic.sh diff --git a/tiny-java-containers/jwebserver/build-jlink.sh b/native-image/containerize/tiny-java-containers/jwebserver/build-jlink.sh similarity index 100% rename from tiny-java-containers/jwebserver/build-jlink.sh rename to native-image/containerize/tiny-java-containers/jwebserver/build-jlink.sh diff --git a/tiny-java-containers/jwebserver/build-jvm.sh b/native-image/containerize/tiny-java-containers/jwebserver/build-jvm.sh similarity index 100% rename from tiny-java-containers/jwebserver/build-jvm.sh rename to native-image/containerize/tiny-java-containers/jwebserver/build-jvm.sh diff --git a/tiny-java-containers/jwebserver/build-mostly.sh b/native-image/containerize/tiny-java-containers/jwebserver/build-mostly.sh similarity index 100% rename from tiny-java-containers/jwebserver/build-mostly.sh rename to native-image/containerize/tiny-java-containers/jwebserver/build-mostly.sh diff --git a/tiny-java-containers/jwebserver/build-static.sh b/native-image/containerize/tiny-java-containers/jwebserver/build-static.sh similarity index 100% rename from tiny-java-containers/jwebserver/build-static.sh rename to native-image/containerize/tiny-java-containers/jwebserver/build-static.sh diff --git a/tiny-java-containers/jwebserver/clean.sh b/native-image/containerize/tiny-java-containers/jwebserver/clean.sh similarity index 100% rename from tiny-java-containers/jwebserver/clean.sh rename to native-image/containerize/tiny-java-containers/jwebserver/clean.sh diff --git a/tiny-java-containers/jwebserver/index.html b/native-image/containerize/tiny-java-containers/jwebserver/index.html similarity index 100% rename from tiny-java-containers/jwebserver/index.html rename to native-image/containerize/tiny-java-containers/jwebserver/index.html