fix(deploy): 端到端跑通编译二进制 + docker compose
端到端验证时发现 4 处细节,一起补上:
1. bin.ts 漏了 default: 'serve'——CMD ["./server"] 会直接吐 help 而
不是起服务(在 compose 里 app 立刻 exit)。citty 原生支持 default
2. Dockerfile 在 bun install 之前就要 COPY patches/,否则 package.json
的 patchedDependencies 找不到补丁文件,install 失败
3. drizzle/ 目录在仓库里必须存在(带 .gitkeep),否则 Dockerfile 末尾
COPY drizzle/ 到运行镜像会失败
4. migrate.ts 之前只检查 ./drizzle 目录是否存在就跳过——空目录时仍会
进到 drizzle 的 readMigrationFiles,报 Can't find meta/_journal.json。
改成检查 meta/_journal.json 是否存在,更准确地区分"还没生成过迁移"
与"有迁移待应用"
验证路径:
- docker compose up -d --build → migrate 完成退出 → app 健康
- curl /api/spec.json → 200,OpenAPI 文档含 todo.{list,create,update,remove}
This commit is contained in:
@@ -3,6 +3,7 @@ FROM oven/bun:1.3.13 AS build
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY package.json bun.lock ./
|
COPY package.json bun.lock ./
|
||||||
|
COPY patches ./patches
|
||||||
RUN bun install --frozen-lockfile
|
RUN bun install --frozen-lockfile
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const main = defineCommand({
|
|||||||
version,
|
version,
|
||||||
description: 'Fullstack server binary (default subcommand: serve)',
|
description: 'Fullstack server binary (default subcommand: serve)',
|
||||||
},
|
},
|
||||||
|
default: 'serve',
|
||||||
subCommands: {
|
subCommands: {
|
||||||
serve: () => import('./src/cli/serve').then((m) => m.default),
|
serve: () => import('./src/cli/serve').then((m) => m.default),
|
||||||
migrate: () => import('./src/cli/migrate').then((m) => m.default),
|
migrate: () => import('./src/cli/migrate').then((m) => m.default),
|
||||||
|
|||||||
+3
-2
@@ -2,6 +2,7 @@ import { existsSync } from 'node:fs'
|
|||||||
import { defineCommand } from 'citty'
|
import { defineCommand } from 'citty'
|
||||||
|
|
||||||
const MIGRATIONS_FOLDER = './drizzle'
|
const MIGRATIONS_FOLDER = './drizzle'
|
||||||
|
const JOURNAL = `${MIGRATIONS_FOLDER}/meta/_journal.json`
|
||||||
|
|
||||||
export default defineCommand({
|
export default defineCommand({
|
||||||
meta: {
|
meta: {
|
||||||
@@ -9,8 +10,8 @@ export default defineCommand({
|
|||||||
description: 'Apply pending database migrations from ./drizzle',
|
description: 'Apply pending database migrations from ./drizzle',
|
||||||
},
|
},
|
||||||
async run() {
|
async run() {
|
||||||
if (!existsSync(MIGRATIONS_FOLDER)) {
|
if (!existsSync(JOURNAL)) {
|
||||||
console.log(`No ${MIGRATIONS_FOLDER} directory; nothing to apply (use db:push in dev).`)
|
console.log(`No migrations found at ${MIGRATIONS_FOLDER} (run \`bun run db:generate\` to create some).`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user