Dockerfile 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # syntax=docker/dockerfile:1
  2. FROM --platform=$BUILDPLATFORM oven/bun:1.3.2-slim AS build-base
  3. WORKDIR /app
  4. FROM build-base AS deps
  5. COPY package.json bun.lock ./
  6. RUN bun install --frozen-lockfile
  7. FROM deps AS build
  8. COPY . .
  9. # 接收构建参数
  10. ARG APP_VERSION=dev
  11. # 设置为环境变量供 Next.js 使用
  12. ENV NEXT_TELEMETRY_DISABLED=1
  13. ENV NEXT_PUBLIC_APP_VERSION=$APP_VERSION
  14. RUN bun run build
  15. FROM node:22-slim AS runner
  16. ENV NODE_ENV=production
  17. ENV PORT=3000
  18. ENV HOST=0.0.0.0
  19. WORKDIR /app
  20. # 安装 PostgreSQL 18 客户端工具(用于数据库备份/恢复功能)和 curl(用于健康检查)
  21. # 需要使用官方 PostgreSQL APT 仓库以获取最新版本
  22. RUN apt-get update && \
  23. apt-get install -y gnupg curl ca-certificates && \
  24. curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql-archive-keyring.gpg && \
  25. echo "deb [signed-by=/usr/share/keyrings/postgresql-archive-keyring.gpg] http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
  26. apt-get update && \
  27. apt-get install -y postgresql-client-18 && \
  28. rm -rf /var/lib/apt/lists/*
  29. COPY --from=build --chown=node:node /app/public ./public
  30. COPY --from=build --chown=node:node /app/drizzle ./drizzle
  31. COPY --from=build --chown=node:node /app/messages ./messages
  32. COPY --from=build --chown=node:node /app/.next/standalone ./
  33. # Server Actions live inside .next/server; copy it or Next.js cannot resolve action IDs.
  34. COPY --from=build --chown=node:node /app/.next/server ./.next/server
  35. COPY --from=build --chown=node:node /app/.next/static ./.next/static
  36. USER node
  37. EXPOSE 3000
  38. CMD ["node", "server.js"]