mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-27 14:52:56 +00:00
Merge pull request #387 from fastapiadmin/dev
fix(docker): 更新健康检查路径并优化构建与日志
This commit is contained in:
@@ -449,9 +449,9 @@ show_containers_logs() {
|
|||||||
log "📊 当前容器状态:" "INFO"
|
log "📊 当前容器状态:" "INFO"
|
||||||
docker compose ps --format "table {{.Service}}\t{{.Name}}\t{{.Status}}\t{{.Ports}}"
|
docker compose ps --format "table {{.Service}}\t{{.Name}}\t{{.Status}}\t{{.Ports}}"
|
||||||
|
|
||||||
log "📋 服务日志:" "INFO"
|
log "📋 服务日志(最近 50 行,实时跟踪请用 docker compose logs -f [服务名]):" "INFO"
|
||||||
echo "----------------------------------------"
|
echo "----------------------------------------"
|
||||||
docker compose logs
|
docker compose logs --tail=50 --no-log-prefix 2>/dev/null || docker compose logs --tail=50
|
||||||
echo "----------------------------------------"
|
echo "----------------------------------------"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,15 +45,12 @@ RUN groupadd -r fastapiadmin && \
|
|||||||
|
|
||||||
WORKDIR /home
|
WORKDIR /home
|
||||||
|
|
||||||
# 从构建阶段复制依赖
|
# 从构建阶段复制依赖(直接指定所有者,避免后续 chown)
|
||||||
COPY --from=builder /home/deps /home/deps
|
COPY --from=builder --chown=fastapiadmin:fastapiadmin /home/deps /home/deps
|
||||||
ENV PYTHONPATH=/home/deps:$PYTHONPATH
|
ENV PYTHONPATH=/home/deps:$PYTHONPATH
|
||||||
|
|
||||||
# 复制应用代码
|
# 复制应用代码(一步到位设置所有者,省去 chmod -R 耗时)
|
||||||
COPY ./backend/ .
|
COPY --chown=fastapiadmin:fastapiadmin ./backend/ .
|
||||||
|
|
||||||
# 更改文件所有权
|
|
||||||
RUN chown -R fastapiadmin:fastapiadmin /home
|
|
||||||
|
|
||||||
# 切换到非 root 用户
|
# 切换到非 root 用户
|
||||||
USER fastapiadmin
|
USER fastapiadmin
|
||||||
@@ -62,6 +59,6 @@ EXPOSE 8001
|
|||||||
|
|
||||||
# 容器健康检查
|
# 容器健康检查
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8001/api/v1/health')" || exit 1
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8001/common/health')" || exit 1
|
||||||
|
|
||||||
CMD ["python", "main.py", "run", "--env=prod"]
|
CMD ["python", "main.py", "run", "--env=prod"]
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ services:
|
|||||||
test:
|
test:
|
||||||
[
|
[
|
||||||
"CMD-SHELL",
|
"CMD-SHELL",
|
||||||
"python -c 'import urllib.request; urllib.request.urlopen(\"http://localhost:8001/api/v1/health\")' || exit 1",
|
"python -c 'import urllib.request; urllib.request.urlopen(\"http://localhost:8001/common/health\")' || exit 1",
|
||||||
]
|
]
|
||||||
interval: 15s
|
interval: 15s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
|
|||||||
@@ -98,8 +98,9 @@ http {
|
|||||||
|
|
||||||
# ==================== HTTPS Server ====================
|
# ==================== HTTPS Server ====================
|
||||||
server {
|
server {
|
||||||
listen 443 ssl http2;
|
listen 443 ssl;
|
||||||
listen [::]:443 ssl http2;
|
listen [::]:443 ssl;
|
||||||
|
http2 on;
|
||||||
server_name service.fastapiadmin.com;
|
server_name service.fastapiadmin.com;
|
||||||
|
|
||||||
# ==================== SSL 配置 ====================
|
# ==================== SSL 配置 ====================
|
||||||
@@ -141,6 +142,12 @@ http {
|
|||||||
add_header Cache-Control "public, no-transform";
|
add_header Cache-Control "public, no-transform";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /api/v1/common/health {
|
||||||
|
access_log off;
|
||||||
|
return 200 "OK";
|
||||||
|
add_header Content-Type text/plain;
|
||||||
|
}
|
||||||
|
|
||||||
# ==================== 后端 API 代理 ====================
|
# ==================== 后端 API 代理 ====================
|
||||||
location /api/v1 {
|
location /api/v1 {
|
||||||
# 速率限制: 每 IP 每秒最多 30 个 API 请求
|
# 速率限制: 每 IP 每秒最多 30 个 API 请求
|
||||||
|
|||||||
Reference in New Issue
Block a user