From 2d4f94db1ca6afbb30334d943ca075856e1505b9 Mon Sep 17 00:00:00 2001 From: Andrea Lamparelli Date: Wed, 21 Feb 2024 10:22:06 +0100 Subject: [PATCH] ci: automate image build and tag --- .github/actions/build/action.yaml | 33 +++++++++++++++++++ .github/workflows/build-master.yaml | 51 +++++++++++++++++++++++++++++ .github/workflows/build-pr.yaml | 40 ++++++++++++++++++++++ .github/workflows/build.yaml | 31 ------------------ 4 files changed, 124 insertions(+), 31 deletions(-) create mode 100644 .github/actions/build/action.yaml create mode 100644 .github/workflows/build-master.yaml create mode 100644 .github/workflows/build-pr.yaml delete mode 100644 .github/workflows/build.yaml diff --git a/.github/actions/build/action.yaml b/.github/actions/build/action.yaml new file mode 100644 index 000000000..e41e35f5e --- /dev/null +++ b/.github/actions/build/action.yaml @@ -0,0 +1,33 @@ +name: "Create a container build" +description: "This workflow can be used to create a container build from source branches." +inputs: + QUAY_ORG: + description: "Quay organization." + default: "opendatahub" + required: false + IMAGE_REPO: + description: "Quay image repo name." + required: true + IMAGE_TAG: + description: "Quay image tag." + required: true + DOCKERFILE: + description: "Dockerfile." + default: "Dockerfile.redhat" + required: false +runs: + using: "composite" + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ env.SOURCE_BRANCH }} + path: build + - name: Build image + shell: bash + working-directory: build + env: + DOCKER_IMAGE_REPO: quay.io/${{ inputs.QUAY_ORG }}/${{ inputs.IMAGE_REPO }} + DOCKER_IMAGE_TAG: ${{ inputs.IMAGE_TAG }} + DOCKER_FILE: ${{ inputs.DOCKERFILE }} + run: | + ./ml_metadata/tools/docker_server/build_docker_image.sh \ No newline at end of file diff --git a/.github/workflows/build-master.yaml b/.github/workflows/build-master.yaml new file mode 100644 index 000000000..252cc1b34 --- /dev/null +++ b/.github/workflows/build-master.yaml @@ -0,0 +1,51 @@ +name: Build MLMD gRPC Server image for Master branch +on: + push: + branches: + - master +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +env: + QUAY_ORG: opendatahub + QUAY_ID: ${{ secrets.QUAY_USERNAME }} + QUAY_TOKEN: ${{ secrets.QUAY_PASSWORD }} + MLMD_IMAGE_REPO: mlmd-grpc-server + MLMD_IMAGE_DOCKERFILE: Dockerfile.redhat + SOURCE_BRANCH: master + +jobs: + build-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Generate Tag + shell: bash + id: tags + run: | + commit_sha=${{ github.event.after }} + tag=main-${commit_sha:0:7} + echo "tag=${tag}" >> $GITHUB_OUTPUT + - name: Build Image + uses: ./.github/actions/build + with: + QUAY_ORG: ${{ env.QUAY_ORG }} + IMAGE_REPO: ${{ env.MLMD_IMAGE_REPO }} + IMAGE_TAG: ${{ steps.tags.outputs.tag }} + DOCKERFILE: ${{ env.MLMD_IMAGE_DOCKERFILE }} + - name: Login to Quay + uses: docker/login-action@v3 + with: + registry: quay.io + username: ${{ env.QUAY_ID }} + password: ${{ env.QUAY_TOKEN }} + - name: Push Images + env: + IMG: quay.io/${{ env.QUAY_ORG }}/${{ env.MLMD_IMAGE_REPO }} + MAIN_HASH_TAG: ${{ steps.tags.outputs.tag }} + run: | + docker push ${IMG}:${MAIN_HASH_TAG} + docker tag ${IMG}:${MAIN_HASH_TAG} ${IMG}:latest + docker push ${IMG}:latest + docker tag ${IMG}:${MAIN_HASH_TAG} ${IMG}:main + docker push ${IMG}:main diff --git a/.github/workflows/build-pr.yaml b/.github/workflows/build-pr.yaml new file mode 100644 index 000000000..ccb16ecfe --- /dev/null +++ b/.github/workflows/build-pr.yaml @@ -0,0 +1,40 @@ +name: Container Image Build +on: + pull_request: + paths-ignore: + - 'LICENSE*' + - '**.gitignore' + - '**.md' + - '**.txt' + - '.github/ISSUE_TEMPLATE/**' + - '.github/dependabot.yml' + - 'docs/**' +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref }} + cancel-in-progress: true +env: + QUAY_ORG: opendatahub + QUAY_ID: ${{ secrets.QUAY_USERNAME }} + QUAY_TOKEN: ${{ secrets.QUAY_PASSWORD }} + MLMD_IMAGE_REPO: mlmd-grpc-server + MLMD_IMAGE_DOCKERFILE: Dockerfile.redhat + SOURCE_BRANCH: ${{ github.ref }} +jobs: + build-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Generate Tag + shell: bash + id: tags + run: | + commit_sha=${{ github.event.after }} + tag=main-${commit_sha:0:7} + echo "tag=${tag}" >> $GITHUB_OUTPUT + - name: Build Image + uses: ./.github/actions/build + with: + QUAY_ORG: ${{ env.QUAY_ORG }} + IMAGE_REPO: ${{ env.MLMD_IMAGE_REPO }} + IMAGE_TAG: ${{ steps.tags.outputs.tag }} + DOCKERFILE: ${{ env.MLMD_IMAGE_DOCKERFILE }} \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 90b09f3f0..000000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,31 +0,0 @@ -name: Container Image Build -on: - pull_request: - paths-ignore: - - 'LICENSE*' - - '**.gitignore' - - '**.md' - - '**.txt' - - '.github/ISSUE_TEMPLATE/**' - - '.github/dependabot.yml' - - 'docs/**' - -jobs: - build-image: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Generate Tag - shell: bash - id: tags - run: | - commit_sha=${{ github.event.after }} - tag=main-${commit_sha:0:7} - echo "tag=${tag}" >> $GITHUB_OUTPUT - - name: Build Image - shell: bash - env: - DOCKER_IMAGE_REPO: quay.io/opendatahub/mlmd-grpc-server - DOCKER_IMAGE_TAG: ${{ steps.tags.outputs.tag }} - DOCKER_FILE: Dockerfile.redhat - run: ./ml_metadata/tools/docker_server/build_docker_image.sh \ No newline at end of file