From b7f58971febdb0ed0f49abdd97804db4940df143 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Mon, 21 Jul 2025 14:40:08 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E7=BC=93=E5=AD=98=E6=B8=85=E9=99=A4=E7=AD=96?= =?UTF-8?q?=E7=95=A5=E5=B9=B6=E6=9B=B4=E6=96=B0=E9=98=BF=E9=87=8C=E4=BA=91?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为前端服务添加构建时的缓存清除策略,通过引入CACHEBUST参数确保每次构建获取最新依赖 更新docker-compose.aliyun.yml添加pull_policy配置确保总是拉取最新镜像 --- build-and-push.sh | 6 +++++- docker-compose.aliyun.yml | 1 + services/frontend/Dockerfile | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build-and-push.sh b/build-and-push.sh index ceee51e..aa6184d 100644 --- a/build-and-push.sh +++ b/build-and-push.sh @@ -30,7 +30,11 @@ for service in "${SERVICES[@]}"; do # 构建Docker镜像 echo "正在构建镜像: $IMAGE_NAME" - docker build -t $IMAGE_NAME $SERVICE_DIR + if [ "$service" = "frontend" ]; then + docker build --build-arg CACHEBUST=$(date +%s) -t $IMAGE_NAME $SERVICE_DIR + else + docker build -t $IMAGE_NAME $SERVICE_DIR + fi if [ $? -ne 0 ]; then echo "镜像构建失败" exit 1 diff --git a/docker-compose.aliyun.yml b/docker-compose.aliyun.yml index d3d3772..a98841a 100644 --- a/docker-compose.aliyun.yml +++ b/docker-compose.aliyun.yml @@ -108,6 +108,7 @@ services: frontend: image: crpi-amr0dt5e5pywqwaf.cn-hangzhou.personal.cr.aliyuncs.com/testrrr/frontend:latest + pull_policy: always container_name: ari-frontend restart: always depends_on: diff --git a/services/frontend/Dockerfile b/services/frontend/Dockerfile index fc9f0ef..28f6302 100644 --- a/services/frontend/Dockerfile +++ b/services/frontend/Dockerfile @@ -3,7 +3,7 @@ WORKDIR /app COPY package*.json ./ RUN npm install COPY . . -RUN npm run build +RUN echo "Cachebust: $CACHEBUST" && npm run build FROM nginx:stable-alpine as production-stage COPY --from=build-stage /app/dist /usr/share/nginx/html