This commit is contained in:
Vaica committed 2026-06-21 23:10:12 +08:00
1 parent ef595cacbf
commit d4bbf150a5
2 files changed
+9 -19

No files matched your search

+5
View File
@@ -16,6 +16,10 @@ RUN npm ci --only=production && \
FROM node:20-alpine AS builder
WORKDIR /app
# 设置构建时环境变量(Turbopack 会内联这些值)
ENV BLOG_ROOT=/blog
ENV NODE_ENV=production
# Copy package files
COPY package.json package-lock.json ./
@@ -64,6 +68,7 @@ EXPOSE 8016
ENV NODE_ENV=production
ENV PORT=8016
ENV HOSTNAME="0.0.0.0"
ENV BLOG_ROOT=/blog
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
+4 -19
View File
@@ -1,25 +1,10 @@
import path from "path";
import os from "os";
// 获取博客根目录
// 优先级:BLOG_ROOT 环境变量 > Docker 容器检测 > 上级目录
function getBlogRoot(): string {
// 1. 环境变量(非 Docker 部署时使用)
const envRoot = process.env.BLOG_ROOT;
if (envRoot && envRoot.trim() && envRoot !== "undefined") {
return path.resolve(envRoot);
}
// 2. Docker 容器检测:cwd 为 /app 时,博客挂载在 /blog
if (process.cwd() === "/app") {
return "/blog";
}
// 3. 回退到上级目录
return path.resolve(process.cwd(), "..");
}
export const BLOG_ROOT = getBlogRoot();
// 博客根目录
// Docker 构建时 BLOG_ROOT=/blog 已被 Turbopack 内联
// 本地开发时回退到上级目录
export const BLOG_ROOT = process.env.BLOG_ROOT || path.resolve(process.cwd(), "..");
export const CONTENT_DIR = path.join(BLOG_ROOT, "content", "posts");
export const STATIC_DIR = path.join(BLOG_ROOT, "static");