chore: refactor dockerfile for prisma migration and build optimization

Refactor the Dockerfile to separate dependency installation and type
generation from the runtime environment.

Changes:
- Moved `bun prisma generate` to the build phase to ensure type definitions
  are created during image build rather than at runtime.
- Updated the ENTRYPOINT to run `bun prisma migrate deploy` before starting
  the application. This ensures database migrations are applied automatically
  upon container startup, supporting production deployments with incremental
  schema changes.
- Added missing newline at the end of the file for compliance.

This change ensures that the application handles schema updates safely in
production without requiring a separate migration step outside the container.
This commit is contained in:
kyuuseiryuu 2026-03-18 01:39:54 +09:00
parent 1793c10b45
commit 845a50253b

View File

@ -1,6 +1,15 @@
FROM oven/bun:latest FROM oven/bun:latest
COPY . /app
WORKDIR /app WORKDIR /app
RUN bun install && bun prisma db push && bun prisma generate COPY . .
ENTRYPOINT [ "bun", "start"]
# 1. 安装依赖并生成 Prisma Client (构建阶段只需生成类型)
RUN bun install
RUN bun prisma generate
# 暴露端口
EXPOSE 3000 EXPOSE 3000
# 2. 使用脚本或直接在启动时执行迁移
# 这样每次容器启动前都会检查并应用增量更新
ENTRYPOINT [ "sh", "-c", "bun prisma migrate deploy && bun start" ]