Skip to content

ODH-Build-And-Publish-Operator-Image #5

ODH-Build-And-Publish-Operator-Image

ODH-Build-And-Publish-Operator-Image #5

# This is a copy of the publish-core-images.yaml and has been customized to
# use the quay login credentials and RHOAI Dockerfile.
# The unused parts of the original have been commented out on purpose.
name: ODH
on:
workflow_dispatch:
inputs:
branch:
required: true
description: "Branch or tag to build from"
default: "dev"
push_images:
required: true
description: "Whether to push images to registry"
default: "true"
type: choice
options:
- "true"
- "false"
image_tag:
required: false
description: "Additional custom tag for the image (optional)"
default: ""
push:
branches:
- dev
tags:
- '**'
pull_request:
branches:
- dev
jobs:
build-and-publish-operator:
name: Build and (or) Publish Image
runs-on: ubuntu-latest
env:
GOPATH: ${{ github.workspace }}/go
REPO_NAME: ${{ vars.QUAY_REPO_NAME || 'opendatahub' }}
steps:
- name: Environment dump
shell: bash
run: |
echo "GOPATH = ${GOPATH}"
echo "REPO_NAME = ${REPO_NAME}"
echo "Event name = ${{ github.event_name }}"
echo "Branch input = ${{ github.event.inputs.branch }}"
echo "Push images input = ${{ github.event.inputs.push_images }}"
echo "Custom tag input = ${{ github.event.inputs.image_tag }}"
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch || github.ref }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run go mod
shell: bash
run: |
go mod download
# Note: Dockerfile.rhoai builds the binary inside the container, so no pre-build needed
- name: Add docker tags
id: meta
uses: docker/metadata-action@v5
with:
images: quay.io/${{ env.REPO_NAME }}/trainer
tags: |
type=raw,latest
type=ref,event=pr
type=sha,prefix=v1-odh-
type=ref,enable=true,priority=600,prefix=,suffix=,event=tag
type=raw,value=${{ github.event.inputs.image_tag }},enable=${{ github.event.inputs.image_tag != '' }}
- name: Build image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: quay.io/${{ env.REPO_NAME }}/trainer
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
containerfiles: |
cmd/trainer-controller-manager/Dockerfile.rhoai
extra-args: |
--pull
# Check if image is build
- name: Check images created
shell: bash
run: buildah images | grep 'quay.io/${{ env.REPO_NAME }}/trainer'
- name: Check image manifest
shell: bash
run: |
buildah manifest inspect ${{ steps.build-image.outputs.image }}:latest
- name: Check image metadata
shell: bash
run: |
buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.title"'
buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.description"'
buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.title"'
buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.description"'
- name: Login to Quay.io
id: podman-login-quay
# Trigger step only for specific branch (master, v.*-branch) or tag (v.*), or when manually triggered with push_images=true.
if: (github.ref == 'refs/heads/dev' || (startsWith(github.ref, 'refs/heads/v') && endsWith(github.ref, '-branch')) || startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_images == 'true')
shell: bash
run: |
podman login --username ${{ 'rh-ee-knema' }} --password ${{ secrets.MY_QUAY_KEY }} quay.io
- name: Push to Quay.io
if: always() && steps.podman-login-quay.outcome == 'success'
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
- name: Print image url
if: steps.push-to-quay.outcome == 'success'
shell: bash
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
- name: Logout from Quay.io
if: always() && steps.podman-login-quay.outcome == 'success'
run: |
podman logout quay.io