Skip to content

Commit 2a51144

Browse files
authored
Merge pull request #61 from cl-a-us/master
Udate spring and provide spring native support with codespace
2 parents db9b0d9 + 1332b7f commit 2a51144

24 files changed

+258
-83
lines changed

.devcontainer/devcontainer.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// see https://github.com/microsoft/vscode-remote-try-java for detailed example on vscode remote java project
2+
{
3+
"name": "dev-container-with-graalvm",
4+
// java images can be found here: https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/java/about
5+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
6+
"features": {
7+
"ghcr.io/devcontainers/features/java:1": {
8+
// version is installed via sdkman
9+
// see https://sdkman.io/jdks#graalce and https://www.graalvm.org/downloads/ for version
10+
"version": "21-graalce",
11+
"installMaven": "true",
12+
"mavenVersion": "3.8.6",
13+
"installGradle": "false"
14+
}
15+
},
16+
// Configure tool-specific properties.
17+
"customizations": {
18+
// Configure properties specific to VS Code.
19+
"vscode": {
20+
"settings": {},
21+
"extensions": [
22+
"streetsidesoftware.code-spell-checker"
23+
]
24+
}
25+
}
26+
// Use 'postCreateCommand' to run commands after the container is created.
27+
, "postCreateCommand": "java -version"
28+
}
+14-26
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
name: build release and push to ECR
2-
on:
2+
on:
33
release:
44
types: [prereleased, released]
55
jobs:
66
build_and_push:
77
runs-on: ubuntu-latest
88
steps:
9-
109
- name: Checkout
11-
uses: actions/checkout@v3
10+
uses: actions/checkout@v4
1211

13-
1412
- name: Login to Public ECR
1513
uses: docker/login-action@v1
1614
with:
@@ -19,32 +17,23 @@ jobs:
1917
password: ${{ secrets.AWS_PROD_ECR_VIADEE_SECRET_ACCESS_KEY }}
2018
env:
2119
AWS_REGION: us-east-1
22-
20+
2321
- name: Set up Docker Buildx
2422
uses: docker/setup-buildx-action@v1
25-
26-
- name: Set up JDK 1.11
27-
uses: actions/setup-java@v3
28-
with:
29-
distribution: 'adopt' # See 'Supported distributions' for available options
30-
java-version: '11'
31-
32-
- name: Cache local Maven repository
33-
uses: actions/cache@v2
23+
24+
- name: Set up JDK 21
25+
uses: actions/setup-java@v4
3426
with:
35-
path: ~/.m2/repository
36-
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
37-
restore-keys: |
38-
${{ runner.os }}-maven-
27+
java-version: "21"
28+
distribution: "adopt" # See 'Supported distributions' for available options
29+
cache: 'maven'
3930

4031
- name: Maven package
41-
run: mvn package -B
32+
run: mvn -B package
4233

43-
44-
-
45-
name: Docker meta
34+
- name: Docker meta
4635
id: meta
47-
uses: docker/metadata-action@v3
36+
uses: docker/metadata-action@v5
4837
with:
4938
images: public.ecr.aws/m4k8r3n4/k8s-demo-app
5039
tags: |
@@ -54,11 +43,10 @@ jobs:
5443
type=semver,pattern={{major}}.{{minor}}
5544
5645
- name: Build and push Docker images
57-
uses: docker/build-push-action@v2.10.0
46+
uses: docker/build-push-action@v5
5847
with:
5948
context: .
6049
platforms: linux/amd64,linux/arm64
6150
push: ${{ github.event_name != 'pull_request' }}
6251
tags: ${{ steps.meta.outputs.tags }}
63-
labels: ${{ steps.meta.outputs.labels }}
64-
52+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/maven.yml

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
33

44
name: Java CI with Maven
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [master]
99
pull_request:
10-
branches: [ master ]
10+
branches: [master]
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
1615

1716
steps:
18-
- uses: actions/checkout@v3
19-
- name: Set up JDK 11
20-
uses: actions/setup-java@v3
21-
with:
22-
java-version: '11'
23-
distribution: 'adopt'
24-
cache: maven
25-
- name: Build with Maven
26-
run: mvn -B package --file pom.xml
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Set up JDK 21
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: "21"
23+
distribution: "liberica" # See 'Supported distributions' for available options
24+
cache: 'maven'
25+
26+
- name: Maven package
27+
run: mvn -B package

.github/workflows/native_build.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3+
4+
name: Java CI Native Build with Maven
5+
6+
on:
7+
push:
8+
branches: [master]
9+
pull_request:
10+
branches: [master]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Set up JDK 21
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: "21"
23+
distribution: "graalvm" # See 'Supported distributions' for available options
24+
cache: 'maven'
25+
26+
- name: Maven native build
27+
run: mvn package -Pnative native:compile
28+
- name: 'Upload Artifact'
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: native-build
32+
path: target/k8s-demo-app
33+
retention-days: 5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: build release and push to ECR
2+
on:
3+
release:
4+
types: [prereleased, released]
5+
jobs:
6+
build_and_push:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
12+
- name: Login to Public ECR
13+
uses: docker/login-action@v1
14+
with:
15+
registry: public.ecr.aws
16+
username: ${{ secrets.AWS_PROD_ECR_VIADEE_ACCESS_KEY_ID }}
17+
password: ${{ secrets.AWS_PROD_ECR_VIADEE_SECRET_ACCESS_KEY }}
18+
env:
19+
AWS_REGION: us-east-1
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v1
23+
24+
- name: Set up JDK 21
25+
uses: actions/setup-java@v4
26+
with:
27+
java-version: "21"
28+
distribution: "graalvm" # See 'Supported distributions' for available options
29+
cache: 'maven'
30+
31+
- name: Maven native build
32+
run: mvn package -Pnative native:compile
33+
34+
- name: Docker meta
35+
id: meta
36+
uses: docker/metadata-action@v5
37+
with:
38+
images: public.ecr.aws/m4k8r3n4/k8s-demo-app-native
39+
tags: |
40+
type=ref,event=branch
41+
type=ref,event=pr
42+
type=semver,pattern={{version}}
43+
type=semver,pattern={{major}}.{{minor}}
44+
45+
- name: Build and push Docker images
46+
uses: docker/build-push-action@v5
47+
with:
48+
context: .
49+
platforms: linux/amd64,linux/arm64
50+
push: ${{ github.event_name != 'pull_request' }}
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM openjdk:11-slim
1+
FROM openjdk:17-slim
22
COPY target/k8s-demo-app.jar app.jar
33
RUN groupadd -g 1000 appuser && \
44
useradd -u 1000 -g 1000 appuser

