From ab4f4848253f25ba22806c2e0e02a96c6b1ee395 Mon Sep 17 00:00:00 2001 From: Valentin Lieberknecht Date: Mon, 8 Jan 2024 12:28:38 +0100 Subject: [PATCH 01/11] bump to spring 3 --- Dockerfile | 2 +- Dockerfile.Multistage | 4 ++-- pom.xml | 10 +++++----- .../de/viadee/k8s/testapp/counter/CounterEntity.java | 4 ++-- .../de/viadee/k8s/testapp/counter/CounterService.java | 2 +- .../k8s/testapp/exception/ExceptionRestController.java | 1 - .../k8s/testapp/readiness/ReadinessController.java | 1 - 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8ba7d49..590606b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:11-slim +FROM openjdk:17-slim COPY target/k8s-demo-app.jar app.jar RUN groupadd -g 1000 appuser && \ useradd -u 1000 -g 1000 appuser diff --git a/Dockerfile.Multistage b/Dockerfile.Multistage index 3ef8f11..5d77d09 100644 --- a/Dockerfile.Multistage +++ b/Dockerfile.Multistage @@ -1,4 +1,4 @@ -FROM maven:3.6-jdk-11-slim as build_container +FROM maven:3.8-openjdk-17-slim as build_container WORKDIR /build COPY pom.xml . @@ -8,7 +8,7 @@ COPY . /usr/src/build WORKDIR /usr/src/build RUN mvn package -B -FROM openjdk:11-slim +FROM openjdk:17-slim COPY --from=build_container /usr/src/build/target/k8s-demo-app.jar app.jar RUN groupadd -g 1000 appuser && \ useradd -u 1000 -g 1000 appuser diff --git a/pom.xml b/pom.xml index 0a44599..1633a25 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ de.viadee.k8s.testapp k8s-demo-app - 0.2.0-SNAPSHOT + 0.2.1-SNAPSHOT jar k8s-demo-app @@ -14,14 +14,14 @@ org.springframework.boot spring-boot-starter-parent - 2.7.0 + 3.2.1 UTF-8 UTF-8 - 11 + 17 @@ -54,12 +54,12 @@ org.webjars bootstrap - 5.2.3 + 5.3.2 org.webjars webjars-locator-core - 0.54 + 0.55 diff --git a/src/main/java/de/viadee/k8s/testapp/counter/CounterEntity.java b/src/main/java/de/viadee/k8s/testapp/counter/CounterEntity.java index 50ed559..25d3639 100644 --- a/src/main/java/de/viadee/k8s/testapp/counter/CounterEntity.java +++ b/src/main/java/de/viadee/k8s/testapp/counter/CounterEntity.java @@ -2,8 +2,8 @@ import java.sql.Timestamp; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; @Entity public class CounterEntity { diff --git a/src/main/java/de/viadee/k8s/testapp/counter/CounterService.java b/src/main/java/de/viadee/k8s/testapp/counter/CounterService.java index b94d750..846707d 100644 --- a/src/main/java/de/viadee/k8s/testapp/counter/CounterService.java +++ b/src/main/java/de/viadee/k8s/testapp/counter/CounterService.java @@ -3,7 +3,7 @@ import java.sql.Timestamp; import java.util.Optional; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/de/viadee/k8s/testapp/exception/ExceptionRestController.java b/src/main/java/de/viadee/k8s/testapp/exception/ExceptionRestController.java index 450eebd..d98c3ac 100644 --- a/src/main/java/de/viadee/k8s/testapp/exception/ExceptionRestController.java +++ b/src/main/java/de/viadee/k8s/testapp/exception/ExceptionRestController.java @@ -16,5 +16,4 @@ public String throwException() { LOG.error("log exception on error level", runtimeException); throw runtimeException; } - } diff --git a/src/main/java/de/viadee/k8s/testapp/readiness/ReadinessController.java b/src/main/java/de/viadee/k8s/testapp/readiness/ReadinessController.java index f57f070..918cbfd 100644 --- a/src/main/java/de/viadee/k8s/testapp/readiness/ReadinessController.java +++ b/src/main/java/de/viadee/k8s/testapp/readiness/ReadinessController.java @@ -32,5 +32,4 @@ public ResponseEntity checkReadiness(@RequestParam(required = false, nam return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build(); } } - } From 9b829559e5a21c182e019da195eed5a469f860fe Mon Sep 17 00:00:00 2001 From: Valentin Lieberknecht Date: Sat, 13 Jan 2024 13:03:03 +0100 Subject: [PATCH 02/11] update actions to java 17 --- .github/workflows/build_push_to_ecr.yaml | 21 ++++++++------------ .github/workflows/maven.yml | 25 ++++++++++++------------ 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build_push_to_ecr.yaml b/.github/workflows/build_push_to_ecr.yaml index 722a3eb..57fad4a 100644 --- a/.github/workflows/build_push_to_ecr.yaml +++ b/.github/workflows/build_push_to_ecr.yaml @@ -1,16 +1,14 @@ name: build release and push to ECR -on: +on: release: types: [prereleased, released] jobs: build_and_push: runs-on: ubuntu-latest steps: - - name: Checkout uses: actions/checkout@v3 - - name: Login to Public ECR uses: docker/login-action@v1 with: @@ -19,16 +17,16 @@ jobs: password: ${{ secrets.AWS_PROD_ECR_VIADEE_SECRET_ACCESS_KEY }} env: AWS_REGION: us-east-1 - + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - + - name: Set up JDK 1.11 uses: actions/setup-java@v3 with: - distribution: 'adopt' # See 'Supported distributions' for available options - java-version: '11' - + distribution: "adopt" # See 'Supported distributions' for available options + java-version: "11" + - name: Cache local Maven repository uses: actions/cache@v2 with: @@ -40,9 +38,7 @@ jobs: - name: Maven package run: mvn package -B - - - - name: Docker meta + - name: Docker meta id: meta uses: docker/metadata-action@v3 with: @@ -60,5 +56,4 @@ jobs: platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 7018ca4..8e20752 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,26 +1,25 @@ # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven name: Java CI with Maven on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'adopt' - cache: maven - - name: Build with Maven - run: mvn -B package --file pom.xml + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: "17" + distribution: "liberica" + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml From f52ec0a6e2ba669037ca0ecf0c9860a5683adb7a Mon Sep 17 00:00:00 2001 From: cau Date: Mon, 5 Feb 2024 11:43:47 +0100 Subject: [PATCH 03/11] Update spring boot to 3.2.1 --- pom.xml | 8 ++++---- .../viadee/k8s/testapp/counter/CounterEntity.java | 6 +++--- .../k8s/testapp/counter/CounterRepository.java | 4 ++-- .../viadee/k8s/testapp/counter/CounterService.java | 10 ++++------ .../viadee/k8s/testapp/health/DbHealthCheck.java | 3 +-- .../k8s/testapp/health/FakedHealthCheck.java | 4 ++-- .../viadee/k8s/testapp/webapp/WebController.java | 14 ++++++-------- src/main/resources/templates/k8s_env.html | 10 +++++----- src/main/resources/templates/k8s_index.html | 6 +++--- .../testapp/testapp/TestappApplicationTests.java | 1 - 10 files changed, 30 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index 0a44599..338d014 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ de.viadee.k8s.testapp k8s-demo-app - 0.2.0-SNAPSHOT + 0.2.1-SNAPSHOT jar k8s-demo-app @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.7.0 + 3.2.1 @@ -54,12 +54,12 @@ org.webjars bootstrap - 5.2.3 + 5.3.2 org.webjars webjars-locator-core - 0.54 + 0.55 diff --git a/src/main/java/de/viadee/k8s/testapp/counter/CounterEntity.java b/src/main/java/de/viadee/k8s/testapp/counter/CounterEntity.java index 50ed559..b1a7086 100644 --- a/src/main/java/de/viadee/k8s/testapp/counter/CounterEntity.java +++ b/src/main/java/de/viadee/k8s/testapp/counter/CounterEntity.java @@ -1,9 +1,9 @@ package de.viadee.k8s.testapp.counter; -import java.sql.Timestamp; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; -import javax.persistence.Entity; -import javax.persistence.Id; +import java.sql.Timestamp; @Entity public class CounterEntity { diff --git a/src/main/java/de/viadee/k8s/testapp/counter/CounterRepository.java b/src/main/java/de/viadee/k8s/testapp/counter/CounterRepository.java index 8c02d5f..86d3f16 100644 --- a/src/main/java/de/viadee/k8s/testapp/counter/CounterRepository.java +++ b/src/main/java/de/viadee/k8s/testapp/counter/CounterRepository.java @@ -1,9 +1,9 @@ package de.viadee.k8s.testapp.counter; -import java.util.Optional; - import org.springframework.data.repository.CrudRepository; +import java.util.Optional; + public interface CounterRepository extends CrudRepository { Optional findById(String id); diff --git a/src/main/java/de/viadee/k8s/testapp/counter/CounterService.java b/src/main/java/de/viadee/k8s/testapp/counter/CounterService.java index b94d750..bf56feb 100644 --- a/src/main/java/de/viadee/k8s/testapp/counter/CounterService.java +++ b/src/main/java/de/viadee/k8s/testapp/counter/CounterService.java @@ -1,16 +1,14 @@ package de.viadee.k8s.testapp.counter; -import java.sql.Timestamp; -import java.util.Optional; - -import javax.annotation.PostConstruct; - +import com.zaxxer.hikari.HikariDataSource; +import jakarta.annotation.PostConstruct; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.zaxxer.hikari.HikariDataSource; +import java.sql.Timestamp; +import java.util.Optional; @Component public class CounterService { diff --git a/src/main/java/de/viadee/k8s/testapp/health/DbHealthCheck.java b/src/main/java/de/viadee/k8s/testapp/health/DbHealthCheck.java index ca72ddf..0faeffa 100644 --- a/src/main/java/de/viadee/k8s/testapp/health/DbHealthCheck.java +++ b/src/main/java/de/viadee/k8s/testapp/health/DbHealthCheck.java @@ -1,5 +1,6 @@ package de.viadee.k8s.testapp.health; +import de.viadee.k8s.testapp.counter.CounterService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -7,8 +8,6 @@ import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.stereotype.Component; -import de.viadee.k8s.testapp.counter.CounterService; - @Component public class DbHealthCheck implements HealthIndicator { diff --git a/src/main/java/de/viadee/k8s/testapp/health/FakedHealthCheck.java b/src/main/java/de/viadee/k8s/testapp/health/FakedHealthCheck.java index a4fffdd..b21ff17 100644 --- a/src/main/java/de/viadee/k8s/testapp/health/FakedHealthCheck.java +++ b/src/main/java/de/viadee/k8s/testapp/health/FakedHealthCheck.java @@ -1,7 +1,5 @@ package de.viadee.k8s.testapp.health; -import java.util.concurrent.atomic.AtomicInteger; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -9,6 +7,8 @@ import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.stereotype.Component; +import java.util.concurrent.atomic.AtomicInteger; + @Component public class FakedHealthCheck implements HealthIndicator { diff --git a/src/main/java/de/viadee/k8s/testapp/webapp/WebController.java b/src/main/java/de/viadee/k8s/testapp/webapp/WebController.java index 82a1a04..47d3b13 100644 --- a/src/main/java/de/viadee/k8s/testapp/webapp/WebController.java +++ b/src/main/java/de/viadee/k8s/testapp/webapp/WebController.java @@ -1,8 +1,8 @@ package de.viadee.k8s.testapp.webapp; -import java.util.Map; -import java.util.TreeMap; - +import com.zaxxer.hikari.HikariDataSource; +import de.viadee.k8s.testapp.counter.CounterEntity; +import de.viadee.k8s.testapp.counter.CounterService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -13,10 +13,8 @@ import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.GetMapping; -import com.zaxxer.hikari.HikariDataSource; - -import de.viadee.k8s.testapp.counter.CounterEntity; -import de.viadee.k8s.testapp.counter.CounterService; +import java.util.HashMap; +import java.util.Map; @Controller public class WebController { @@ -72,7 +70,7 @@ public String k8s_index(Model model) { @GetMapping("/env") public String k8s_env(Model model) { initBgColor(model); - Map env = new TreeMap<>(System.getenv()); + Map env = new HashMap<>(System.getenv()); model.addAttribute("env", env); diff --git a/src/main/resources/templates/k8s_env.html b/src/main/resources/templates/k8s_env.html index 2c4eaca..29af478 100644 --- a/src/main/resources/templates/k8s_env.html +++ b/src/main/resources/templates/k8s_env.html @@ -1,12 +1,12 @@ -
+
K8s Test App -
+
@@ -22,8 +22,8 @@

