From 0c99913e916d761d7a08126c6b8412e7f13ec559 Mon Sep 17 00:00:00 2001 From: Sakurasan <26715255+Sakurasan@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:47:59 +0800 Subject: [PATCH] update action --- .github/workflows/ci.yaml | 44 +++++++++++++++++++++++------------- .github/workflows/tag.yaml | 46 ++++++++++++++++++++++++-------------- 2 files changed, 57 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 75c52ae..ffcb86d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,54 +1,66 @@ name: Docker Image CI -#触发器设置 + on: push: branches: - main - dev -#项目任务,任务之间可以并行调度 jobs: - build: - #选择云端运行的环境 runs-on: ubuntu-latest steps: - #uses代表使用一个模块,此处使用的是checkout模块,将github项目文件导入到当前环境中 - uses: actions/checkout@v3 - #使用with跟在后面来为前面的模块输入参数 with: submodules: 'true' + - name: Get current date id: date - run: echo "::set-output name=today::$(date +'%Y%m%d')" + run: echo "today=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT + - name: Set up QEMU uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v2 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Available platforms - run: echo ${{ steps.buildx.outputs.platforms }} + run: echo ${{ steps.buildx.outputs.platforms }} + - name: Login to DockerHub uses: docker/login-action@v2 with: - #这里用到了github的secrets功能,避免账户和密码随仓库泄露 - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push - #导入这个模块来完成自动编译和推送 - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v4 with: context: . file: ./docker/Dockerfile push: true - #在这里通过加入需要编译的平台和前面配好的QEMU,buildx来达到多平台编译 platforms: linux/amd64,linux/arm64 - #指定用户/仓库名 tags: | ${{ github.repository }}:${{ steps.date.outputs.today }} ${{ github.repository }}:${{ contains(github.ref,'main') && 'latest' || 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: Docker Hub Description - #这里是通过md文件自动生成dockerhub描述的模块,也可以不需要 uses: peter-evans/dockerhub-description@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml index 70ed97f..8236026 100644 --- a/.github/workflows/tag.yaml +++ b/.github/workflows/tag.yaml @@ -1,53 +1,65 @@ name: Docker Image CI -#触发器设置 + on: push: tags: - 'v*' -#项目任务,任务之间可以并行调度 jobs: - build: - #选择云端运行的环境 runs-on: ubuntu-latest steps: - #uses代表使用一个模块,此处使用的是checkout模块,将github项目文件导入到当前环境中 - uses: actions/checkout@v3 - #使用with跟在后面来为前面的模块输入参数 with: submodules: 'true' - - name: Get version # 获取 Tag Version + + - name: Get version id: vars - run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} + run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT + - name: Set up QEMU uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v2 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Available platforms - run: echo ${{ steps.buildx.outputs.platforms }} + run: echo ${{ steps.buildx.outputs.platforms }} + - name: Login to DockerHub uses: docker/login-action@v2 with: - #这里用到了github的secrets功能,避免账户和密码随仓库泄露 - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push - #导入这个模块来完成自动编译和推送 - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v4 with: context: . file: ./docker/Dockerfile push: true - #在这里通过加入需要编译的平台和前面配好的QEMU,buildx来达到多平台编译 platforms: linux/amd64,linux/arm64 - #指定用户/仓库名 tags: | ${{ github.repository }}:${{ steps.vars.outputs.tag }} ${{ github.repository }}:latest + 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: Docker Hub Description - #这里是通过md文件自动生成dockerhub描述的模块,也可以不需要 uses: peter-evans/dockerhub-description@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }}