From 902e23e6ba86d414a9ec3937ae542d2022d62491 Mon Sep 17 00:00:00 2001 From: "bo.jiang" Date: Wed, 24 Aug 2022 21:07:15 +0800 Subject: [PATCH] Integrate image build ci Signed-off-by: bo.jiang --- .github/PULL_REQUEST_TEMPLATE.md | 26 ++--- .../{tag.yaml => auto-version-release.yaml} | 30 ++++-- .github/workflows/call-images-build.yaml | 98 ++++++++++++------- .github/workflows/call-offline-build.yaml | 19 +++- .github/workflows/call-os-pkgs-build.yaml | 2 +- .github/workflows/spray-image-build.yaml | 33 ------- build/images/spray-job/Dockerfile | 6 +- 7 files changed, 117 insertions(+), 97 deletions(-) rename .github/workflows/{tag.yaml => auto-version-release.yaml} (76%) delete mode 100644 .github/workflows/spray-image-build.yaml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 8a118081f..010fd5f3a 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,21 +1,24 @@ **What type of PR is this?** -> Uncomment only one ` /kind <>` line, hit enter to put that in a new line, and remove leading whitespaces from that line: -> -> /kind api-change -> /kind bug -> /kind cleanup -> /kind design -> /kind documentation -> /kind failing-test -> /kind feature -> /kind flake + **What this PR does / why we need it**: @@ -29,4 +32,3 @@ Fixes # **Special notes for your reviewer**: -**make sure your commit is signed off** diff --git a/.github/workflows/tag.yaml b/.github/workflows/auto-version-release.yaml similarity index 76% rename from .github/workflows/tag.yaml rename to .github/workflows/auto-version-release.yaml index e23633cfe..eefbdd4aa 100644 --- a/.github/workflows/tag.yaml +++ b/.github/workflows/auto-version-release.yaml @@ -4,22 +4,36 @@ on: push: tags: - 'v[0-9]+.[0-9]+.[0-9]+' -env: - KUKEAN_OPERATOR_IMAGE_NAME: kubean-operator - KUBESPRAY_IMAGE_NAME: kubespray - SPRAY_JOB_IMAGE_NAME: spray-job - KUBESPRAY_TAG: master + - 'v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+' jobs: + get-spray-ref: + runs-on: ubuntu-latest + outputs: + sha: ${{ steps.get_ref.outputs.sha }} + steps: + - name: Get kubespray latest commit sha + id: get_ref + run: | + COMMIT_SHA=`git ls-remote https://github.com/kubernetes-sigs/kubespray.git HEAD | awk '{ print $1}'` + echo ::set-output name=sha::${COMMIT_SHA} + call-offline-build: uses: ./.github/workflows/call-offline-build.yaml + needs: get-spray-ref + with: + spray_ref: ${{ needs.get-spray-ref.outputs.sha }} - call-os-pkgs-build: - uses: ./.github/workflows/call-os-pkgs-build.yaml - call-images-build: uses: ./.github/workflows/call-images-build.yaml secrets: inherit + needs: get-spray-ref + with: + spray_ref: ${{ needs.get-spray-ref.outputs.sha }} + + call-os-pkgs-build: + uses: ./.github/workflows/call-os-pkgs-build.yaml + charts: needs: [call-images-build,call-offline-build] diff --git a/.github/workflows/call-images-build.yaml b/.github/workflows/call-images-build.yaml index 4c3a4d2e0..8d0f51218 100644 --- a/.github/workflows/call-images-build.yaml +++ b/.github/workflows/call-images-build.yaml @@ -1,11 +1,15 @@ name: build-image -on: workflow_call +on: + workflow_call: + inputs: + spray_ref: + required: true + type: string env: - KUKEAN_OPERATOR_IMAGE_NAME: kubean-operator - SPRAY_JOB_IMAGE_NAME: spray-job - KUBESPRAY_TAG: master + ONLINE_REGISTER: ghcr.io + BUILD_PLATFORM: linux/amd64,linux/arm64 jobs: build-push: @@ -15,44 +19,64 @@ jobs: contents: read steps: + - name: Set env + run: | + echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV} + echo "SPRAY_SHA_SHORT=$(echo ${{ inputs.spray_ref }} | cut -c 1-7)" >> ${GITHUB_ENV} + + - name: Echo env + run: | + echo "REPO: ${{ env.REPO }}" + echo "SPRAY_SHA_SHORT: ${{ env.SPRAY_SHA_SHORT }}" + - uses: actions/checkout@v3 with: fetch-depth: 0 + - uses: actions/checkout@v3 + with: + repository: kubernetes-sigs/kubespray + ref: ${{ inputs.spray_ref }} + path: ./kubespray + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2.0.0 + - name: Log in to registry - # This is where you will update the PAT to GITHUB_TOKEN run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin - - name: kubean-operator Build image - run: docker build . --file ./build/images/$KUKEAN_OPERATOR_IMAGE_NAME/Dockerfile --tag $KUKEAN_OPERATOR_IMAGE_NAME + - name: kubespray base image build + uses: docker/build-push-action@v3.1.1 + with: + context: ./ + file: ./build/images/kubespray/Dockerfile + github-token: ${{ secrets.GITHUB_TOKEN }} + push: true + platforms: ${{ env.BUILD_PLATFORM }} + tags: ${{ env.ONLINE_REGISTER }}/${{ env.REPO }}/kubespray:${{ env.SPRAY_SHA_SHORT }} - - name: kubean-operator Push image - run: | - IMAGE_ID=ghcr.io/${{ github.repository }}/$KUKEAN_OPERATOR_IMAGE_NAME - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - # Strip git ref prefix from version - VERSION=$(git describe --tags --abbrev=8 --dirty) - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $KUKEAN_OPERATOR_IMAGE_NAME $IMAGE_ID:$VERSION - docker tag $KUKEAN_OPERATOR_IMAGE_NAME $IMAGE_ID:latest - docker push $IMAGE_ID:$VERSION - docker push $IMAGE_ID:latest - - - name: spray-job Build image - run: docker build . --file ./build/images/$SPRAY_JOB_IMAGE_NAME/Dockerfile --tag $SPRAY_JOB_IMAGE_NAME --build-arg spray_tag=$KUBESPRAY_TAG - - - name: spray-job Push image - run: | - IMAGE_ID=ghcr.io/${{ github.repository }}/$SPRAY_JOB_IMAGE_NAME - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - # Strip git ref prefix from version - VERSION=$(git describe --tags --abbrev=8 --dirty) - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SPRAY_JOB_IMAGE_NAME $IMAGE_ID:$VERSION - docker tag $SPRAY_JOB_IMAGE_NAME $IMAGE_ID:latest - docker push $IMAGE_ID:$VERSION - docker push $IMAGE_ID:latest + - name: spray-job image build + uses: docker/build-push-action@v3.1.1 + with: + context: ./ + file: ./build/images/spray-job/Dockerfile + github-token: ${{ secrets.GITHUB_TOKEN }} + push: true + platforms: ${{ env.BUILD_PLATFORM }} + tags: ${{ env.ONLINE_REGISTER }}/${{ env.REPO }}/spray-job:${{ github.ref_name }} + build-args: | + SPRAY_TAG=${{ env.SPRAY_SHA_SHORT }} + REPO=${{ env.REPO }} + + - name: kubean-operator image build + uses: docker/build-push-action@v3.1.1 + with: + context: ./ + file: ./build/images/kubean-operator/Dockerfile + github-token: ${{ secrets.GITHUB_TOKEN }} + push: true + platforms: ${{ env.BUILD_PLATFORM }} + tags: ${{ env.ONLINE_REGISTER }}/${{ env.REPO }}/kubean-operator:${{ github.ref_name }} diff --git a/.github/workflows/call-offline-build.yaml b/.github/workflows/call-offline-build.yaml index d78edd513..9f00f5ca9 100644 --- a/.github/workflows/call-offline-build.yaml +++ b/.github/workflows/call-offline-build.yaml @@ -1,11 +1,22 @@ name: Offline Build CI -on: workflow_call +on: + workflow_call: + inputs: + spray_ref: + required: true + type: string jobs: offline-build: runs-on: ubuntu-latest steps: + - name: Set env + run: echo "SPRAY_SHA_SHORT=$(echo ${{ inputs.spray_ref }} | cut -c 1-7)" >> ${GITHUB_ENV} + + - name: Echo env + run: echo ${SPRAY_SHA_SHORT} + - name: git clone kubean repo uses: actions/checkout@v3 with: @@ -15,7 +26,7 @@ jobs: uses: actions/checkout@v3 with: repository: kubernetes-sigs/kubespray - ref: ${{ env.KUBESPRAY_TAG }} + ref: ${{ inputs.spray_ref }} path: ./kubespray - name: install yq tool @@ -23,8 +34,8 @@ jobs: - name: generate ComponentsVersion & OfflineVersion files run: | - KUBEAN_TAG=${GITHUB_REF_NAME} KUBESPRAY_TAG=${{ env.KUBESPRAY_TAG }} bash artifacts/manage_version_cr.sh create_componentsversion - KUBEAN_TAG=${GITHUB_REF_NAME} KUBESPRAY_TAG=${{ env.KUBESPRAY_TAG }} bash artifacts/manage_version_cr.sh create_offlineversion + KUBEAN_TAG=${GITHUB_REF_NAME} KUBESPRAY_TAG=${SPRAY_SHA_SHORT} bash artifacts/manage_version_cr.sh create_componentsversion + KUBEAN_TAG=${GITHUB_REF_NAME} KUBESPRAY_TAG=${SPRAY_SHA_SHORT} bash artifacts/manage_version_cr.sh create_offlineversion - name: preparing the python environment uses: actions/setup-python@v4 with: diff --git a/.github/workflows/call-os-pkgs-build.yaml b/.github/workflows/call-os-pkgs-build.yaml index 64ae5fc1f..6ae314c48 100644 --- a/.github/workflows/call-os-pkgs-build.yaml +++ b/.github/workflows/call-os-pkgs-build.yaml @@ -23,7 +23,7 @@ jobs: uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2.0.0 - name: Build OS packages to local uses: docker/build-push-action@v3 diff --git a/.github/workflows/spray-image-build.yaml b/.github/workflows/spray-image-build.yaml deleted file mode 100644 index 5cc09b870..000000000 --- a/.github/workflows/spray-image-build.yaml +++ /dev/null @@ -1,33 +0,0 @@ -name: Kubespray Image Build CI - -on: - workflow_dispatch: - inputs: - kubespray_branch: - description: "branch name" - required: true - default: "master" -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/checkout@v3 - with: - repository: kubernetes-sigs/kubespray - ref: ${{ github.event.inputs.kubespray_branch }} - path: ./kubespray - - name: Log in to registry - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin - - name: Set up Docker Buildx - uses: crazy-max/ghaction-docker-buildx@v1 - with: - buildx-version: latest - - name: Build dockerfile (with push) - run: | - docker buildx build \ - --platform=linux/amd64,linux/arm64 \ - --output "type=image,push=true" \ - --build-arg "KUBESPRAY_BRANCH=${{ github.event.inputs.kubespray_branch }}" \ - --file ./build/images/kubespray/Dockerfile . \ - --tag ghcr.io/${{ github.repository }}/kubespray:"${{ github.event.inputs.kubespray_branch }}" diff --git a/build/images/spray-job/Dockerfile b/build/images/spray-job/Dockerfile index 956dcd347..8e4422151 100644 --- a/build/images/spray-job/Dockerfile +++ b/build/images/spray-job/Dockerfile @@ -1,5 +1,7 @@ -ARG spray_tag=master -FROM ghcr.io/kubean-io/kubean/kubespray:$spray_tag +ARG SPRAY_TAG=master +ARG REPO=kubean-io/kubean + +FROM ghcr.io/${REPO}/kubespray:${SPRAY_TAG} WORKDIR /kubespray