Environment Variables

- key - val + val + val @@ -32,7 +32,7 @@

Environment Variables

-
+
\ No newline at end of file diff --git a/src/main/resources/templates/k8s_index.html b/src/main/resources/templates/k8s_index.html index f945367..e973db8 100644 --- a/src/main/resources/templates/k8s_index.html +++ b/src/main/resources/templates/k8s_index.html @@ -1,12 +1,12 @@ -
+
K8s Test App -
+
@@ -29,7 +29,7 @@

welcome_text +
\ No newline at end of file diff --git a/src/test/java/de/viadee/k8s/testapp/testapp/TestappApplicationTests.java b/src/test/java/de/viadee/k8s/testapp/testapp/TestappApplicationTests.java index 0c01667..a4d4d5f 100644 --- a/src/test/java/de/viadee/k8s/testapp/testapp/TestappApplicationTests.java +++ b/src/test/java/de/viadee/k8s/testapp/testapp/TestappApplicationTests.java @@ -2,7 +2,6 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest public class TestappApplicationTests { From 84c576b2ff773914341ffe84a4ccd1ca4a7ce569 Mon Sep 17 00:00:00 2001 From: cau Date: Thu, 21 Mar 2024 21:58:43 +0100 Subject: [PATCH 04/11] first draft spring native --- pom.xml | 24 ++++++++---- .../NativeReflectionRuntimeHintConfig.java | 37 +++++++++++++++++++ .../viadee/k8s/testapp/config/WebConfig.java | 18 +++++++++ .../resources/templates/fragments/footer.html | 2 +- .../resources/templates/fragments/header.html | 2 +- 5 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 src/main/java/de/viadee/k8s/testapp/config/NativeReflectionRuntimeHintConfig.java create mode 100644 src/main/java/de/viadee/k8s/testapp/config/WebConfig.java diff --git a/pom.xml b/pom.xml index 338d014..0a349b7 100644 --- a/pom.xml +++ b/pom.xml @@ -14,14 +14,15 @@ org.springframework.boot spring-boot-starter-parent - 3.2.1 + 3.2.3 UTF-8 UTF-8 - 11 + 17 + 6.4.2.Final @@ -54,21 +55,30 @@ org.webjars bootstrap + 5.3.2 - - org.webjars - webjars-locator-core - 0.55 - ${project.artifactId} + + org.graalvm.buildtools + native-maven-plugin + + + de.viadee.k8s.testapp.K8sDemoApplication + + org.springframework.boot spring-boot-maven-plugin + + + de.viadee.k8s.testapp.K8sDemoApplication + + diff --git a/src/main/java/de/viadee/k8s/testapp/config/NativeReflectionRuntimeHintConfig.java b/src/main/java/de/viadee/k8s/testapp/config/NativeReflectionRuntimeHintConfig.java new file mode 100644 index 0000000..42fa1c9 --- /dev/null +++ b/src/main/java/de/viadee/k8s/testapp/config/NativeReflectionRuntimeHintConfig.java @@ -0,0 +1,37 @@ +package de.viadee.k8s.testapp.config; + +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.annotation.RegisterReflectionForBinding; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportRuntimeHints; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +import java.util.HashMap; +import java.util.Map; + + +@Configuration +@RegisterReflectionForBinding(classes = {HashMap.class}) +@ImportRuntimeHints(NativeReflectionRuntimeHintConfig.NativeRuntimeHints.class) +@EnableWebMvc +public class NativeReflectionRuntimeHintConfig { + + static class NativeRuntimeHints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + + // especially for rendering k8s_env.html + hints.reflection().registerType(Map.Entry.class, MemberCategory.values()); + // hints.reflection().registerType(HashMap.class, MemberCategory.values()); + // Innere Klassen + hints.reflection().registerTypeIfPresent(classLoader, "java.util.HashMap$Node" + , MemberCategory.values()); + + hints.resources().registerPattern("META-INF/resources/webjars/bootstrap/5.3.2/css/bootstrap.min.css"); + hints.resources().registerPattern("META-INF/resources/webjars/bootstrap/5.3.2/js/bootstrap.min.js"); + } + } +} diff --git a/src/main/java/de/viadee/k8s/testapp/config/WebConfig.java b/src/main/java/de/viadee/k8s/testapp/config/WebConfig.java new file mode 100644 index 0000000..c23dbd0 --- /dev/null +++ b/src/main/java/de/viadee/k8s/testapp/config/WebConfig.java @@ -0,0 +1,18 @@ +package de.viadee.k8s.testapp.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + + +@Configuration +@EnableWebMvc +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); + } + +} \ No newline at end of file diff --git a/src/main/resources/templates/fragments/footer.html b/src/main/resources/templates/fragments/footer.html index c484e32..98bd22c 100644 --- a/src/main/resources/templates/fragments/footer.html +++ b/src/main/resources/templates/fragments/footer.html @@ -9,7 +9,7 @@
+ src="webjars/bootstrap/5.3.2/js/bootstrap.min.js">
diff --git a/src/main/resources/templates/fragments/header.html b/src/main/resources/templates/fragments/header.html index f3f0d91..f6b2858 100644 --- a/src/main/resources/templates/fragments/header.html +++ b/src/main/resources/templates/fragments/header.html @@ -3,7 +3,7 @@
+ href="webjars/bootstrap/5.3.2/css/bootstrap.min.css" /> K8s Test App
From 2b30d85da225489b11a8d029bbbd4f67795cc3f6 Mon Sep 17 00:00:00 2001 From: "Claus U. (UsC)" <3043061+cl-a-us@users.noreply.github.com> Date: Wed, 16 Oct 2024 12:06:59 +0200 Subject: [PATCH 05/11] introduce devcontainer.json for codespace with graalvm * Create devcontainer.json used https://github.com/microsoft/vscode-remote-try-java as base * update spring and add native hints * Update README.md --- .devcontainer/devcontainer.json | 28 ++++++++++++++++++++++++++++ README.md | 16 ++++++++++++++++ pom.xml | 8 +++----- 3 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..48d0ded --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,28 @@ +// see https://github.com/microsoft/vscode-remote-try-java for detailed example on vscode remote java project +{ + "name": "dev-container-with-graalvm", + // java images can be found here: https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/java/about + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "ghcr.io/devcontainers/features/java:1": { + // version is installed via sdkman + // see https://sdkman.io/jdks#graalce and https://www.graalvm.org/downloads/ for version + "version": "21-graalce", + "installMaven": "true", + "mavenVersion": "3.8.6", + "installGradle": "false" + } + }, + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + "settings": {}, + "extensions": [ + "streetsidesoftware.code-spell-checker" + ] + } + } + // Use 'postCreateCommand' to run commands after the container is created. +, "postCreateCommand": "java -version" +} diff --git a/README.md b/README.md index dbd5f0a..db025c4 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,19 @@ Or build and run with maven locally: Or just do a local docker build: `docker build -t imagename .` Then you can run the container locally. + + +## Native Build + + ```shell +mvn clean +# 'package' contains step 'process-aot' which is needed for native:compile +mvn package -Pnative +mvn native:compile + ``` + +### start native build +```shell +./target/k8s-demo-app +./target/k8s-demo-app --spring.profiles.active=red +``` diff --git a/pom.xml b/pom.xml index 0a349b7..11ba87b 100644 --- a/pom.xml +++ b/pom.xml @@ -14,14 +14,14 @@ org.springframework.boot spring-boot-starter-parent - 3.2.3 + 3.3.4 UTF-8 UTF-8 - 17 + 21 6.4.2.Final @@ -75,9 +75,7 @@ org.springframework.boot spring-boot-maven-plugin - - de.viadee.k8s.testapp.K8sDemoApplication - + From 29d73160d5aee14a87c3adccc7cea7bd06c1e97c Mon Sep 17 00:00:00 2001 From: "Claus U. (UsC)" <3043061+cl-a-us@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:44:57 +0000 Subject: [PATCH 06/11] add additional hint --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index db025c4..f33fdbd 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ mvn clean # 'package' contains step 'process-aot' which is needed for native:compile mvn package -Pnative mvn native:compile +# If "[1/8] Initializing..." fails, it might be due to a lag of resources. Try increasing the VM resources. ``` ### start native build From c9765aa918c838f9b90ba1d916e37dcaba07f92c Mon Sep 17 00:00:00 2001 From: "Claus U. (UsC)" <3043061+cl-a-us@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:09:34 +0000 Subject: [PATCH 07/11] update actions to JDK 21 --- .github/workflows/build_push_to_ecr.yaml | 23 ++++++++--------------- .github/workflows/maven.yml | 16 +++++++++------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build_push_to_ecr.yaml b/.github/workflows/build_push_to_ecr.yaml index 57fad4a..5945235 100644 --- a/.github/workflows/build_push_to_ecr.yaml +++ b/.github/workflows/build_push_to_ecr.yaml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Login to Public ECR uses: docker/login-action@v1 @@ -21,26 +21,19 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Set up JDK 1.11 - uses: actions/setup-java@v3 + - name: Set up JDK 21 + uses: actions/setup-java@v4 with: + java-version: "21" distribution: "adopt" # See 'Supported distributions' for available options - java-version: "11" - - - name: Cache local Maven repository - uses: actions/cache@v2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- + cache: 'maven' - name: Maven package - run: mvn package -B + run: mvn -B package - name: Docker meta id: meta - uses: docker/metadata-action@v3 + uses: docker/metadata-action@v5 with: images: public.ecr.aws/m4k8r3n4/k8s-demo-app tags: | @@ -50,7 +43,7 @@ jobs: type=semver,pattern={{major}}.{{minor}} - name: Build and push Docker images - uses: docker/build-push-action@v2.10.0 + uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64,linux/arm64 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8e20752..212a166 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -14,12 +14,14 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 + - name: Checkout + uses: actions/checkout@v4 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - java-version: "17" - distribution: "liberica" - cache: maven - - name: Build with Maven - run: mvn -B package --file pom.xml + java-version: "21" + distribution: "liberica" # See 'Supported distributions' for available options + cache: 'maven' + + - name: Maven package + run: mvn -B package From e782b5dcece1266348f6c19358b89e447815471b Mon Sep 17 00:00:00 2001 From: "Claus U. (UsC)" <3043061+cl-a-us@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:16:25 +0000 Subject: [PATCH 08/11] add native build workflow --- .github/workflows/native_build.yaml | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/native_build.yaml diff --git a/.github/workflows/native_build.yaml b/.github/workflows/native_build.yaml new file mode 100644 index 0000000..9d67e37 --- /dev/null +++ b/.github/workflows/native_build.yaml @@ -0,0 +1,33 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +name: Java CI Native Build with Maven + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: "graalvm" # See 'Supported distributions' for available options + cache: 'maven' + + - name: Maven native build + run: mvn package -Pnative native:compile + - name: 'Upload Artifact' + uses: actions/upload-artifact@v4 + with: + name: native-build + path: target/k8s-demo-app + retention-days: 5 From 1153cf8b3ece841314cbe6d2f6895920520af5f2 Mon Sep 17 00:00:00 2001 From: "Claus U. (UsC)" <3043061+cl-a-us@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:01:36 +0000 Subject: [PATCH 09/11] fix k8s_env copy past bug --- README.md | 2 +- src/main/resources/templates/k8s_env.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f33fdbd..08c291a 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Or build and run with maven locally: Then you can run the container locally. -## Native Build +## Native Build in github Codespaces ```shell mvn clean diff --git a/src/main/resources/templates/k8s_env.html b/src/main/resources/templates/k8s_env.html index 29af478..c423eab 100644 --- a/src/main/resources/templates/k8s_env.html +++ b/src/main/resources/templates/k8s_env.html @@ -22,7 +22,7 @@

Environment Variables

- val + key val From 5f6d52f358468a1f7edcaeba0c361cb66d9e14d8 Mon Sep 17 00:00:00 2001 From: "Claus U. (UsC)" <3043061+cl-a-us@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:02:55 +0000 Subject: [PATCH 10/11] add action 'native build push to ecr' --- .../workflows/native_build_push_to_ecr.yaml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/native_build_push_to_ecr.yaml diff --git a/.github/workflows/native_build_push_to_ecr.yaml b/.github/workflows/native_build_push_to_ecr.yaml new file mode 100644 index 0000000..9b69201 --- /dev/null +++ b/.github/workflows/native_build_push_to_ecr.yaml @@ -0,0 +1,52 @@ +name: build release and push to ECR +on: + release: + types: [prereleased, released] +jobs: + build_and_push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to Public ECR + uses: docker/login-action@v1 + with: + registry: public.ecr.aws + username: ${{ secrets.AWS_PROD_ECR_VIADEE_ACCESS_KEY_ID }} + password: ${{ secrets.AWS_PROD_ECR_VIADEE_SECRET_ACCESS_KEY }} + env: + AWS_REGION: us-east-1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: "graalvm" # See 'Supported distributions' for available options + cache: 'maven' + + - name: Maven native build + run: mvn package -Pnative native:compile + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: public.ecr.aws/m4k8r3n4/k8s-demo-app-native + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Build and push Docker images + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From 1332b7f4a1d747e095d107903bb19f0239d05ee6 Mon Sep 17 00:00:00 2001 From: "Claus U. (UsC)" <3043061+cl-a-us@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:41:01 +0000 Subject: [PATCH 11/11] Update dependencies --- pom.xml | 14 +++++--------- .../config/NativeReflectionRuntimeHintConfig.java | 4 ++-- src/main/resources/templates/fragments/footer.html | 2 +- src/main/resources/templates/fragments/header.html | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 11ba87b..28f2025 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ de.viadee.k8s.testapp k8s-demo-app - 0.2.1-SNAPSHOT + 0.2.2-SNAPSHOT jar k8s-demo-app @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 3.3.4 + 3.3.5 @@ -22,7 +22,7 @@ UTF-8 UTF-8 21 - 6.4.2.Final + @@ -55,8 +55,8 @@ org.webjars bootstrap - - 5.3.2 + + 5.3.3 @@ -66,10 +66,6 @@ org.graalvm.buildtools native-maven-plugin - - - de.viadee.k8s.testapp.K8sDemoApplication - org.springframework.boot diff --git a/src/main/java/de/viadee/k8s/testapp/config/NativeReflectionRuntimeHintConfig.java b/src/main/java/de/viadee/k8s/testapp/config/NativeReflectionRuntimeHintConfig.java index 42fa1c9..41be192 100644 --- a/src/main/java/de/viadee/k8s/testapp/config/NativeReflectionRuntimeHintConfig.java +++ b/src/main/java/de/viadee/k8s/testapp/config/NativeReflectionRuntimeHintConfig.java @@ -30,8 +30,8 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { hints.reflection().registerTypeIfPresent(classLoader, "java.util.HashMap$Node" , MemberCategory.values()); - hints.resources().registerPattern("META-INF/resources/webjars/bootstrap/5.3.2/css/bootstrap.min.css"); - hints.resources().registerPattern("META-INF/resources/webjars/bootstrap/5.3.2/js/bootstrap.min.js"); + hints.resources().registerPattern("META-INF/resources/webjars/bootstrap/5.3.3/css/bootstrap.min.css"); + hints.resources().registerPattern("META-INF/resources/webjars/bootstrap/5.3.3/js/bootstrap.min.js"); } } } diff --git a/src/main/resources/templates/fragments/footer.html b/src/main/resources/templates/fragments/footer.html index 98bd22c..1453e4e 100644 --- a/src/main/resources/templates/fragments/footer.html +++ b/src/main/resources/templates/fragments/footer.html @@ -9,7 +9,7 @@
+ src="webjars/bootstrap/5.3.3/js/bootstrap.min.js">

diff --git a/src/main/resources/templates/fragments/header.html b/src/main/resources/templates/fragments/header.html index f6b2858..f4e3d38 100644 --- a/src/main/resources/templates/fragments/header.html +++ b/src/main/resources/templates/fragments/header.html @@ -3,7 +3,7 @@
+ href="webjars/bootstrap/5.3.3/css/bootstrap.min.css" /> K8s Test App