-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
51 lines (32 loc) · 1.1 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 基础镜像
FROM node:18-alpine3.14 AS base
ARG PNPM_VERSION=8.3.1
RUN npm install -g pnpm@$PNPM_VERSION
# 用pnpm构建依赖
FROM base AS build-stage
WORKDIR /ai-assistant
# 仅复制lock文件
COPY pnpm-lock.yaml .
# 这里这么写主要是缓存依赖,参考文档https://pnpm.io/zh/cli/fetch
RUN pnpm fetch
COPY . .
RUN pnpm i -r --offline
RUN npm run build
# 单独构建后台依赖
FROM base AS backend-modules
WORKDIR /ai-assistant/packages/backend
COPY packages/backend/package.json .
RUN pnpm i
COPY packages/backend .
# service
FROM node:18-alpine3.14 AS service
WORKDIR /ai-assistant
# COPY --from=build-stage /ai-assistant/packages/backend ./packages/backend
COPY --from=build-stage /ai-assistant/packages/frontend/dist ./packages/frontend/dist
# 这里需要用到npm下载到的node_modules
# 因为本项目是monorepo, 根项目下的node_modules巨大,而后台项目下的node_modules不全
# 因此这里单独用npm构建
COPY --from=backend-modules /ai-assistant/packages/backend ./packages/backend
EXPOSE 3000
WORKDIR /ai-assistant/packages/backend
CMD ["npm", "run", "start"]