From d2a043f2a3e8004b49135eb1e581293fb1684a9f Mon Sep 17 00:00:00 2001 From: d8dfun Date: Tue, 1 Jul 2025 00:19:14 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20.github/workflows/build.ya?= =?UTF-8?q?ml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yaml | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 000000000..1a0fb8a36 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,61 @@ +name: Virtual Kubelet Docker Build and Deploy +on: + release: + types: [created] # 仅在创建Release时触发,也可选择published、edited等 + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: 输出触发信息 + run: | + echo "🎉 该作业由 ${{ github.event_name }} 事件自动触发。" + echo "🐧 此作业当前在 GitHub 托管的 ${{ runner.os }} 服务器上运行!" + echo "🔎 您的发布版本是 ${{ github.ref_name }},仓库是 ${{ github.repository }}。" + + - name: 检出仓库代码 + uses: actions/checkout@v4 + + - name: 输出工作区信息 + run: | + echo "💡 ${{ github.repository }} 仓库已克隆到运行器。" + echo "🖥️ 工作流现在已准备好在运行器上测试您的代码。" + ls -la ${{ github.workspace }} + echo "🍏 此作业的状态是 ${{ job.status }}。" + + - name: 设置 Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: 从标签名中提取版本号 + id: extract_version + run: | + # 从Release标签名中提取版本号,例如从 v0.1.0 中提取 v0.1.0 + VERSION=$(echo "${{ github.ref_name }}" | sed 's|refs/tags/||') + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "提取的版本号:$VERSION" + + - name: 登录 Docker 注册表 + uses: docker/login-action@v3 + with: + registry: registry.cn-beijing.aliyuncs.com + username: ${{ secrets.ALI_DOCKER_REGISTRY_USERNAME }} + password: ${{ secrets.ALI_DOCKER_REGISTRY_PASSWORD }} + + - name: 构建并推送 Virtual Kubelet 镜像 + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile # 确保Dockerfile路径正确 + push: true + tags: | + registry.cn-beijing.aliyuncs.com/d8dcloud/virtual-kubelet:${{ env.VERSION }} + registry.cn-beijing.aliyuncs.com/d8dcloud/virtual-kubelet:latest + build-args: | + GOLANG_CI_LINT_VERSION=v1.68.0 + BUILD_TAGS="" + labels: | + org.opencontainers.image.title=Virtual Kubelet + org.opencontainers.image.description=Kubernetes Virtual Kubelet implementation + org.opencontainers.image.version=${{ env.VERSION }} + org.opencontainers.image.source=${{ github.repositoryUrl }} + org.opencontainers.image.revision=${{ github.sha }} \ No newline at end of file