From 029ab254c91df5db3a353f86d537a6f99c35856b Mon Sep 17 00:00:00 2001 From: Huy Mai Date: Tue, 6 Aug 2024 15:35:30 +0300 Subject: [PATCH] Move container build to gh runner Signed-off-by: Huy Mai --- .github/workflows/build-images-action.yml | 106 +++++++++++++++------- 1 file changed, 71 insertions(+), 35 deletions(-) diff --git a/.github/workflows/build-images-action.yml b/.github/workflows/build-images-action.yml index a05c359527..a89a2ee113 100644 --- a/.github/workflows/build-images-action.yml +++ b/.github/workflows/build-images-action.yml @@ -1,12 +1,13 @@ name: build-images-action on: - push: - branches: - - 'main' - - 'release-*' - tags: - - 'v*' + pull_request + # push: + # branches: + # - 'main' + # - 'release-*' + # tags: + # - 'v*' permissions: {} @@ -20,37 +21,72 @@ jobs: if: github.repository == 'metal3-io/baremetal-operator' steps: + + - name: Get branch or tag name + id: get_name + run: | + ref=${{ github.ref }} + if [[ "$ref" == refs/heads/* ]]; then + echo "name=${ref#refs/heads/}" >> $GITHUB_OUTPUT + elif [[ "$ref" == refs/tags/* ]]; then + echo "name=${ref#refs/tags/}" >> $GITHUB_OUTPUT + else + echo "name=$ref" >> $GITHUB_OUTPUT + fi + + - name: Get short SHA + id: get_sha + run: echo "sha=`git rev-parse --short ${{ github.sha }}`" >> $GITHUB_OUTPUT + + - name: Get current date + id: date + run: echo "current_date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + + - name: Get image tags + id: image_tags + run: | + image_tags=$(echo "${{ steps.get_name.outputs.name }}" | sed 's/\//_/') + image_tags="${image_tags} ${{ steps.get_name.outputs.name }}_${{ steps.date.outputs.current_date }}_${{ steps.get_sha.outputs.sha }}" >> $GITHUB_OUTPUT + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + image_tags="${image_tags} latest" >> $GITHUB_OUTPUT + fi + + - name: Echo the image tags + run: echo "${{ steps.image_tags.outputs.image_tags }}" + - name: build bmo image - uses: toptal/jenkins-job-trigger-action@137fff703dd260b52b53d3ba1960396415abc568 # 1.0.2 + uses: philips-software/docker-ci-scripts@v4.5.0 with: - jenkins_url: "https://jenkins.nordix.org/" - jenkins_user: "metal3.bot@gmail.com" - jenkins_token: ${{ secrets.JENKINS_TOKEN }} - job_name: "metal3_baremetal-operator_container_image_building" - job_params: | - { - "BUILD_CONTAINER_IMAGE_GIT_REFERENCE": "${{ github.ref }}" - } - job_timeout: "1000" + dockerfile: "./Dockerfile" + image-name: "baremetal-operator" + tags: "${{ steps.image_tags.outputs.image_tags }}" + env: + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_TOKEN: "${{ secrets.REGISTRY_TOKEN }}" + REGISTRY_URL: quay.io/metal3-io + GITHUB_ORGANIZATION: metal3-io + BUILD_CONTAINER_IMAGE_GIT_REFERENCE": "${{ github.ref }}" + - name: build keepalived image - uses: toptal/jenkins-job-trigger-action@137fff703dd260b52b53d3ba1960396415abc568 # 1.0.2 + uses: philips-software/docker-ci-scripts@v4.5.0 with: - jenkins_url: "https://jenkins.nordix.org/" - jenkins_user: "metal3.bot@gmail.com" - jenkins_token: ${{ secrets.JENKINS_TOKEN }} - job_name: "metal3_keepalived_container_image_building" - job_params: | - { - "BUILD_CONTAINER_IMAGE_GIT_REFERENCE": "${{ github.ref }}" - } - job_timeout: "1000" - - name: Slack Notification on Failure - if: ${{ failure() }} - uses: rtCamp/action-slack-notify@4e5fb42d249be6a45a298f3c9543b111b02f7907 # 2.3.0 + dockerfile: "./resources/keepalived-docker/Dockerfile" + image-name: "keepalived" + tags: ${{ steps.image_tags.outputs.image_tags }} env: - SLACK_TITLE: 'GitHub Action Failed in ${{ github.repository }}' - SLACK_COLOR: '#FF0000' - SLACK_MESSAGE: 'The GitHub Action workflow failed for baremetal operator image build.' - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - SLACK_CHANNEL: metal3-github-actions-notify - SLACK_USERNAME: metal3-github-actions-notify + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_TOKEN: "${{ secrets.REGISTRY_TOKEN }}" + REGISTRY_URL: quay.io/metal3-io + GITHUB_ORGANIZATION: metal3-io + BUILD_CONTAINER_IMAGE_GIT_REFERENCE": "${{ github.ref }}" + + # - name: Slack Notification on Failure + # if: ${{ failure() }} + # uses: rtCamp/action-slack-notify@4e5fb42d249be6a45a298f3c9543b111b02f7907 # 2.3.0 + # env: + # SLACK_TITLE: 'GitHub Action Failed in ${{ github.repository }}' + # SLACK_COLOR: '#FF0000' + # SLACK_MESSAGE: 'The GitHub Action workflow failed for baremetal operator image build.' + # SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + # SLACK_CHANNEL: metal3-github-actions-notify + # SLACK_USERNAME: metal3-github-actions-notify