Skip to content

Spring Boot 4.0.9 + GraalVM native image on GHCR - #1

Merged
tschuehly merged 3 commits into
masterfrom
boot4-native
Nov 8, 2026
Merged

tschuehly merged 3 commits into
masterfrom
boot4-native

Conversation

@tschuehly

Copy link
Copy Markdown
Owner

Upgrades the demo from Spring Boot 3.2.2 to 4.0.9 and ships it as a GraalVM native image.

Upgrade

  • Boot 4.0.9, Kotlin 2.2.21, Gradle 9.1.0, toolchain JDK 25 (bytecode target 17; Kotlin 2.2 cannot emit 25)
  • Starters web → webmvc, aop → aspectj; tools.jackson.module:jackson-module-kotlin (Jackson 3)
  • Dropped unused thymeleaf-extras-java8time / -springsecurity6
  • spring-view-component 0.7.2 → 0.9.1 (Boot 4 line). @PutViewAction is gone, so the never-rendered PersonActionViewComponent was removed; no page referenced it
  • Fixed toast template (toastContext → toastCtx); the save toast returned 500 before

Native

  • Dockerfile: ghcr.io/graalvm/native-image-community:25 runs nativeCompile, runtime gcr.io/distroless/base-debian12:nonroot (mostly-static binary)
  • common/NativeHints.kt: resource hint for co-located templates, binding hints for all ViewContext classes + PersonFormDTO
  • AdvancedTableViewComponent.html: tableRow.get(0) → tableRow[0] (no reflection on Arrays$ArrayList)

CI .github/workflows/native-image.yml: builds on PRs (no push); on push to master/main pushes ghcr.io/tschuehly/fullstack-with-spring:<sha> and :latest.

Verified locally (arm64 native container): /, /tables, /forms, /tabbed, /component/person/table, /component/person/modal/1, /lineChartComponent, PUT /api/person, webjars, static CSS, /actuator/health all 200; startup 0.21 s; ~108 MiB container memory after ~95 requests.

No DB and no env vars needed (all data in-memory). Not deployed.

- Boot 3.2.2 -> 4.0.9, Kotlin 2.2.21, Gradle 9.1.0, JDK/GraalVM 25 (bytecode 17)
- starters: web -> webmvc, aop -> aspectj; Jackson 3 kotlin module; drop unused thymeleaf extras
- spring-view-component 0.7.2 -> 0.9.1; remove unreferenced PersonActionViewComponent (@PutViewAction no longer exists)
- fix toast template variable (toastContext -> toastCtx)
- native: Dockerfile (GraalVM 25 nativeCompile -> distroless), runtime hints for templates and ViewContext binding
- GitHub Actions: build on PRs, push ghcr.io/<repo>:<sha> and :latest on master/main
Copilot AI balanced review requested due to automatic review settings November 8, 2026 01:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Manual workflow runs on feature branches can publish images as :latest, so publication must also be restricted to master/main to prevent overwriting the default-branch image.

1 open issue
What changed in this PR

Upgrades the Spring demo to Spring Boot 4 and adds GraalVM native container builds with GitHub Container Registry publication.

Changes:

  • Updates Spring Boot, Kotlin, Gradle, and the JDK toolchain, with compatible dependencies.
  • Adds native-image configuration and reflection/resource hints, fixes template expressions, and removes the unused person action component.
  • Adds a multi-stage Docker build and CI for building and publishing native images.
File Description
src/​main/​kotlin/​de/​tschuehly/​fullstackdemo/​web/​page/​layout/​LayoutViewComponent.kt Removes an unused import.
src/​main/​kotlin/​de/​tschuehly/​fullstackdemo/​web/​component/​util/​toast/​ToastViewComponent.html Corrects toast context references.
src/​main/​kotlin/​de/​tschuehly/​fullstackdemo/​web/​component/​util/​advancedTable/​AdvancedTableViewComponent.html Uses native-compatible list indexing.
src/​main/​kotlin/​de/​tschuehly/​fullstackdemo/​web/​component/​person/​action/​PersonActionViewComponent.kt Removes the unused legacy action component.
src/​main/​kotlin/​de/​tschuehly/​fullstackdemo/​web/​component/​person/​action/​PersonActionViewComponent.html Removes its unused template.
src/​main/​kotlin/​de/​tschuehly/​fullstackdemo/​common/​NativeHints.kt Registers native template resources and reflection hints.
gradlew.bat Refreshes the Windows Gradle launcher.
gradlew Refreshes the Unix Gradle launcher.
gradle/​wrapper/​gradle-wrapper.properties Selects Gradle 9.1.0.
Dockerfile Builds a native executable and packages it in a nonroot runtime.
build.gradle.kts Updates dependencies and toolchain; configures native compilation.
.github/​workflows/​native-image.yml Adds native container builds and registry publication.
.dockerignore Excludes local artifacts and slides from the build context.

Review effort: Balanced

Comment thread .github/workflows/native-image.yml Outdated
with:
context: .
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
…ges:write job

- image label service=<kamal service> (Kamal deploy --skip-push checks it); CI asserts it
- push trigger and publish guard: master only (default branch), so no other branch overwrites :latest
- build/test job is read-only (contents: read, no persisted checkout token); publish job gets
  packages:write, runs only on push to master, loads the built image artifact and runs no repo code
@tschuehly
tschuehly merged commit c74996f into master Nov 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants