You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
# 生产阶段
|
|
FROM oven/bun:alpine AS production
|
|
|
|
WORKDIR /app
|
|
|
|
# 安装构建依赖
|
|
RUN apk add --no-cache python3 make g++ gcc dos2unix
|
|
|
|
# 复制应用文件
|
|
COPY --chown=bun:bun ./package.json ./package.json
|
|
COPY --chown=bun:bun ./bun.lockb ./bun.lockb
|
|
COPY --chown=bun:bun ./knexfile.mjs ./knexfile.mjs
|
|
COPY --chown=bun:bun ./jsconfig.json ./jsconfig.json
|
|
COPY --chown=bun:bun ./src ./src
|
|
COPY --chown=bun:bun ./public ./public
|
|
COPY --chown=bun:bun ./entrypoint.sh ./entrypoint.sh
|
|
|
|
# 安装生产依赖和修复 entrypoint.sh
|
|
RUN bun install --frozen-lockfile --production --registry https://registry.npmjs.org && \
|
|
# 修复 entrypoint.sh 的换行符
|
|
dos2unix ./entrypoint.sh && \
|
|
chmod +x ./entrypoint.sh
|
|
|
|
# 创建必要的目录并设置权限
|
|
RUN mkdir -p ./database ./logs && \
|
|
chown -R bun:bun ./database ./logs
|
|
|
|
# 设置环境变量
|
|
ENV NODE_ENV=production
|
|
ENV BUN_ENV=production
|
|
ENV PORT=3000
|
|
|
|
# 暴露端口
|
|
EXPOSE 3000
|
|
|
|
# 切换到非root用户
|
|
USER bun
|
|
|
|
# 健康检查优化
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
CMD bun --version && \
|
|
(wget --spider -q http://localhost:3000/health || \
|
|
wget --spider -q http://localhost:3000/ || \
|
|
exit 1)
|
|
|
|
# 设置入口点
|
|
ENTRYPOINT ["./entrypoint.sh"]
|
|
|