diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..460d583 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +node_modules +.output +.git +.gitignore +.DS_Store +*.log +.env.local +.env.*.local +README.md +.vscode +.swc diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..68fa6b4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# Stage 1: 使用 bun 安装依赖和构建 +FROM oven/bun:1 AS builder + +WORKDIR /app + +# 复制依赖文件 +COPY package.json bun.lock* bun.lockb* ./ + +# 使用 bun 安装依赖 +RUN bun install --frozen-lockfile + +# 复制源代码 +COPY . . + +# 构建应用 +RUN bun run build + +# Stage 2: 使用 Node.js 运行 +FROM node:22-slim AS runner + +WORKDIR /app + +# 从 builder 阶段复制构建产物 +COPY --from=builder /app/.output ./.output +COPY --from=builder /app/package.json ./ + +# 设置环境变量 +ENV NODE_ENV=production +ENV HOST=0.0.0.0 +ENV PORT=3000 + +EXPOSE 3000 + +# 使用 Node.js 运行 Nitro 服务 +CMD ["node", ".output/server/index.mjs"] diff --git a/server/plugins/setup.ts b/server/plugins/setup.ts index bae2d52..7546097 100644 --- a/server/plugins/setup.ts +++ b/server/plugins/setup.ts @@ -27,7 +27,7 @@ async function runMigrations() { console.log("✅ Database migrations completed!"); } catch (error) { console.error("❌ Failed to run migrations:", error); - process.exit(0); + process.exit(1); } finally { await pgClient.end(); }