Skip to content

Remove redundant static pages and assets from static.zip #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM container-registry.oracle.com/graalvm/native-image:24-muslib AS nativebuild
COPY . /webserver
WORKDIR /webserver
# Build a fully static native image with optimization for size
RUN ./mvnw -Dmaven.test.skip=true -Pnative,fully-static native:compile
RUN ./mvnw -Dmaven.test.skip=true -Pnative,static native:compile

# Alpine - no glibc
FROM alpine:3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM container-registry.oracle.com/graalvm/native-image:24-muslib AS nativebuild
COPY . /webserver
WORKDIR /webserver
# Build a fully static native image with optimization for size
RUN ./mvnw -Dmaven.test.skip=true -Pnative,fully-static native:compile
RUN ./mvnw -Dmaven.test.skip=true -Pnative,static native:compile

# Scratch-nothing
FROM scratch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN microdnf -y install wget xz && \
rm -rf upx-${UPX_VERSION}-amd64_linux

# Build a fully static native image with optimization for size
RUN ./mvnw -Dmaven.test.skip=true -Pnative,fully-static native:compile
RUN ./mvnw -Dmaven.test.skip=true -Pnative,static native:compile
RUN ls -lh /webserver/target
# Compress with UPX
RUN ./upx --lzma --best -o /webserver/webserver.static-upx /webserver/target/webserver.static
Expand Down
6 changes: 3 additions & 3 deletions native-image/spring-boot-webserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cd native-image/spring-boot-webserver

Unzip the static resources required for the application:
```bash
unzip src/main/resources/static.zip -d src/main/resources/static
unzip src/main/resources/static.zip -d src/main/resources
```

## **STEP 1**: Compile and Run the Application from a JAR File Inside a Container
Expand Down Expand Up @@ -92,7 +92,7 @@ Jlink, or `jlink`, is a tool that generates a custom Java runtime image that con
This is one of the approaches to make applications more space efficient and cloud-friendly, introduced in Java 11.

The script _build-jlink.sh_ that runs `docker build` using the _Dockerfile.distroless-java-base.jlink_.
The Dockerfile runs two stages: first it generates a Jlink custom runtime on a full JDK (`container-registry.oracle.com/graalvm/jdk:24`); then copies the runtime image folder along with static website pages into a Distroless Java base image, and sets the entrypoint.
The Dockerfile runs two stages: first it generates a Jlink custom runtime on a full JDK (`container-registry.oracle.com/graalvm/jdk:24`); then copies the runtime image folder along with static website pages into a distroless Java base image, and sets the entrypoint.
Distroless Java base image provides `glibc` and other libraries needed by the JDK, but not a full-blown JDK.

The application does not have to be modular, but you need to figure out which modules the application depends on to be able to `jlink` it.
Expand Down Expand Up @@ -493,7 +493,7 @@ A _scratch_ container is a [Docker official image](https://hub.docker.com/_/scra
A separate Maven profile exists for this step:
```xml
<profile>
<id>fully-static</id>
<id>static</id>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
# TOOLCHAIN_DIR=${SCRIPT_DIR}/musl-toolchain
# PATH=${TOOLCHAIN_DIR}/bin:${PATH}

# ./mvnw -Dmaven.test.skip=true -Pnative,fully-static native:compile
# ./mvnw -Dmaven.test.skip=true -Pnative,static native:compile

docker build --no-cache . -f Dockerfile.alpine.static -t webserver:scratch.static-alpine
2 changes: 1 addition & 1 deletion native-image/spring-boot-webserver/build-static-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# TOOLCHAIN_DIR=${SCRIPT_DIR}/musl-toolchain
# PATH=${TOOLCHAIN_DIR}/bin:${PATH}

# ./mvnw -Dmaven.test.skip=true -Pnative,fully-static native:compile
# ./mvnw -Dmaven.test.skip=true -Pnative,static native:compile

# Scratch-nothing
docker build --no-cache . -f Dockerfile.scratch.static -t webserver:scratch.static
2 changes: 1 addition & 1 deletion native-image/spring-boot-webserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
</profile>
<!-- Fully static image + optimized for size -->
<profile>
<id>fully-static</id>
<id>static</id>
<build>
<plugins>
<plugin>
Expand Down
Binary file not shown.