-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
69 lines (53 loc) · 1.92 KB
/
Dockerfile
File metadata and controls
69 lines (53 loc) · 1.92 KB
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
68
69
####
# Multi-stage Dockerfile for building Quarkus application with GraalVM
# This builds the JAR inside Docker container and creates a runtime image
# Uses mount caches for faster builds
####
# Build stage - 使用GraalVM进行构建
FROM ghcr.io/graalvm/graalvm-community:21 AS builder
# 安装Maven
RUN microdnf install -y wget tar gzip && \
microdnf clean all
# 下载并安装Maven(使用缓存加速)
RUN --mount=type=cache,target=/tmp/maven-cache \
if [ ! -f /tmp/maven-cache/apache-maven-3.9.6-bin.tar.gz ]; then \
wget -q https://archive.apache.org/dist/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz -O /tmp/maven-cache/apache-maven-3.9.6-bin.tar.gz; \
fi && \
tar -xzf /tmp/maven-cache/apache-maven-3.9.6-bin.tar.gz -C /opt && \
ln -s /opt/apache-maven-3.9.6/bin/mvn /usr/local/bin/mvn
# 设置工作目录
WORKDIR /app
# 复制Maven配置文件
COPY pom.xml .
COPY mvnw .
COPY mvnw.cmd .
COPY .mvn .mvn
# 下载依赖(利用Docker缓存和Maven本地仓库缓存)
RUN --mount=type=cache,target=/root/.m2 \
mvn dependency:go-offline -B
# 复制源代码
COPY src ./src
# 构建应用(使用Maven缓存)
RUN --mount=type=cache,target=/root/.m2 \
mvn clean package -DskipTests
# Runtime stage - 使用GraalVM运行时
FROM ghcr.io/graalvm/graalvm-community:21
# 安装语言运行时
RUN microdnf install -y python3 python3-pip curl && \
microdnf clean all && \
rm -rf /var/cache/yum
# 设置工作目录
WORKDIR /app
# 复制构建好的JAR文件
COPY --from=builder /app/target/quarkus-app/ ./
# 创建非root用户
RUN groupadd -r appuser && useradd -r -g appuser -m appuser && \
chown -R appuser:appuser /app
USER appuser
# 暴露端口
EXPOSE 8080
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8080/api/script/health || exit 1
# 启动应用
ENTRYPOINT ["java", "-jar", "quarkus-run.jar"]