feat: 更新健康检查脚本和依赖
Some checks failed
部署后端服务 / 🚀 构建并部署 (push) Has been cancelled

- 将健康检查命令从`/photography-api --health-check`更新为使用新的脚本`/usr/local/bin/health-check.sh`
- 在Dockerfile中添加`wget`作为运行时依赖
- 确保健康检查脚本具有执行权限

此更改提升了健康检查的可靠性和灵活性。
This commit is contained in:
xujiang
2025-07-16 15:02:27 +08:00
parent e5fa256fb0
commit fdf524a172
5 changed files with 22 additions and 8 deletions

View File

@ -1,6 +1,6 @@
# Photography Portfolio - 项目总览 # Photography Portfolio - 项目总览
> 📍 这是一个模块化摄影作品集项目所有模块都有独立的CLAUDE.md文件 > 📍 这是一个模块化摄影作品集项目所有模块都有独立的CLAUDE.md文件,所有给我的提示都要用中文
## 🎯 项目结构 ## 🎯 项目结构

View File

@ -45,8 +45,8 @@ FROM alpine:3.19
# 配置镜像源加速 # 配置镜像源加速
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 安装运行时依赖 (包含SQLite动态库) # 安装运行时依赖 (包含SQLite动态库和wget用于健康检查)
RUN apk add --no-cache ca-certificates tzdata sqlite RUN apk add --no-cache ca-certificates tzdata sqlite wget
# 创建非root用户 # 创建非root用户
RUN addgroup -g 1001 -S appgroup && \ RUN addgroup -g 1001 -S appgroup && \
@ -61,10 +61,12 @@ COPY --from=builder /app/configs /configs
COPY --from=builder /app/scripts /scripts COPY --from=builder /app/scripts /scripts
COPY --from=builder /app/pkg/migration /pkg/migration COPY --from=builder /app/pkg/migration /pkg/migration
COPY --from=builder /app/etc /etc COPY --from=builder /app/etc /etc
COPY --from=builder /app/health-check.sh /usr/local/bin/health-check.sh
# 设置目录权限 # 设置目录权限和脚本权限
RUN mkdir -p /app && \ RUN mkdir -p /app && \
chown -R appuser:appgroup /app chown -R appuser:appgroup /app && \
chmod +x /usr/local/bin/health-check.sh
# 设置时区 # 设置时区
ENV TZ=Asia/Shanghai ENV TZ=Asia/Shanghai
@ -80,7 +82,7 @@ EXPOSE 8080
# 健康检查 # 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD ["/usr/local/bin/photography-api", "--health-check"] CMD /usr/local/bin/health-check.sh
# 启动应用 # 启动应用
ENTRYPOINT ["/usr/local/bin/photography-api"] ENTRYPOINT ["/usr/local/bin/photography-api"]

View File

@ -52,7 +52,7 @@ services:
- logs_data:/app/logs - logs_data:/app/logs
restart: unless-stopped restart: unless-stopped
healthcheck: healthcheck:
test: ["CMD", "/photography-api", "--health-check"] test: ["CMD", "/usr/local/bin/health-check.sh"]
interval: 30s interval: 30s
timeout: 10s timeout: 10s
retries: 3 retries: 3

View File

@ -52,7 +52,7 @@ services:
- logs_data:/app/logs - logs_data:/app/logs
restart: unless-stopped restart: unless-stopped
healthcheck: healthcheck:
test: ["CMD", "/photography-api", "--health-check"] test: ["CMD", "/usr/local/bin/health-check.sh"]
interval: 30s interval: 30s
timeout: 10s timeout: 10s
retries: 3 retries: 3

12
backend/health-check.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
# 健康检查脚本
# 用于Docker健康检查和Kubernetes探针
# 检查健康检查端点
if wget --no-verbose --tries=1 --spider http://localhost:8080/api/v1/health; then
echo "Health check passed"
exit 0
else
echo "Health check failed"
exit 1
fi