From d4d5bd5cead1ca8eb736867a9db24a192f047509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=A8=E9=98=B3=20=E9=BE=9A?= <2302635277@qq.com> Date: Thu, 6 Aug 2026 11:56:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=20GitHub=20Actions?= =?UTF-8?q?=E3=80=81GHCR=20=E5=92=8C=20Docker=20Compose=20=E7=9A=84?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=20CI/CD=20=E8=87=AA=E5=8A=A8=E5=8C=96?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E6=B5=81=E7=A8=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-cd.yml | 3 +-- deploy/CI-CD-DESIGN.md | 2 +- Dockerfile => deploy/Dockerfile | 3 +-- deploy/deploy.sh | 35 ++++++++++++++++++++++++++++++-- design/vue/Dockerfile | 4 ---- internal/service/auth_service.go | 31 ++++++++++++++++++++++++++-- 6 files changed, 65 insertions(+), 13 deletions(-) rename Dockerfile => deploy/Dockerfile (96%) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index f27c9cf..9aea78b 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -135,7 +135,7 @@ jobs: uses: docker/build-push-action@v7 with: context: . - file: Dockerfile + file: deploy/Dockerfile platforms: linux/amd64 push: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }} tags: | @@ -266,4 +266,3 @@ jobs: done echo "生产环境外部健康检查失败" >&2 exit 1 - diff --git a/deploy/CI-CD-DESIGN.md b/deploy/CI-CD-DESIGN.md index 34f719f..6805daa 100644 --- a/deploy/CI-CD-DESIGN.md +++ b/deploy/CI-CD-DESIGN.md @@ -199,7 +199,7 @@ Compose 与脚本作业执行: ```text .github/workflows/ci-cd.yml -Dockerfile +deploy/Dockerfile .dockerignore design/vue/Dockerfile design/vue/.dockerignore diff --git a/Dockerfile b/deploy/Dockerfile similarity index 96% rename from Dockerfile rename to deploy/Dockerfile index 2477110..7d16fc8 100644 --- a/Dockerfile +++ b/deploy/Dockerfile @@ -53,8 +53,7 @@ USER app EXPOSE 8080 -HEALTHCHECK --interval=15s --timeout=5s --start-period=20s --retries=5 \ +HEALTHCHECK --interval=60s --timeout=5s --start-period=20s --retries=5 \ CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health', timeout=3)"] ENTRYPOINT ["/app/solvify-agent"] - diff --git a/deploy/deploy.sh b/deploy/deploy.sh index c3cc1b4..977f29e 100644 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -76,6 +76,37 @@ wait_for_health() { return 1 } +# 等待指定服务进入运行状态 +wait_for_running() { + local service_name="$1" + local deadline=$((SECONDS + HEALTH_TIMEOUT_SECONDS)) + local container_id + local container_status + + while (( SECONDS < deadline )); do + container_id="$(compose_command ps -q "$service_name" 2>/dev/null || true)" + if [[ -n "$container_id" ]]; then + container_status="$(docker inspect \ + --format '{{.State.Status}}' \ + "$container_id" 2>/dev/null || true)" + case "$container_status" in + running) + log "${service_name} 已进入运行状态" + return 0 + ;; + exited|dead) + log "${service_name} 状态异常:${container_status}" + return 1 + ;; + esac + fi + sleep 3 + done + + log "${service_name} 启动等待超时" + return 1 +} + # 输出有限诊断信息且不读取配置文件 print_diagnostics() { compose_command ps || true @@ -98,7 +129,7 @@ rollback() { compose_command up -d --no-deps backend || return 1 wait_for_health backend || return 1 compose_command up -d --no-deps frontend || return 1 - wait_for_health frontend || return 1 + wait_for_running frontend || return 1 log "上一版本恢复完成" } @@ -190,7 +221,7 @@ main() { log "更新前端" compose_command up -d --no-deps frontend - wait_for_health frontend + wait_for_running frontend ln -sfn "$SCRIPT_DIR" "$SOLVIFY_ROOT/current" docker image prune -f >/dev/null diff --git a/design/vue/Dockerfile b/design/vue/Dockerfile index 8089aaa..ac42a82 100644 --- a/design/vue/Dockerfile +++ b/design/vue/Dockerfile @@ -19,7 +19,3 @@ COPY nginx.conf /etc/nginx/conf.d/default.conf COPY --from=builder /app/dist /usr/share/nginx/html EXPOSE 80 - -HEALTHCHECK --interval=15s --timeout=5s --start-period=10s --retries=5 \ - CMD wget -q -O /dev/null http://127.0.0.1/health || exit 1 - diff --git a/internal/service/auth_service.go b/internal/service/auth_service.go index 4df0ad4..40d32c3 100644 --- a/internal/service/auth_service.go +++ b/internal/service/auth_service.go @@ -223,8 +223,35 @@ func (s *authService) SendEmailCode(emailStr string) error { } // 3. 调用邮件组件把验证码发送给目标邮箱 - subject := "Ryne 博客验证码" - body := fmt.Sprintf("
有效期 5 分钟,请勿泄露给他人。
", code) + subject := "Solvify 邮箱验证码" + body := fmt.Sprintf(` +| + + | +