From eb8d215cf14e3f4d37a3c5e8d03a8d9fa5a4d0a3 Mon Sep 17 00:00:00 2001 From: Daniel Butler Date: Thu, 19 Oct 2023 15:12:25 +0100 Subject: [PATCH] update workflows to build and publish ubi images --- .github/workflows/pull_request.yaml | 45 +++++++++++++++++++++++++++-- .github/workflows/push.yaml | 39 +++++++++++++++++++++++++ Dockerfile.ubi | 2 +- 3 files changed, 83 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index e599287..292355c 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -7,6 +7,7 @@ on: env: DOCKER_FILE_PATH: Dockerfile + UBI_DOCKER_FILE_PATH: Dockerfile.ubi KUBERNETES_VERSION: "1.19.0" KIND_VERSION: "0.17.0" REGISTRY: ghcr.io @@ -82,12 +83,14 @@ jobs: - name: Test run: make test - - name: Generate Tag + - name: Generate Tags id: generate_tag run: | sha=${{ github.event.pull_request.head.sha }} tag="SNAPSHOT-PR-${{ github.event.pull_request.number }}-${sha:0:8}" + ubi_tag="SNAPSHOT-PR-${{ github.event.pull_request.number }}-UBI-${sha:0:8}" echo "GIT_TAG=$(echo ${tag})" >> $GITHUB_OUTPUT + echo "GIT_UBI_TAG=$(echo ${ubi_tag})" >> $GITHUB_OUTPUT - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -122,6 +125,25 @@ jobs: org.opencontainers.image.created=${{ steps.prep.outputs.created }} org.opencontainers.image.revision=${{ github.sha }} + - name: Build and Push Docker UBI Image to Docker registry + uses: docker/build-push-action@v4 + with: + context: . + file: ${{ env.DOCKER_UBI_FILE_PATH }} + pull: true + push: true + build-args: | + BUILD_PARAMETERS=${{ env.BUILD_PARAMETERS }} + BUILDER_IMAGE=${{ env.DOCKER_IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_TAG }} + cache-to: type=inline + platforms: linux/amd64,linux/arm,linux/arm64 + tags: | + ${{ env.DOCKER_IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_UBI_TAG }} + labels: | + org.opencontainers.image.source=${{ github.event.repository.clone_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} + - name: Login to ghcr registry uses: docker/login-action@v2 with: @@ -150,13 +172,32 @@ jobs: org.opencontainers.image.created=${{ steps.prep.outputs.created }} org.opencontainers.image.revision=${{ github.sha }} + - name: Build and Push Docker UBI Image to ghcr registry + uses: docker/build-push-action@v4 + with: + context: . + file: ${{ env.DOCKER_UBI_FILE_PATH }} + pull: true + push: true + build-args: | + BUILD_PARAMETERS=${{ env.BUILD_PARAMETERS }} + BUILDER_IMAGE=${{ env.DOCKER_IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_TAG }} + cache-to: type=inline + platforms: linux/amd64,linux/arm,linux/arm64 + tags: | + ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_UBI_TAG }} + labels: | + org.opencontainers.image.source=${{ github.event.repository.clone_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} + - name: Comment on PR uses: mshick/add-pr-comment@v2 if: always() env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - message-success: '@${{ github.actor }} Image is available for testing. `docker pull ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_TAG }}`' + message-success: '@${{ github.actor }} Images are available for testing. `docker pull ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_TAG }}`\n`docker pull ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.GIT_UBI_TAG }}`' message-failure: '@${{ github.actor }} Yikes! You better fix it before anyone else finds out! [Build](https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}/checks) has Failed!' allow-repeats: true diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index e10c7c8..bad87e7 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -7,6 +7,7 @@ on: env: DOCKER_FILE_PATH: Dockerfile + DOCKER_UBI_FILE_PATH: Dockerfile.ubi KUBERNETES_VERSION: "1.19.0" KIND_VERSION: "0.17.0" HELM_REGISTRY_URL: "https://stakater.github.io/stakater-charts" @@ -111,6 +112,25 @@ jobs: org.opencontainers.image.created=${{ steps.prep.outputs.created }} org.opencontainers.image.revision=${{ github.sha }} + - name: Build and Push Docker UBI Image to Docker registry + uses: docker/build-push-action@v4 + with: + context: . + file: ${{ env.DOCKER_UBI_FILE_PATH }} + pull: true + push: true + build-args: | + BUILD_PARAMETERS=${{ env.BUILD_PARAMETERS }} + BUILDER_IMAGE= ${{ env.DOCKER_IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.new_tag }} + cache-to: type=inline + platforms: linux/amd64,linux/arm,linux/arm64 + tags: | + ${{ env.DOCKER_IMAGE_REPOSITORY }}:ubi-${{ steps.generate_tag.outputs.new_tag }} + labels: | + org.opencontainers.image.source=${{ github.event.repository.clone_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} + - name: Login to ghcr registry uses: docker/login-action@v2 with: @@ -139,6 +159,25 @@ jobs: org.opencontainers.image.created=${{ steps.prep.outputs.created }} org.opencontainers.image.revision=${{ github.sha }} + - name: Build and Push Docker UBI Image to ghcr registry + uses: docker/build-push-action@v4 + with: + context: . + file: ${{ env.DOCKER_FILE_PATH }} + pull: true + push: true + build-args: | + BUILD_PARAMETERS=${{ env.BUILD_PARAMETERS }} + BUILDER_IMAGE= ${{ env.DOCKER_IMAGE_REPOSITORY }}:${{ steps.generate_tag.outputs.new_tag }} + cache-to: type=inline + platforms: linux/amd64,linux/arm,linux/arm64 + tags: | + ${{ env.GHCR_IMAGE_REPOSITORY }}:ubi-${{ steps.generate_tag.outputs.new_tag }} + labels: | + org.opencontainers.image.source=${{ github.event.repository.clone_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} + ############################## ## Add steps to generate required artifacts for a release here(helm chart, operator manifest etc.) ############################## diff --git a/Dockerfile.ubi b/Dockerfile.ubi index d25693c..43ce010 100644 --- a/Dockerfile.ubi +++ b/Dockerfile.ubi @@ -1,7 +1,7 @@ ARG BUILDER_IMAGE ARG BASE_IMAGE -FROM ${BUILDER_IMAGE:-docker.io/stakater/reloader:v1.0.44} as SRC +FROM ${BUILDER_IMAGE} as SRC FROM ${BASE_IMAGE:-registry.access.redhat.com/ubi8/ubi-minimal}