Skip to content

Commit

Permalink
Move tiny-java-containers under native-image/containerize category
Browse files Browse the repository at this point in the history
  • Loading branch information
olyagpl committed Dec 18, 2024
1 parent 4084651 commit 4f1feae
Show file tree
Hide file tree
Showing 33 changed files with 136 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
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:
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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ cd graalvm-demos
</thead>
<tbody>
<tr>
<td align="left" width="30%"><a href="/tiny-java-containers/">tiny-java-containers</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/tiny-java-containers.yml"><img alt="tiny-java-containers" src="https://github.com/graalvm/graalvm-demos/actions/workflows/tiny-java-containers.yml/badge.svg" /></a>
<td align="left" width="70%">Demonstrates how to build very small Docker container images with GraalVM Native Image and various lightweight base images. <br><strong>Technologies: </strong> Native Image, musl libc<br><strong>Reference: </strong><a href="https://www.graalvm.org/22.0/reference-manual/native-image/StaticImages/">Static and Mostly Static Images</a></td>
<td align="left" width="30%"><a href="/native-image/containerize/tiny-java-containers/">tiny-java-containers</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/containerize-tiny-java-containers.yml.yml"><img alt="native-image/containerize/tiny-java-containers" src="https://github.com/graalvm/graalvm-demos/actions/workflows/containerize-tiny-java-containers.yml/badge.svg" /></a>
<td align="left" width="70%">Demonstrates how to build very small Docker container images with GraalVM Native Image and various lightweight base images. <br><strong>Technologies: </strong> Native Image, musl libc<br><strong>Reference: </strong><a href="https://www.graalvm.org/latest/reference-manual/native-image/guides/build-static-executables/">Static and Mostly Static Images</a></td>
</tr>
<tr>
<td align="left" width="30%"><a href="/native-image/hello-world/">native-image/hello-world</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/native-image-hello-world.yml"><img alt="native-image/hello-world" src="https://github.com/graalvm/graalvm-demos/actions/workflows/native-image-hello-world.yml/badge.svg" /></a></td>
Expand Down Expand Up @@ -143,7 +143,7 @@ cd graalvm-demos
</thead>
<tbody>
<tr>
<td align="left" width="30%"><a href="/native-image/containerize/">native-image/containerize</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/native-image-containerize.yml"><img alt="native-image/containerizee" src="https://github.com/graalvm/graalvm-demos/actions/workflows/native-image-containerize.yml/badge.svg" /></a></td>
<td align="left" width="30%"><a href="/native-image/containerize/spring-boot-microservice-jibber/">spring-boot-microservice-jibber</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/containerize-spring-boot-jibber.yml"><img alt="native-image/containerize/spring-boot-microservice-jibber" src="https://github.com/graalvm/graalvm-demos/actions/workflows/containerize-spring-boot-jibber.yml/badge.svg" /></a></td>
<td align="left" width="70%">Demonstrates how to compile a Spring Boot 3 application into a native executable using the Native Build Tools Maven plugin and a Maven profile <br> <strong>Technologies: </strong>Spring Boot, Native Image, Native Build Tools Maven plugin <br><strong>Reference: </strong><a href="https://www.graalvm.org/latest/reference-manual/native-image/guides/containerise-native-executable-and-run-in-docker-container/">Containerize a Native Executable and Run in a Container</a>, <a href="https://docs.oracle.com/en/graalvm/jdk/21/docs/getting-started/oci/cloud-shell/">Oracle GraalVM in OCI Cloud Shell</a></td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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<String> jibber() {
return ResponseEntity.ok(j.generate());
}
}
Original file line number Diff line number Diff line change
@@ -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("<br/>\n");
}
//
return b.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
management.endpoints.web.exposure.include=metrics,health,info,prometheus
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.

0 comments on commit 4f1feae

Please sign in to comment.