Skip to content

Commit ec91438

Browse files
committed
Update.
1 parent 9784322 commit ec91438

File tree

7 files changed

+444
-43
lines changed

7 files changed

+444
-43
lines changed

.github/workflows/release.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ jobs:
112112
chmod -R +x ./assets/*
113113
mkdir dist
114114
mv ./assets/*/*/* ./dist
115+
116+
- name: Verify build context
117+
run: |
118+
echo "=== Build context verification ==="
119+
echo "Current directory contents:"
120+
ls -la
121+
echo "Script directory contents:"
122+
ls -la script/
123+
echo "Dist directory contents:"
124+
ls -la dist/
125+
echo "Entrypoint script:"
126+
ls -la script/entrypoint.sh
127+
echo "Dockerfile:"
128+
head -20 Dockerfile
115129
116130
- name: Extract branch name
117131
run: |

Dockerfile

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22
FROM alpine:3.19 AS certs
33
RUN 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
# 二进制文件准备阶段
614
FROM alpine:3.19 AS binary-prep
715
ARG TARGETARCH
816
WORKDIR /prep
917

10-
# 复制所有构建产物和脚本
18+
# 复制所有构建产物
1119
COPY dist/ ./dist/
12-
COPY script/entrypoint.sh ./entrypoint.sh
1320

1421
# 查找并复制正确的二进制文件
1522
RUN 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
# 设置执行权限
2027
RUN test -f /prep/app && chmod +x /prep/app
21-
RUN chmod +x /prep/entrypoint.sh
2228

2329
# 最终运行阶段
2430
FROM scratch
@@ -33,17 +39,21 @@ COPY --from=certs /usr/share/zoneinfo /usr/share/zoneinfo
3339
COPY --from=certs /etc/passwd /etc/passwd
3440
COPY --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
4757
COPY --from=binary-prep /prep/app /dashboard/app
4858

4959
# 复制静态资源文件(重要:应用依赖这些文件)

Dockerfile.debug

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# 调试版本的 Dockerfile
2+
# 用于诊断 entrypoint.sh 文件问题
3+
4+
# 多阶段构建 - 证书和工具阶段
5+
FROM alpine:3.19 AS certs
6+
RUN apk update && apk add --no-cache ca-certificates tzdata busybox-static
7+
8+
# 二进制文件准备阶段
9+
FROM alpine:3.19 AS binary-prep
10+
ARG TARGETARCH
11+
WORKDIR /prep
12+
13+
# 复制所有构建产物和脚本
14+
COPY dist/ ./dist/
15+
COPY script/entrypoint.sh ./entrypoint.sh
16+
17+
# 调试:列出复制的文件
18+
RUN echo "=== 调试信息 ===" && \
19+
echo "当前目录内容:" && \
20+
ls -la && \
21+
echo "dist目录内容:" && \
22+
ls -la ./dist/ && \
23+
echo "entrypoint.sh文件信息:" && \
24+
ls -la ./entrypoint.sh && \
25+
echo "entrypoint.sh内容:" && \
26+
cat ./entrypoint.sh
27+
28+
# 查找并复制正确的二进制文件
29+
RUN find ./dist -name "*linux*${TARGETARCH}*" -type f -executable | head -1 | xargs -I {} cp {} /prep/app || \
30+
find ./dist -name "*${TARGETARCH}*" -type f -executable | head -1 | xargs -I {} cp {} /prep/app || \
31+
find ./dist -name "server-dash*" -type f -executable | head -1 | xargs -I {} cp {} /prep/app
32+
33+
# 设置执行权限
34+
RUN test -f /prep/app && chmod +x /prep/app
35+
RUN chmod +x /prep/entrypoint.sh
36+
37+
# 调试:验证文件
38+
RUN echo "=== 准备阶段完成 ===" && \
39+
echo "准备的文件:" && \
40+
ls -la /prep/ && \
41+
echo "app文件信息:" && \
42+
file /prep/app && \
43+
echo "entrypoint.sh权限:" && \
44+
ls -la /prep/entrypoint.sh
45+
46+
# 最终运行阶段 - 使用 Alpine 而不是 scratch 进行调试
47+
FROM alpine:3.19
48+
49+
ARG TARGETOS
50+
ARG TARGETARCH
51+
ARG TZ=Asia/Shanghai
52+
53+
# 安装基本工具用于调试
54+
RUN apk add --no-cache ca-certificates tzdata busybox
55+
56+
# 从证书阶段复制必要文件
57+
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
58+
COPY --from=certs /usr/share/zoneinfo /usr/share/zoneinfo
59+
60+
# 复制入口脚本和应用
61+
COPY --from=binary-prep /prep/entrypoint.sh /entrypoint.sh
62+
COPY --from=binary-prep /prep/app /dashboard/app
63+
64+
# 复制静态资源文件
65+
COPY resource/ /dashboard/resource/
66+
67+
# 调试:验证最终镜像中的文件
68+
RUN echo "=== 最终镜像调试信息 ===" && \
69+
echo "根目录内容:" && \
70+
ls -la / && \
71+
echo "entrypoint.sh文件信息:" && \
72+
ls -la /entrypoint.sh && \
73+
echo "dashboard目录内容:" && \
74+
ls -la /dashboard/ && \
75+
echo "app文件信息:" && \
76+
ls -la /dashboard/app && \
77+
file /dashboard/app
78+
79+
# 设置工作目录和环境变量
80+
WORKDIR /dashboard
81+
ENV TZ=$TZ
82+
ENV GIN_MODE=release
83+
84+
# 创建数据目录
85+
RUN mkdir -p /dashboard/data
86+
87+
# 暴露端口
88+
EXPOSE 80 2222
89+
90+
# 健康检查
91+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
92+
CMD ["/dashboard/app", "--health-check"] || exit 1
93+
94+
# 使用入口脚本启动
95+
ENTRYPOINT ["/entrypoint.sh"]

Dockerfile.minimal

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# 最小化 Dockerfile - 使用 distroless 而不是 scratch
2+
# 这样可以避免 entrypoint.sh 找不到的问题
3+
4+
# 多阶段构建 - 证书和工具阶段
5+
FROM alpine:3.19 AS certs
6+
RUN apk update && apk add --no-cache ca-certificates tzdata
7+
8+
# 二进制文件准备阶段
9+
FROM alpine:3.19 AS binary-prep
10+
ARG TARGETARCH
11+
WORKDIR /prep
12+
13+
# 复制构建产物
14+
COPY dist/ ./dist/
15+
16+
# 查找并复制正确的二进制文件
17+
RUN find ./dist -name "*linux*${TARGETARCH}*" -type f -executable | head -1 | xargs -I {} cp {} /prep/app || \
18+
find ./dist -name "*${TARGETARCH}*" -type f -executable | head -1 | xargs -I {} cp {} /prep/app || \
19+
find ./dist -name "server-dash*" -type f -executable | head -1 | xargs -I {} cp {} /prep/app
20+
21+
# 设置执行权限
22+
RUN chmod +x /prep/app
23+
24+
# 最终运行阶段 - 使用 distroless 基础镜像
25+
FROM gcr.io/distroless/static-debian12:latest
26+
27+
ARG TZ=Asia/Shanghai
28+
29+
# 从证书阶段复制必要文件
30+
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
31+
COPY --from=certs /usr/share/zoneinfo /usr/share/zoneinfo
32+
33+
# 复制应用和静态资源
34+
COPY --from=binary-prep /prep/app /dashboard/app
35+
COPY resource/ /dashboard/resource/
36+
37+
# 设置工作目录和环境变量
38+
WORKDIR /dashboard
39+
ENV TZ=$TZ
40+
ENV GIN_MODE=release
41+
42+
# 暴露端口
43+
EXPOSE 80 2222
44+
45+
# 健康检查
46+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
47+
CMD ["/dashboard/app", "--health-check"] || exit 1
48+
49+
# 直接启动应用,不使用 entrypoint.sh
50+
ENTRYPOINT ["/dashboard/app"]

script/entrypoint-simple.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
3+
# 简化版 entrypoint.sh
4+
# 减少外部依赖,专注于核心功能
5+
6+
# 健康检查模式
7+
if [ "$1" = "--health-check" ]; then
8+
# 简单的进程检查
9+
if [ -f "/proc/1/comm" ]; then
10+
exit 0
11+
else
12+
exit 1
13+
fi
14+
fi
15+
16+
# 创建数据目录(如果不存在)
17+
if [ ! -d "/dashboard/data" ]; then
18+
mkdir -p /dashboard/data
19+
fi
20+
21+
# 检查配置文件,如果不存在则创建基本配置
22+
if [ ! -f "/dashboard/data/config.yaml" ]; then
23+
cat > /dashboard/data/config.yaml << 'EOF'
24+
debug: false
25+
language: zh-CN
26+
httpport: 80
27+
grpcport: 2222
28+
database:
29+
type: sqlite
30+
dsn: data/sqlite.db
31+
jwt_secret: "default-secret-change-me"
32+
admin:
33+
username: admin
34+
password: admin123
35+
site:
36+
brand: "ServerStatus"
37+
theme: "default"
38+
EOF
39+
fi
40+
41+
# 启动应用
42+
exec /dashboard/app "$@"

script/entrypoint.sh

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
11
#!/bin/sh
22

3-
# 设置错误处理
4-
set -e
5-
6-
# 日志函数
7-
log() {
8-
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
9-
}
3+
# ServerStatus Dashboard 入口脚本
4+
# 兼容 scratch 镜像环境
105

116
# 健康检查模式
127
if [ "$1" = "--health-check" ]; then
13-
# 检查应用是否响应
14-
if command -v wget >/dev/null 2>&1; then
15-
wget --quiet --tries=1 --timeout=5 --spider http://localhost:80/api/v1/service/status || exit 1
16-
elif command -v curl >/dev/null 2>&1; then
17-
curl -f -s --max-time 5 http://localhost:80/api/v1/service/status >/dev/null || exit 1
8+
# 检查进程是否存在
9+
if [ -f "/proc/1/comm" ]; then
10+
exit 0
1811
else
19-
# 如果没有 wget 或 curl,检查进程是否存在
20-
pgrep -f "/dashboard/app" >/dev/null || exit 1
12+
exit 1
2113
fi
22-
exit 0
2314
fi
2415

25-
log "Starting ServerStatus Dashboard..."
16+
# 简单日志函数(不依赖 date 命令)
17+
log() {
18+
echo "[ENTRYPOINT] $1"
19+
}
2620

27-
# 配置 DNS(如果 /etc/resolv.conf 存在且可写)
28-
if [ -w /etc/resolv.conf ] 2>/dev/null; then
29-
log "Configuring DNS servers..."
30-
{
31-
echo "nameserver 127.0.0.11"
32-
echo "nameserver 8.8.4.4"
33-
echo "nameserver 223.5.5.5"
34-
echo "nameserver 1.1.1.1"
35-
} > /etc/resolv.conf
36-
fi
21+
log "Starting ServerStatus Dashboard..."
3722

3823
# 检查数据目录
3924
if [ ! -d "/dashboard/data" ]; then
@@ -43,7 +28,7 @@ fi
4328

4429
# 检查配置文件
4530
if [ ! -f "/dashboard/data/config.yaml" ]; then
46-
log "No config.yaml found, creating default configuration..."
31+
log "Creating default configuration..."
4732
cat > /dashboard/data/config.yaml << 'EOF'
4833
# ServerStatus Dashboard 配置文件
4934
debug: false
@@ -58,7 +43,7 @@ database:
5843
dsn: data/sqlite.db
5944
6045
# JWT 密钥 (请修改为随机字符串)
61-
jwt_secret: "your-secret-key-here"
46+
jwt_secret: "default-secret-please-change"
6247
6348
# 管理员账户 (首次启动后请立即修改)
6449
admin:
@@ -102,11 +87,16 @@ tgchatid: ""
10287
wxpushertoken: ""
10388
wxpusheruids: []
10489
EOF
105-
log "Default configuration created at /dashboard/data/config.yaml"
106-
log "Please review and modify the configuration as needed"
90+
log "Default configuration created"
91+
log "Please modify admin password after first login"
92+
fi
93+
94+
# 检查应用文件
95+
if [ ! -f "/dashboard/app" ]; then
96+
log "ERROR: Application binary not found at /dashboard/app"
97+
exit 1
10798
fi
10899

109-
# 检查应用文件权限
110100
if [ ! -x "/dashboard/app" ]; then
111101
log "Setting executable permissions for app..."
112102
chmod +x /dashboard/app

0 commit comments

Comments
 (0)