50 lines
1.6 KiB
Docker
Executable File
50 lines
1.6 KiB
Docker
Executable File
# 构建阶段 - 使用 Bun 官方镜像
|
||
FROM node:22.16.0-alpine as base
|
||
# 更改 apk 镜像源为阿里云
|
||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||
# 设置 npm 镜像源
|
||
RUN npm config set registry https://registry.npmmirror.com
|
||
# 安装 bun
|
||
RUN npm install -g bun
|
||
RUN npm install -g pnpm && pnpm config set registry https://registry.npmmirror.com
|
||
# 设置工作目录
|
||
WORKDIR /app
|
||
|
||
# 构建阶段 - 安装所有依赖并构建
|
||
FROM base as builder
|
||
WORKDIR /app
|
||
# 复制 workspace 配置文件
|
||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.json ./
|
||
# 复制所有需要的包
|
||
COPY apps/fenghuo/api ./apps/fenghuo/api
|
||
COPY apps/fenghuo/common ./apps/fenghuo/common
|
||
COPY apps/fenghuo/db ./apps/fenghuo/db
|
||
COPY shared/oidc-provider ./shared/oidc-provider
|
||
COPY shared/tus ./shared/tus/
|
||
COPY shared/typescript-config ./shared/typescript-config
|
||
COPY shared/eslint-config ./shared/eslint-config
|
||
# 安装所有依赖(包括 devDependencies)
|
||
RUN pnpm install
|
||
# 构建后端应用
|
||
RUN pnpm --filter backend build
|
||
|
||
# 运行时阶段 - 最小化的生产镜像
|
||
FROM base as runtime
|
||
|
||
# 设置工作目录
|
||
WORKDIR /app
|
||
|
||
# 从构建阶段复制构建产物
|
||
COPY --from=builder /app/apps/fenghuo/api/dist ./apps/fenghuo/api/dist
|
||
# 从构建阶段复制生成的 Prisma 客户端和 schema
|
||
COPY --from=builder /app/apps/fenghuo/db ./apps/fenghuo/db/
|
||
RUN pnpm --filter db install
|
||
RUN pnpm --filter db db:generate
|
||
# 复制入口脚本
|
||
COPY apps/fenghuo/api/entrypoint.sh ./entrypoint.sh
|
||
RUN chmod +x ./entrypoint.sh
|
||
# 暴露端口
|
||
EXPOSE 3000
|
||
|
||
# 启动应用
|
||
CMD ["./entrypoint.sh"] |