/
Dockerfile
30 lines (29 loc) · 890 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
FROM alpine:latest as builder
# Install JDK
RUN apk add --no-cache openjdk17-jdk
# Set up project
WORKDIR /application
# Set up gradle
COPY gradlew .
COPY gradle gradle
RUN chmod +x gradlew
RUN ./gradlew --version
# Copy source
COPY *.gradle.kts .
COPY gradle.lockfile .
COPY .git .git
COPY src src
# Build and extract layered jar
RUN ./gradlew --no-daemon bootJar && java -Djarmode=layertools -jar build/libs/*.jar extract
FROM alpine:latest
EXPOSE 8080
ENV server.port 8080
RUN apk add --no-cache openjdk17-jre-headless
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
WORKDIR /application
COPY --from=builder /application/dependencies .
COPY --from=builder /application/spring-boot-loader .
COPY --from=builder /application/snapshot-dependencies .
COPY --from=builder /application/application .
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]