Skip to content

Build and push images #300

Build and push images

Build and push images #300

Workflow file for this run

name: Build and push images
on:
push:
branches:
- 'main'
- 'master'
workflow_dispatch:
inputs:
authorinoVersion:
description: Authorino version
required: true
default: latest
channels:
description: Bundle and catalog channels, comma separated
required: true
default: stable
env:
IMG_REGISTRY_HOST: quay.io
IMG_REGISTRY_ORG: kuadrant
MAIN_BRANCH_NAME: main
OPERATOR_NAME: authorino-operator
BUILD_CONFIG_FILE: build.yaml
LATEST_AUTHORINO_GITREF: ${{ vars.AUTHORINO_SHA != '' && vars.AUTHORINO_SHA || 'latest' }}
jobs:
build:
name: Build and push image
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set Operator version
id: operator-version
run: |
if [[ ${GITHUB_REF_NAME/\//-} =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
echo "VERSION=${GITHUB_REF_NAME/\//-}" >> $GITHUB_ENV
else
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ env.OPERATOR_NAME }}
tags: |
type=raw,value=${{ github.sha }}
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch,enable={{is_not_default_branch}}
- name: Install yq dependency
run: make yq
- name: Set default authorino image
run: |
echo "DEFAULT_AUTHORINO_IMAGE=$(./bin/yq e -e '.config.authorinoImage' ${{ env.BUILD_CONFIG_FILE }} || echo ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/authorino:${{ env.LATEST_AUTHORINO_GITREF }})" >> $GITHUB_ENV
- name: Login to Container Registry
if: ${{ !env.ACT }}
uses: docker/login-action@v3
with:
registry: ${{ env.IMG_REGISTRY_HOST }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}
- name: Build Image
id: build-image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
push: ${{ !env.ACT }}
tags: ${{ steps.meta.outputs.tags }}
build-args: |
OPERATOR_VERSION=${{ env.VERSION }}
GIT_SHA=${{ github.sha }}
DIRTY=false
DEFAULT_AUTHORINO_IMAGE=${{ env.DEFAULT_AUTHORINO_IMAGE }}
provenance: false
- name: Print Image URL
run: |
echo "Image(s) pushed:"
echo "${{ steps.meta.outputs.tags }}"
build-bundle:
needs: build
name: Build and push bundle image
runs-on: ubuntu-latest
if: github.ref_name == 'main' || startsWith(github.ref, 'refs/tags/v') # We cannot use `env.MAIN_BRANCH_NAME` because `env` context is not available to `job.if`. See https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
id: go
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set Operator version
id: operator-version
run: |
tag=${GITHUB_REF_NAME}
if [[ ${tag} =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
echo "VERSION=${tag#v}" >> $GITHUB_ENV
else
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ env.OPERATOR_NAME }}-bundle
tags: |
type=raw,value=${{ github.sha }}
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch,enable={{is_not_default_branch}}
- name: Run make bundle (main)
if: ${{ github.ref_name == env.MAIN_BRANCH_NAME }}
run: make bundle REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} IMAGE_TAG=${{ github.sha }} AUTHORINO_VERSION=${{ env.LATEST_AUTHORINO_GITREF }}
- name: Run make bundle (release)
if: ${{ github.ref_name != env.MAIN_BRANCH_NAME }}
run: make bundle REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} VERSION=${{env.VERSION}} AUTHORINO_VERSION=${{ github.event.inputs.authorinoVersion }} CHANNELS=${{ github.event.inputs.channels }} DEFAULT_CHANNEL=stable
- name: Git diff
run: git diff
- name: Verify manifests and bundle (main)
if: github.ref_name == env.MAIN_BRANCH_NAME
run: make verify-manifests verify-bundle REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} IMAGE_TAG=${{ github.sha }} AUTHORINO_VERSION=${{ env.LATEST_AUTHORINO_GITREF }}
- name: Verify manifests and bundle (release)
if: ${{ github.ref_name != env.MAIN_BRANCH_NAME }}
run: make verify-manifests verify-bundle REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} VERSION=${{env.VERSION}} AUTHORINO_VERSION=${{ github.event.inputs.authorinoVersion }} CHANNELS=${{ github.event.inputs.channels }} DEFAULT_CHANNEL=stable
- name: Login to Container Registry
if: ${{ !env.ACT }}
uses: docker/login-action@v3
with:
registry: ${{ env.IMG_REGISTRY_HOST }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}
- name: Build Image
id: build-image
uses: docker/build-push-action@v5
with:
context: .
file: ./bundle.Dockerfile
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
push: ${{ !env.ACT }}
tags: ${{ steps.meta.outputs.tags }}
build-args: |
version=${{ env.VERSION }}
provenance: false
- name: Print Image URL
run: |
echo "Image(s) pushed:"
echo "${{ steps.meta.outputs.tags }}"
build-catalog:
name: Build and push catalog image
needs: [ build, build-bundle ]
runs-on: ubuntu-latest
if: github.ref_name == 'main' || startsWith(github.ref, 'refs/tags/v') # We cannot use `env.MAIN_BRANCH_NAME` because `env` context is not available to `job.if`. See https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
id: go
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set Operator version
id: operator-version
run: |
tag=${GITHUB_REF_NAME}
if [[ ${tag} =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
echo "VERSION=${tag#v}" >> $GITHUB_ENV
else
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ env.OPERATOR_NAME }}-catalog
tags: |
type=raw,value=${{ github.sha }}
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch,enable={{is_not_default_branch}}
- name: Run make catalog (main)
if: ${{ github.ref_name == env.MAIN_BRANCH_NAME }}
run: |
make catalog \
REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} \
VERSION=${{ env.VERSION }} \
IMAGE_TAG=${{ github.sha }} \
AUTHORINO_VERSION=${{ env.LATEST_AUTHORINO_GITREF }} \
CHANNELS=${{ inputs.channels }}
- name: Run make catalog (release)
if: ${{ github.ref_name != env.MAIN_BRANCH_NAME }}
run: |
make catalog \
REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} \
VERSION=${{ env.VERSION }} \
AUTHORINO_VERSION=${{ github.event.inputs.authorinoVersion }} \
CHANNELS=${{ inputs.channels }}
- name: Git diff
run: git diff
- name: Login to Container Registry
if: ${{ !env.ACT }}
uses: docker/login-action@v3
with:
registry: ${{ env.IMG_REGISTRY_HOST }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}
- name: Build Image
id: build-image
uses: docker/build-push-action@v5
with:
context: ./catalog
file: ./catalog/${{ env.OPERATOR_NAME }}-catalog.Dockerfile
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
push: ${{ !env.ACT }}
tags: ${{ steps.meta.outputs.tags }}
provenance: false
- name: Print Image URL
run: |
echo "Image(s) pushed:"
echo "${{ steps.meta.outputs.tags }}"