From 4d490d0add0f0d384077faf0340122df0ac8a568 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Wed, 1 Jul 2026 00:22:07 +0800 Subject: [PATCH] ci(ci): add alpine image build workflow and refactor dockerfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构了packages/ui的Dockerfile,支持通过build-arg指定基础镜像类型,新增了多架构的alpine镜像构建任务,适配不同场景的镜像使用需求 --- .github/workflows/release-image.yml | 16 +++++++++++ packages/ui/Dockerfile | 41 ++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release-image.yml b/.github/workflows/release-image.yml index 31181550a..820a98a7c 100644 --- a/.github/workflows/release-image.yml +++ b/.github/workflows/release-image.yml @@ -94,6 +94,22 @@ jobs: greper/certd:${{steps.get_certd_version.outputs.result}} ghcr.io/${{ github.repository }}:latest ghcr.io/${{ github.repository }}:${{steps.get_certd_version.outputs.result}} + - name: Build alpine + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64,linux/arm64 + push: true + context: ./packages/ui/ + build-args: | + base_type=alpine + tags: | + registry.cn-shenzhen.aliyuncs.com/handsfree/certd:alpine + registry.cn-shenzhen.aliyuncs.com/handsfree/certd:${{steps.get_certd_version.outputs.result}}-alpine + greper/certd:alpine + greper/certd:${{steps.get_certd_version.outputs.result}}-alpine + ghcr.io/${{ github.repository }}:alpine + ghcr.io/${{ github.repository }}:${{steps.get_certd_version.outputs.result}}-alpine + - name: Build armv7 uses: docker/build-push-action@v6 with: diff --git a/packages/ui/Dockerfile b/packages/ui/Dockerfile index 09cb7c277..25b9cdd2f 100644 --- a/packages/ui/Dockerfile +++ b/packages/ui/Dockerfile @@ -1,9 +1,15 @@ -# 根据目标平台选择基础镜像:amd64/arm64 用 trixie-slim,arm/v7 没有 trixie-slim 发布,回退到 alpine -FROM --platform=linux/amd64 node:22-trixie-slim AS base-amd64 -FROM --platform=linux/arm64 node:22-trixie-slim AS base-arm64 -FROM --platform=linux/arm/v7 node:22-alpine AS base-arm-v7 +ARG base_type=slim -FROM base-${TARGETARCH}${TARGETVARIANT:+-}${TARGETVARIANT} AS builder +# 根据 base_type 参数选择基础镜像系列 +FROM --platform=linux/amd64 node:22-alpine AS base-amd64-alpine +FROM --platform=linux/arm64 node:22-alpine AS base-arm64-alpine +FROM --platform=linux/arm/v7 node:22-alpine AS base-arm-v7-alpine + +FROM --platform=linux/amd64 node:22-trixie-slim AS base-amd64-slim +FROM --platform=linux/arm64 node:22-trixie-slim AS base-arm64-slim +FROM --platform=linux/arm/v7 node:22-alpine AS base-arm-v7-slim + +FROM base-${TARGETARCH}${TARGETVARIANT:+-}${TARGETVARIANT}-${base_type} AS builder WORKDIR /workspace/ COPY . /workspace/ @@ -15,12 +21,17 @@ RUN cp /workspace/certd-client/dist/* /workspace/certd-server/public/ -rf RUN cd /workspace/certd-server && pnpm install --production && npm run build-on-docker -FROM base-${TARGETARCH}${TARGETVARIANT:+-}${TARGETVARIANT} +ARG base_type=slim + +FROM base-${TARGETARCH}${TARGETVARIANT:+-}${TARGETVARIANT}-${base_type} EXPOSE 7001 EXPOSE 7002 +ARG base_type=slim + # 根据基础镜像发行版选择包管理器 # trixie-slim -> apt-get, alpine -> apk +# base_type=alpine 时不安装 openjdk RUN if [ -f /etc/debian_version ]; then \ apt-get update \ && apt-get install -y --no-install-recommends \ @@ -32,16 +43,20 @@ RUN if [ -f /etc/debian_version ]; then \ iputils-ping \ dnsutils \ iproute2 \ - && wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor | tee /usr/share/keyrings/adoptium.gpg > /dev/null \ - && echo "deb [signed-by=/usr/share/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb bookworm main" | tee /etc/apt/sources.list.d/adoptium.list \ - && apt-get update \ - && apt-get install -y --no-install-recommends temurin-8-jre \ + && if [ "$base_type" != "alpine" ]; then \ + wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor | tee /usr/share/keyrings/adoptium.gpg > /dev/null \ + && echo "deb [signed-by=/usr/share/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb bookworm main" | tee /etc/apt/sources.list.d/adoptium.list \ + && apt-get update \ + && apt-get install -y --no-install-recommends temurin-8-jre; \ + fi \ && apt-get clean \ && rm -rf /var/lib/apt/lists/*; \ elif [ -f /etc/alpine-release ]; then \ - apk add --no-cache \ - openssl \ - openjdk8-jre; \ + if [ "$base_type" = "alpine" ]; then \ + apk add --no-cache openssl; \ + else \ + apk add --no-cache openssl openjdk8-jre; \ + fi; \ else \ echo "Unsupported base image"; exit 1; \ fi