From 39ad8a7447724cb30d80cc1cf538ab36df1efa00 Mon Sep 17 00:00:00 2001 From: He Wang Date: Tue, 27 Aug 2024 21:27:54 +0800 Subject: [PATCH] release oceanbase-ce by build-push-action --- .../workflows/release-lts-oceanbase-ce.yml | 10 +- .github/workflows/release-oceanbase-ce.yml | 10 +- .../reusable-build-and-test-oceanbase-ce.yml | 2 + .../workflows/reusable-build-oceanbase-ce.yml | 67 +++++++++++- .../reusable-release-oceanbase-ce.yml | 101 +++--------------- 5 files changed, 81 insertions(+), 109 deletions(-) diff --git a/.github/workflows/release-lts-oceanbase-ce.yml b/.github/workflows/release-lts-oceanbase-ce.yml index f61886c..7f262a4 100644 --- a/.github/workflows/release-lts-oceanbase-ce.yml +++ b/.github/workflows/release-lts-oceanbase-ce.yml @@ -19,17 +19,9 @@ jobs: id: set_version_vars run: echo "version=$(echo $tagName | grep -P '(\d*\.\d*\.\d*\.\d*-\d{18})' --only-matching)" >> $GITHUB_OUTPUT - build-and-test: - uses: ./.github/workflows/reusable-build-and-test-oceanbase-ce.yml - needs: set-version - with: - cache_key: release-lts-oceanbase-ce - version: ${{ needs.set-version.outputs.version }} - release: uses: ./.github/workflows/reusable-release-oceanbase-ce.yml - needs: build-and-test + needs: set-version with: - cache_key: release-lts-oceanbase-ce version: ${{ needs.set-version.outputs.version }} lts: true diff --git a/.github/workflows/release-oceanbase-ce.yml b/.github/workflows/release-oceanbase-ce.yml index 30e1a7d..f4ff9ac 100644 --- a/.github/workflows/release-oceanbase-ce.yml +++ b/.github/workflows/release-oceanbase-ce.yml @@ -19,17 +19,9 @@ jobs: id: set_version_vars run: echo "version=$(echo $tagName | grep -P '(\d*\.\d*\.\d*\.\d*-\d{18})' --only-matching)" >> $GITHUB_OUTPUT - build-and-test: - uses: ./.github/workflows/reusable-build-and-test-oceanbase-ce.yml - needs: set-version - with: - cache_key: release-oceanbase-ce - version: ${{ needs.set-version.outputs.version }} - release: uses: ./.github/workflows/reusable-release-oceanbase-ce.yml - needs: build-and-test + needs: set-version with: - cache_key: release-oceanbase-ce version: ${{ needs.set-version.outputs.version }} lts: false diff --git a/.github/workflows/reusable-build-and-test-oceanbase-ce.yml b/.github/workflows/reusable-build-and-test-oceanbase-ce.yml index 841492f..4ef53b4 100644 --- a/.github/workflows/reusable-build-and-test-oceanbase-ce.yml +++ b/.github/workflows/reusable-build-and-test-oceanbase-ce.yml @@ -16,6 +16,8 @@ jobs: with: cache_key: ${{ inputs.cache_key }} version: ${{ inputs.version }} + push-images: false + push-lts-images: false test-slim: needs: build diff --git a/.github/workflows/reusable-build-oceanbase-ce.yml b/.github/workflows/reusable-build-oceanbase-ce.yml index 00c26b2..efd06eb 100644 --- a/.github/workflows/reusable-build-oceanbase-ce.yml +++ b/.github/workflows/reusable-build-oceanbase-ce.yml @@ -3,12 +3,18 @@ name: build oceanbase-ce image on: workflow_call: inputs: - cache_key: - required: true - type: string version: required: true type: string + cache_key: + required: false + type: string + push-images: + required: false + type: boolean + push-lts-images: + required: false + type: boolean jobs: build-oceanbase-ce-image: @@ -35,6 +41,29 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker hub + if: ${{ inputs.push-images }} + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Log in to Quay io + if: ${{ inputs.push-images }} + uses: docker/login-action@v3 + with: + registry: quay.io + username: ${{ secrets.QUAY_IO_USERNAME }} + password: ${{ secrets.QUAY_IO_PASSWORD }} + + - name: Log in to Ghcr io + if: ${{ inputs.push-images }} + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Build pre image uses: docker/build-push-action@v6 @@ -53,13 +82,45 @@ jobs: mkdir -p ./oceanbase-ce/share docker run -v ./oceanbase-ce/share:/root/share oceanbase-ce-pre + - name: Set image tags + if: ${{ inputs.push-images }} + id: set_image_tags + run: | + image_tags="" + image_tags="${image_tags} ${{ env.DOCKER_PUSH_BASE }}/oceanbase-ce:${{ inputs.version }}" + image_tags="${image_tags} quay.io/${{ env.QUAY_IO_PUSH_BASE }}/oceanbase-ce:${{ inputs.version }}" + image_tags="${image_tags} ghcr.io/${{ github.repository_owner }}/oceanbase-ce:${{ inputs.version }}" + if [[ "${{ inputs.push-lts-images }}" == "true" ]]; then + lts_version="$(echo ${{ inputs.version }} | grep -P '(\d*\.\d*\.\d*)' --only-matching)" + lts_tag="${lts_version}-lts" + image_tags="${image_tags} ${{ env.DOCKER_PUSH_BASE }}/oceanbase-ce:${lts_tag}" + image_tags="${image_tags} quay.io/${{ env.QUAY_IO_PUSH_BASE }}/oceanbase-ce:${lts_tag}" + image_tags="${image_tags} ghcr.io/${{ github.repository_owner }}/oceanbase-ce:${lts_tag}" + fi + echo "image tags: ${image_tags}" + echo "tags=${image_tags}" >> $GITHUB_OUTPUT + + - name: Build and push observer image + if: ${{ inputs.push-images }} + uses: docker/build-push-action@v6 + with: + context: ./oceanbase-ce + platforms: linux/amd64,linux/arm64 + file: ./oceanbase-ce/Dockerfile + push: true + tags: ${{ steps.set_image_tags.outputs.tags }} + build-args: | + VERSION=${{ inputs.version }} + - name: Build observer image + if: ${{ inputs.push-images == false }} run: | cd oceanbase-ce docker buildx build --build-arg VERSION=${{ inputs.version }} --platform linux/amd64 -t oceanbase-ce:amd64 --load --output type=docker,dest=./oceanbase-ce-amd64.tar . docker buildx build --build-arg VERSION=${{ inputs.version }} --platform linux/arm64 -t oceanbase-ce:arm64 --load --output type=docker,dest=./oceanbase-ce-arm64.tar . - name: Upload artifact + if: ${{ inputs.push-images == false }} uses: actions/upload-artifact@v4 with: name: ${{ inputs.cache_key }} diff --git a/.github/workflows/reusable-release-oceanbase-ce.yml b/.github/workflows/reusable-release-oceanbase-ce.yml index 8e152fd..5d4c0dc 100644 --- a/.github/workflows/reusable-release-oceanbase-ce.yml +++ b/.github/workflows/reusable-release-oceanbase-ce.yml @@ -3,9 +3,6 @@ name: release oceanbase-ce image on: workflow_call: inputs: - cache_key: - required: true - type: string version: required: true type: string @@ -14,88 +11,16 @@ on: type: boolean jobs: - release-oceanbase-ce: - runs-on: ubuntu-latest - steps: - - name: Free disk space on Ubuntu runner - uses: kfir4444/free-disk-space@main - with: - tool-cache: false - android: true - dotnet: true - haskell: true - large-packages: true - swap-storage: true - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to Docker hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Log in to Quay io - uses: docker/login-action@v3 - with: - registry: quay.io - username: ${{ secrets.QUAY_IO_USERNAME }} - password: ${{ secrets.QUAY_IO_PASSWORD }} - - - name: Log in to Ghcr io - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Download artifact - uses: actions/download-artifact@v4 - with: - name: ${{ inputs.cache_key }} - path: /tmp - - - name: Load observer images - run: | - docker load -i /tmp/oceanbase-ce-amd64.tar - rm -f /tmp/oceanbase-ce-amd64.tar - docker load -i /tmp/oceanbase-ce-arm64.tar - rm -f /tmp/oceanbase-ce-arm64.tar - - - name: Publish observer images with version tag - run: | - gh_tag=ghcr.io/${{ github.repository_owner }}/oceanbase-ce:${{ inputs.version }} - docker buildx imagetools create --dry-run --tag $gh_tag oceanbase-ce:amd64 oceanbase-ce:arm64 - docker push $gh_tag - - docker tag $gh_tag quay.io/${{ vars.QUAY_IO_PUSH_BASE }}/oceanbase-ce:${{ inputs.version }} - docker push quay.io/${{ vars.QUAY_IO_PUSH_BASE }}/oceanbase-ce:${{ inputs.version }} - - docker tag $gh_tag ghcr.io/${{ github.repository_owner }}/oceanbase-ce:${{ inputs.version }} - docker push ghcr.io/${{ github.repository_owner }}/oceanbase-ce:${{ inputs.version }} - - - name: Publish observer images with lts tag - if: ${{ inputs.lts }} - run: | - gh_tag=ghcr.io/${{ github.repository_owner }}/oceanbase-ce:${{ inputs.version }} - lts_version=$(echo $tagName | grep -P '(\d*\.\d*\.\d*)' --only-matching) - lts_tag="${lts_version}-lts" - - docker tag $gh_tag ${{ vars.DOCKER_PUSH_BASE }}/oceanbase-ce:$lts_tag - docker tag $gh_tag ${{ vars.DOCKER_PUSH_BASE }}/oceanbase-ce:latest - docker push ${{ vars.DOCKER_PUSH_BASE }}/oceanbase-ce:$lts_tag - docker push ${{ vars.DOCKER_PUSH_BASE }}/oceanbase-ce:latest - - docker tag $gh_tag quay.io/${{ vars.QUAY_IO_PUSH_BASE }}/oceanbase-ce:$lts_tag - docker tag $gh_tag quay.io/${{ vars.QUAY_IO_PUSH_BASE }}/oceanbase-ce:latest - docker push quay.io/${{ vars.QUAY_IO_PUSH_BASE }}/oceanbase-ce:$lts_tag - docker push quay.io/${{ vars.QUAY_IO_PUSH_BASE }}/oceanbase-ce:latest - - docker tag $gh_tag ghcr.io/${{ github.repository_owner }}/oceanbase-ce:$lts_tag - docker tag $gh_tag ghcr.io/${{ github.repository_owner }}/oceanbase-ce:latest - docker push ghcr.io/${{ github.repository_owner }}/oceanbase-ce:$lts_tag - docker push ghcr.io/${{ github.repository_owner }}/oceanbase-ce:latest + build-and-test: + uses: ./.github/workflows/reusable-build-and-test-oceanbase-ce.yml + with: + cache_key: release-oceanbase-ce + version: ${{ inputs.version }} + + release: + uses: ./.github/workflows/reusable-build-oceanbase-ce.yml + needs: build-and-test + with: + version: ${{ inputs.version }} + push-images: true + push-lts-images: ${{ inputs.lts }}