Skip to content

Commit d72984b

Browse files
authored
修复 dockerfile 添加缓存层 (#1943)
1 parent 3921266 commit d72984b

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

web/Dockerfile

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
FROM node:20
1+
# 如果需要用 cicd ,请设置环境变量:
2+
# variables:
3+
# DOCKER_BUILDKIT: 1
24

3-
WORKDIR /gva_web/
4-
COPY . .
5+
FROM node:20-slim AS base
6+
ENV PNPM_HOME="/pnpm"
7+
ENV PATH="$PNPM_HOME:$PATH"
8+
RUN corepack enable
9+
COPY . /app
10+
WORKDIR /app
511

6-
RUN yarn && yarn build
712

8-
FROM nginx:alpine
9-
LABEL MAINTAINER="SliverHorn@[email protected]"
13+
FROM base AS prod-deps
14+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod
15+
16+
FROM base AS build
17+
COPY --from=prod-deps /app/node_modules /app/node_modules
18+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install && pnpm run build
1019

11-
COPY .docker-compose/nginx/conf.d/my.conf /etc/nginx/conf.d/my.conf
12-
COPY --from=0 /gva_web/dist /usr/share/nginx/html
13-
RUN cat /etc/nginx/nginx.conf
14-
RUN cat /etc/nginx/conf.d/my.conf
20+
21+
FROM nginx:alpine
22+
LABEL MAINTAINER="[email protected]"
23+
COPY --from=base /app/.docker-compose/nginx/conf.d/my.conf /etc/nginx/conf.d/my.conf
24+
COPY --from=build /app/dist /usr/share/nginx/html
1525
RUN ls -al /usr/share/nginx/html

0 commit comments

Comments
 (0)