forked from feynman7355608/echo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.buildkit
67 lines (49 loc) · 2.6 KB
/
Dockerfile.buildkit
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# syntax=docker/dockerfile:1.3
ARG MAVEN_IMAGE=maven:3-adoptopenjdk-11
ARG MAVEN_RUNTIME=adoptopenjdk:11-jre-hotspot
# -----------------------------------------------------------------------------
# Build 构建,使用了 buildx 的缓存
# -----------------------------------------------------------------------------
FROM ${MAVEN_IMAGE} AS build
WORKDIR /application
COPY build/settings.xml /usr/share/maven/ref/settings-docker.xml
# copy 复制所有文件,建议有选择的只把 src 和 lib 复制进去,CI 中不会有log等文件就无所谓了
COPY . .
# build
RUN --mount=type=cache,target=/usr/share/maven/ref/repository mvn -f /application/pom.xml -s /usr/share/maven/ref/settings-docker.xml clean package -DskipTests
# -----------------------------------------------------------------------------
# spring-boot unpacker
# -----------------------------------------------------------------------------
FROM ${MAVEN_RUNTIME} as unpacker
WORKDIR application
ARG JAR_FILE=/application/target/*.jar
COPY --from=build ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract
# -----------------------------------------------------------------------------
# Runtime
# -----------------------------------------------------------------------------
FROM ${MAVEN_RUNTIME}
LABEL maintainer="Mark Zhou <zz.mark06@gmail.com>"
# 支持的环境变量:
# - NAME 应用名称
# - JAVA_OPTS jvm 参数
# - JAVA_AGENT jvm agent
WORKDIR /application
HEALTHCHECK --interval=3s --timeout=5s --start-period=120s CMD curl -f http://localhost:60002/actuator || exit 1
# 以下为单一 jar 文件运行方法
# COPY --from=build target/*.jar ./app.jar
# 以下四行为 springboot 2.3.0+ 分层打包
# https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/reference/html/spring-boot-features.html#writing-the-dockerfile
# https://docs.spring.io/spring-boot/docs/2.4.0/reference/htmlsingle/#boot-features-container-images
# https://docs.spring.io/spring-boot/docs/2.5.3/reference/htmlsingle/#features.container-images
COPY --from=unpacker application/dependencies/ ./
COPY --from=unpacker application/spring-boot-loader/ ./
COPY --from=unpacker application/snapshot-dependencies/ ./
COPY --from=unpacker application/application/ ./
# add startup.sh,为了防止换行符,后边有转换 CRLF -> LF ,因此这个文件必须最后加入,不然上边的 extract 就失去了意义
COPY build/startup-springboot.sh ./startup-springboot.sh
RUN sed -i $'s/\r$//' startup-springboot.sh
ENTRYPOINT ["sh", "startup-springboot.sh"]
# 60001 springmvc, 60002 spring-actuator
EXPOSE 60001
EXPOSE 60002