22FROM alpine:3.19 AS certs
33RUN apk update && apk add --no-cache ca-certificates tzdata busybox-static
44
5+ # 脚本准备阶段
6+ FROM alpine:3.19 AS script-prep
7+ WORKDIR /prep
8+ # 复制并设置entrypoint.sh权限
9+ COPY script/entrypoint.sh ./entrypoint.sh
10+ # 规范化换行并赋予可执行权限(避免 CRLF 导致的执行失败)
11+ RUN sed -i 's/\r $//' ./entrypoint.sh && chmod +x ./entrypoint.sh
12+
513# 二进制文件准备阶段
614FROM alpine:3.19 AS binary-prep
715ARG TARGETARCH
816WORKDIR /prep
917
10- # 复制所有构建产物和脚本
18+ # 复制所有构建产物
1119COPY dist/ ./dist/
12- COPY script/entrypoint.sh ./entrypoint.sh
1320
1421# 查找并复制正确的二进制文件
1522RUN find ./dist -name "*linux*${TARGETARCH}*" -type f -executable | head -1 | xargs -I {} cp {} /prep/app || \
@@ -18,7 +25,6 @@ RUN find ./dist -name "*linux*${TARGETARCH}*" -type f -executable | head -1 | xa
1825
1926# 设置执行权限
2027RUN test -f /prep/app && chmod +x /prep/app
21- RUN chmod +x /prep/entrypoint.sh
2228
2329# 最终运行阶段
2430FROM scratch
@@ -33,17 +39,21 @@ COPY --from=certs /usr/share/zoneinfo /usr/share/zoneinfo
3339COPY --from=certs /etc/passwd /etc/passwd
3440COPY --from=certs /etc/group /etc/group
3541
36- # 复制基本的 shell 工具(用于健康检查和脚本执行)
37- COPY --from=certs /bin/busybox /bin/sh
38- COPY --from=certs /bin/busybox /bin/mkdir
39- COPY --from=certs /bin/busybox /bin/chmod
40- COPY --from=certs /bin/busybox /bin/cat
41- COPY --from=certs /bin/busybox /bin/echo
42- COPY --from=certs /bin/busybox /bin/date
43- COPY --from=certs /bin/busybox /bin/pgrep
42+ # 复制静态 busybox 到 scratch(重要:避免动态链接导致的“no such file or directory”)
43+ # 注意:busybox-static 包提供的是 /bin/busybox.static
44+ COPY --from=certs /bin/busybox.static /bin/sh
45+ COPY --from=certs /bin/busybox.static /bin/busybox
46+ COPY --from=certs /bin/busybox.static /bin/mkdir
47+ COPY --from=certs /bin/busybox.static /bin/chmod
48+ COPY --from=certs /bin/busybox.static /bin/cat
49+ COPY --from=certs /bin/busybox.static /bin/echo
50+ COPY --from=certs /bin/busybox.static /bin/date
51+ COPY --from=certs /bin/busybox.static /bin/pgrep
52+ COPY --from=certs /bin/busybox.static /bin/test
53+ COPY --from=certs /bin/busybox.static /bin/ls
4454
4555# 复制入口脚本和应用
46- COPY --from=binary -prep /prep/entrypoint.sh /entrypoint.sh
56+ COPY --from=script -prep /prep/entrypoint.sh /entrypoint.sh
4757COPY --from=binary-prep /prep/app /dashboard/app
4858
4959# 复制静态资源文件(重要:应用依赖这些文件)
0 commit comments