Skip to content

Commit dde616a

Browse files
committed
feat: reduce image size with alpine and amazon corretto jdk
1 parent 6c3f141 commit dde616a

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

Dockerfile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
FROM eclipse-temurin:17-jdk-focal
1+
FROM amazoncorretto:17-alpine as corretto-jdk
2+
3+
# required for strip-debug to work
4+
RUN apk add --no-cache binutils
5+
6+
# Build small JRE image
7+
RUN jlink \
8+
--add-modules ALL-MODULE-PATH \
9+
--strip-debug \
10+
--no-man-pages \
11+
--no-header-files \
12+
--compress=2 \
13+
--output /jre
14+
15+
FROM alpine:latest
16+
ENV JAVA_HOME=/jre
17+
ENV PATH="${JAVA_HOME}/bin:${PATH}"
18+
19+
COPY --from=corretto-jdk /jre $JAVA_HOME
220

321
ARG JAR_FILE
422
ARG SPRING_BOOT_VERSION
@@ -7,8 +25,8 @@ LABEL org.opencontainers.image.authors="Oliver Sahner <[email protected]>"
725
LABEL org.springframework.boot="${SPRING_BOOT_VERSION}"
826

927
RUN mkdir /opt/app
10-
RUN addgroup --system --gid 1001 spring
11-
RUN adduser --system --no-create-home --uid 1001 --gid 1001 spring
28+
RUN addgroup -g 1001 -S spring
29+
RUN adduser -u 1001 -S spring -G spring
1230
RUN chown spring:spring /opt/app
1331
USER spring
1432

contributed/buildDocker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ if [[ $p -eq 1 ]]; then
3333
PLATFORM="linux/amd64"
3434
fi
3535
echo -e " ${color_light_cyan}+ for platform ${PLATFORM}${color_restore}"
36-
docker build --build-arg JAR_FILE="${JAR_FILE}" --build-arg SPRING_BOOT_VERSION="${SPRING_BOOT_VERSION}" \
36+
DOCKER_BUILDKIT=1 docker build --build-arg JAR_FILE="${JAR_FILE}" --build-arg SPRING_BOOT_VERSION="${SPRING_BOOT_VERSION}" \
3737
--platform=${PLATFORM} --no-cache --pull --rm -f Dockerfile -t "${GROUPID}/${ARTIFACTID}:${VERSION}" .

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.0.2</version>
8+
<version>3.0.4</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111

1212
<groupId>osahner</groupId>
1313
<artifactId>kotlin-spring-boot-rest-jpa-jwt-starter</artifactId>
14-
<version>0.9.1-SNAPSHOT</version>
14+
<version>0.9.2-SNAPSHOT</version>
1515
<packaging>jar</packaging>
1616

1717
<name>kotlin spring-boot 2 rest/jpa/jwt starter</name>
@@ -22,7 +22,7 @@
2222
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2323

2424
<java.version>17</java.version>
25-
<kotlin.version>1.8.0</kotlin.version>
25+
<kotlin.version>1.8.10</kotlin.version>
2626

2727
<dockerfile-maven.version>1.4.13</dockerfile-maven.version>
2828
<jacoco-maven-plugin.version>0.8.7</jacoco-maven-plugin.version>

0 commit comments

Comments
 (0)