Dockerfile.Multistage

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM maven:3.6-jdk-11-slim as build_container
1+
FROM maven:3.8-openjdk-17-slim as build_container
22

33
WORKDIR /build
44
COPY pom.xml .
@@ -8,7 +8,7 @@ COPY . /usr/src/build
88
WORKDIR /usr/src/build
99
RUN mvn package -B
1010

11-
FROM openjdk:11-slim
11+
FROM openjdk:17-slim
1212
COPY --from=build_container /usr/src/build/target/k8s-demo-app.jar app.jar
1313
RUN groupadd -g 1000 appuser && \
1414
useradd -u 1000 -g 1000 appuser

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,20 @@ Or build and run with maven locally:
3131

3232
Or just do a local docker build: `docker build -t imagename .`
3333
Then you can run the container locally.
34+
35+
36+
## Native Build in github Codespaces
37+
38+
```shell
39+
mvn clean
40+
# 'package' contains step 'process-aot' which is needed for native:compile
41+
mvn package -Pnative
42+
mvn native:compile
43+
# If "[1/8] Initializing..." fails, it might be due to a lag of resources. Try increasing the VM resources.
44+
```
45+
46+
### start native build
47+
```shell
48+
./target/k8s-demo-app
49+
./target/k8s-demo-app --spring.profiles.active=red
50+
```

pom.xml

+13-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>de.viadee.k8s.testapp</groupId>
77
<artifactId>k8s-demo-app</artifactId>
8-
<version>0.2.0-SNAPSHOT</version>
8+
<version>0.2.2-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>k8s-demo-app</name>
@@ -14,14 +14,15 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.7.0</version>
17+
<version>3.3.5</version>
1818
<relativePath/> <!-- lookup parent from repository -->
1919
</parent>
2020

2121
<properties>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<java.version>11</java.version>
24+
<java.version>21</java.version>
25+
<!-- <hibernate.version>6.4.2.Final</hibernate.version> https://github.com/spring-projects/spring-boot/issues/39744 -->
2526
</properties>
2627

2728
<dependencies>
@@ -54,21 +55,24 @@
5455
<dependency>
5556
<groupId>org.webjars</groupId>
5657
<artifactId>bootstrap</artifactId>
57-
<version>5.2.3</version>
58-
</dependency>
59-
<dependency>
60-
<groupId>org.webjars</groupId>
61-
<artifactId>webjars-locator-core</artifactId>
62-
<version>0.54</version>
58+
<!-- On update replace version in htmls (needed for native )-->
59+
<version>5.3.3</version>
6360
</dependency>
6461
</dependencies>
6562

6663
<build>
6764
<finalName>${project.artifactId}</finalName>
6865
<plugins>
66+
<plugin>
67+
<groupId>org.graalvm.buildtools</groupId>
68+
<artifactId>native-maven-plugin</artifactId>
69+
</plugin>
6970
<plugin>
7071
<groupId>org.springframework.boot</groupId>
7172
<artifactId>spring-boot-maven-plugin</artifactId>
73+
<configuration>
74+
75+
</configuration>
7276
<executions>
7377
<execution>
7478
<goals>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package de.viadee.k8s.testapp.config;
2+
3+
import org.springframework.aot.hint.MemberCategory;
4+
import org.springframework.aot.hint.RuntimeHints;
5+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
6+
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.context.annotation.ImportRuntimeHints;
9+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
10+
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
14+
15+
@Configuration
16+
@RegisterReflectionForBinding(classes = {HashMap.class})
17+
@ImportRuntimeHints(NativeReflectionRuntimeHintConfig.NativeRuntimeHints.class)
18+
@EnableWebMvc
19+
public class NativeReflectionRuntimeHintConfig {
20+
21+
static class NativeRuntimeHints implements RuntimeHintsRegistrar {
22+
23+
@Override
24+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
25+
26+
// especially for rendering k8s_env.html
27+
hints.reflection().registerType(Map.Entry.class, MemberCategory.values());
28+
// hints.reflection().registerType(HashMap.class, MemberCategory.values());
29+
// Innere Klassen
30+
hints.reflection().registerTypeIfPresent(classLoader, "java.util.HashMap$Node"
31+
, MemberCategory.values());
32+
33+
hints.resources().registerPattern("META-INF/resources/webjars/bootstrap/5.3.3/css/bootstrap.min.css");
34+
hints.resources().registerPattern("META-INF/resources/webjars/bootstrap/5.3.3/js/bootstrap.min.js");
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package de.viadee.k8s.testapp.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
5+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
6+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7+
8+
9+
@Configuration
10+
@EnableWebMvc
11+
public class WebConfig implements WebMvcConfigurer {
12+
13+
@Override
14+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
15+
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
16+
}
17+
18+
}

0 commit comments

Comments
 (0)