From b6967655745401a96499aa59f924f9e07d4498ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=BA=AD?= Date: Tue, 19 Aug 2025 11:15:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20ci/cd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/develop.yml | 46 ++++++++++++++++------------------- Dockerfile | 18 +++++++++++--- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 9b21627..eae615c 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -12,10 +12,6 @@ env: jobs: build: runs-on: ubuntu-latest - container: - image: zuogeus/act-ubuntu:node18 - options: --add-host nexus.zzwb.cc:192.168.2.7 - steps: - name: Setup Environments shell: bash @@ -25,54 +21,54 @@ jobs: echo "IMAGE_NAME=${{ vars.REGISTRY_URL }}/${{ vars.REGISTRY_NAMESPACE }}/$REPO:$GITHUB_REF_NAME" >> $GITHUB_ENV - name: Checkout - uses: https://gitee.com/zuowenbo/checkout@v4.1.1 + uses: https://gitee.com/zuowenbo/checkout@v4.2.2 - - name: Get npm cache directory - id: npm-cache-dir - shell: bash - run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} - - - name: Set node_modules cache - uses: https://gitee.com/zuowenbo/cache@v4.0.0 - id: npm-cache + - name: Cache Docker layers + uses: https://gitee.com/zuowenbo/cache@v4.2.1 with: - path: ${{ steps.npm-cache-dir.outputs.dir }} - key: ${{ runner.os }}-node-umi4-${{ hashFiles('**/package-lock.json') }} + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ env.REPO_NAME }}-${{ github.sha }} restore-keys: | - ${{ runner.os }}-node-umi4- - - - run: npm install --registry=https://registry.npmmirror.com - - run: npm run build + ${{ runner.os }}-buildx-${{ env.REPO_NAME }}- - name: Set up Docker Buildx - uses: https://gitee.com/zuowenbo/setup-buildx-action@v3.0.0 + uses: https://gitee.com/zuowenbo/setup-buildx-action@v3.9.0 with: - driver-opts: network=host + driver-opts: image=registry.cn-shenzhen.aliyuncs.com/zuoge-proxy/buildkit:buildx-stable-1 - name: Login to Docker Hub - uses: https://gitee.com/zuowenbo/login-action@v3.0.0 + uses: https://gitee.com/zuowenbo/login-action@v3.3.0 with: registry: ${{ vars.REGISTRY_URL }} username: ${{ vars.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_PASSWORD }} - name: Build and push final image - uses: https://gitee.com/zuowenbo/build-push-action@v5.1.0 + uses: https://gitee.com/zuowenbo/build-push-action@v6.14.0 with: context: . tags: ${{ env.IMAGE_NAME }} push: true + platforms: linux/amd64 build-args: BRANCH=${{ env.GITHUB_REF_NAME }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache - name: Deploy to remote uses: https://gitee.com/zuowenbo/ssh-action@v1.0.3 with: - host: ${{ vars.LOAN_DEV_HOST_IP }} + host: ${{ vars.DEV_HOST_IP }} port: 22 username: 'ubuntu' - password: ${{ secrets.LOAN_DEV_HOST_PASSWORD }} + password: ${{ secrets.DEV_HOST_PASSWORD }} script: | docker login -u ${{ vars.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ vars.REGISTRY_URL}} + docker volume create ${{ env.REPO_NAME }} || true docker pull ${{ env.IMAGE_NAME }} docker stop ${{ env.REPO_NAME }} || true docker rm ${{ env.REPO_NAME }} || true diff --git a/Dockerfile b/Dockerfile index 365a9df..f535562 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,15 @@ -FROM nexus.zzwb.cc:18444/nginx:1.21-alpine -COPY dist /usr/share/nginx/html -COPY docker/nginx.conf /etc/nginx/nginx.conf \ No newline at end of file +# 构建阶段 +FROM registry.cn-shenzhen.aliyuncs.com/zuoge-proxy/node:20-alpine AS build +RUN npm install -g pnpm --registry=https://registry.npmmirror.com + +WORKDIR /app +COPY package.json pnpm-lock.yaml* ./ +RUN pnpm install --registry=https://registry.npmmirror.com + +COPY . . +RUN pnpm build + +# 部署阶段 +FROM registry.cn-shenzhen.aliyuncs.com/zuoge-proxy/nginx:1.27.3-alpine AS app +COPY --from=build /app/dist /usr/share/nginx/html +COPY docker/nginx.conf /etc/nginx/nginx.conf