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