Skip to content

Commit

Permalink
ci: optimize Dockerfile multi-stage build (#4057)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
iutx authored Sep 13, 2024
1 parent 2f09a98 commit 124d1c1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 41 deletions.
29 changes: 23 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
# syntax = registry.erda.cloud/retag/dockerfile:latest
FROM registry.erda.cloud/erda-x/node:14 AS build

WORKDIR /build

COPY . ./erda-ui
COPY --from=erda-ui-enterprise / /build/erda-ui-enterprise

RUN cd erda-ui/shell && \
npm run extra-logic && \
cd /build/erda-ui && \
npm cache clean --force && \
npm install -g --force [email protected] && \
pnpm install --frozen-lockfile --no-optional --unsafe-perm && \
pnpm run build-online

FROM registry.erda.cloud/erda-x/node:14

WORKDIR /usr/src/app

COPY public ./public
COPY scheduler ./scheduler
COPY --from=build /build/erda-ui/public ./public
COPY --from=build /build/erda-ui/scheduler ./scheduler

WORKDIR /usr/src/app/scheduler

ENV NODE_ENV=production

RUN npm i [email protected] -g
RUN pnpm i --unsafe-perm --reporter append-only
RUN pnpm run build
RUN npm install -g [email protected] && \
pnpm install --unsafe-perm --reporter append-only && \
pnpm run build

CMD pnpm run start:prod
CMD ["pnpm", "run", "start:prod"]
39 changes: 4 additions & 35 deletions pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,14 @@ stages:
description: 从 git 代码仓库中解析提交信息,生成仓库版本
params:
git_dir: ${{ dirs.erda-ui-enterprise }}
- stage:
- js-build:
alias: build-erda-ui
description: 针对 nodejs 工程的编译打包任务
version: "1.0"
params:
build_cmd:
- cd ${{ dirs.erda-ui }}/shell && npm run extra-logic
- cd ${{ dirs.erda-ui }}
- npm cache clean --force
- npm i -g --force [email protected]
- pnpm i --frozen-lockfile --no-optional --unsafe-perm
- pnpm run build-online
- cp -r ${{ dirs.erda-ui }}/{public,scheduler} $WORKDIR
node_version: 14
resources:
cpu: 0.5
mem: 6144
- js-build:
alias: build-erda-ui-enterprise
description: 针对 nodejs 工程的编译打包任务
version: "1.0"
params:
build_cmd:
- cd ${{ dirs.erda-ui-enterprise }}/admin && npm ci
- npm run build
- cp -r ${{ dirs.erda-ui-enterprise }}/{public,server} $WORKDIR
node_version: 14
resources:
cpu: 0.5
mem: 2048
- stage:
- dockerfile:
alias: build-erda-ui-image
description: 针对自定义 dockerfile 打包,产出可运行镜像
version: "1.0"
params:
build_context:
erda-ui-enterprise: ${{ dirs.erda-ui-enterprise }}
image:
name: ui
tag: ${{ outputs.ui-version.image_tag }}
Expand All @@ -82,8 +53,7 @@ stages:
password: ${{ configs.docker_registry_password }}
url: ${{ configs.docker_registry }}
username: ${{ configs.docker_registry_username }}
workdir: ${{ dirs.build-erda-ui }}
image: registry.erda.cloud/erda-actions/dockerfile-action:1.0-20230509080433-9515bd6
workdir: ${{ dirs.erda-ui }}
resources:
cpu: 0.5
mem: 2048
Expand All @@ -100,8 +70,7 @@ stages:
password: ${{ configs.docker_registry_password }}
url: ${{ configs.docker_registry }}
username: ${{ configs.docker_registry_username }}
workdir: ${{ dirs.build-erda-ui-enterprise }}
image: registry.erda.cloud/erda-actions/dockerfile-action:1.0-20230509080433-9515bd6
workdir: ${{ dirs.erda-ui-enterprise }}
resources:
cpu: 0.5
mem: 2048
Expand Down

0 comments on commit 124d1c1

Please sign in to comment.