Skip to content

Commit 124d1c1

Browse files
authored
ci: optimize Dockerfile multi-stage build (erda-project#4057)
* ci: optimize Dockerfile multi-stage build Signed-off-by: Ash <[email protected]> * copy scheduler from builder Signed-off-by: Ash <[email protected]> * resolve FROM as warning Signed-off-by: Ash <[email protected]> --------- Signed-off-by: Ash <[email protected]>
1 parent 2f09a98 commit 124d1c1

File tree

2 files changed

+27
-41
lines changed

2 files changed

+27
-41
lines changed

Dockerfile

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1+
# syntax = registry.erda.cloud/retag/dockerfile:latest
2+
FROM registry.erda.cloud/erda-x/node:14 AS build
3+
4+
WORKDIR /build
5+
6+
COPY . ./erda-ui
7+
COPY --from=erda-ui-enterprise / /build/erda-ui-enterprise
8+
9+
RUN cd erda-ui/shell && \
10+
npm run extra-logic && \
11+
cd /build/erda-ui && \
12+
npm cache clean --force && \
13+
npm install -g --force [email protected] && \
14+
pnpm install --frozen-lockfile --no-optional --unsafe-perm && \
15+
pnpm run build-online
16+
117
FROM registry.erda.cloud/erda-x/node:14
218

319
WORKDIR /usr/src/app
420

5-
COPY public ./public
6-
COPY scheduler ./scheduler
21+
COPY --from=build /build/erda-ui/public ./public
22+
COPY --from=build /build/erda-ui/scheduler ./scheduler
723

824
WORKDIR /usr/src/app/scheduler
25+
926
ENV NODE_ENV=production
1027

11-
RUN npm i [email protected] -g
12-
RUN pnpm i --unsafe-perm --reporter append-only
13-
RUN pnpm run build
28+
RUN npm install -g [email protected] && \
29+
pnpm install --unsafe-perm --reporter append-only && \
30+
pnpm run build
1431

15-
CMD pnpm run start:prod
32+
CMD ["pnpm", "run", "start:prod"]

pipeline.yml

+4-35
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,14 @@ stages:
3737
description: 从 git 代码仓库中解析提交信息,生成仓库版本
3838
params:
3939
git_dir: ${{ dirs.erda-ui-enterprise }}
40-
- stage:
41-
- js-build:
42-
alias: build-erda-ui
43-
description: 针对 nodejs 工程的编译打包任务
44-
version: "1.0"
45-
params:
46-
build_cmd:
47-
- cd ${{ dirs.erda-ui }}/shell && npm run extra-logic
48-
- cd ${{ dirs.erda-ui }}
49-
- npm cache clean --force
50-
- npm i -g --force [email protected]
51-
- pnpm i --frozen-lockfile --no-optional --unsafe-perm
52-
- pnpm run build-online
53-
- cp -r ${{ dirs.erda-ui }}/{public,scheduler} $WORKDIR
54-
node_version: 14
55-
resources:
56-
cpu: 0.5
57-
mem: 6144
58-
- js-build:
59-
alias: build-erda-ui-enterprise
60-
description: 针对 nodejs 工程的编译打包任务
61-
version: "1.0"
62-
params:
63-
build_cmd:
64-
- cd ${{ dirs.erda-ui-enterprise }}/admin && npm ci
65-
- npm run build
66-
- cp -r ${{ dirs.erda-ui-enterprise }}/{public,server} $WORKDIR
67-
node_version: 14
68-
resources:
69-
cpu: 0.5
70-
mem: 2048
7140
- stage:
7241
- dockerfile:
7342
alias: build-erda-ui-image
7443
description: 针对自定义 dockerfile 打包,产出可运行镜像
7544
version: "1.0"
7645
params:
46+
build_context:
47+
erda-ui-enterprise: ${{ dirs.erda-ui-enterprise }}
7748
image:
7849
name: ui
7950
tag: ${{ outputs.ui-version.image_tag }}
@@ -82,8 +53,7 @@ stages:
8253
password: ${{ configs.docker_registry_password }}
8354
url: ${{ configs.docker_registry }}
8455
username: ${{ configs.docker_registry_username }}
85-
workdir: ${{ dirs.build-erda-ui }}
86-
image: registry.erda.cloud/erda-actions/dockerfile-action:1.0-20230509080433-9515bd6
56+
workdir: ${{ dirs.erda-ui }}
8757
resources:
8858
cpu: 0.5
8959
mem: 2048
@@ -100,8 +70,7 @@ stages:
10070
password: ${{ configs.docker_registry_password }}
10171
url: ${{ configs.docker_registry }}
10272
username: ${{ configs.docker_registry_username }}
103-
workdir: ${{ dirs.build-erda-ui-enterprise }}
104-
image: registry.erda.cloud/erda-actions/dockerfile-action:1.0-20230509080433-9515bd6
73+
workdir: ${{ dirs.erda-ui-enterprise }}
10574
resources:
10675
cpu: 0.5
10776
mem: 2048

0 commit comments

Comments
 (0)