diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f7c7f0b..dddc569 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,13 +4,6 @@ name: 构建并推送 Docker 镜像 # 定义触发工作流的条件 on: push: - branches: [ "main" ] # 只在 main 分支上触发 - paths: - - 'Dockerfile' # 当 Dockerfile 发生变化时触发 - - 'version' # 当 version 文件发生变化时触发 - pull_request: - branches: [ "main" ] # 当对 main 分支发起 pull request 时触发 - workflow_dispatch: # 允许手动触发工作流 # 环境变量 env: @@ -23,24 +16,25 @@ jobs: steps: # 步骤1: 检出代码 - name: 检出代码 - uses: actions/checkout@v2 + uses: actions/checkout@v3 # 步骤2: 读取版本号 - name: 读取版本号 id: get_version - run: echo "VERSION=$(cat version)" >> $GITHUB_OUTPUT + run: | + echo "VERSION=$(cat version)" >> $GITHUB_ENV # 步骤3: 设置 QEMU(用于多架构构建) - name: 设置 QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v2 # 步骤4: 设置 Docker Buildx(用于构建 Docker 镜像) - name: 设置 Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 # 步骤5: 登录到 GitHub Container Registry - name: 登录到 GitHub Container Registry - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.repository_owner }} @@ -48,20 +42,20 @@ jobs: # 新步骤: 登录到 DockerHub - name: 登录到 DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} # 步骤6: 构建并推送 Docker 镜像到 GitHub Container Registry 和 DockerHub - name: 构建并推送 - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v3 with: - context: . # 构建上下文为当前目录 + context: . # 构建上下文为当前目录 push: true # 推送镜像到仓库 platforms: linux/amd64,linux/arm64 # 构建多架构镜像 tags: | # 定义镜像标签 ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest - ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }} + ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest - ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }} + ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}