Skip to content

Build and push image #253

Build and push image

Build and push image #253

Workflow file for this run

name: Build and push image
on:
push:
branches:
- 'main'
- 'master'
workflow_dispatch: { }
env:
IMG_TAGS: ${{ github.sha }}
IMG_REGISTRY_HOST: quay.io
IMG_REGISTRY_ORG: kuadrant
MAIN_BRANCH_NAME: main
jobs:
prepare:
name: Prepare build info
runs-on: ubuntu-latest
outputs:
version: ${{ steps.build-info.outputs.version }}
git_sha: ${{ steps.build-info.outputs.git_sha }}
dirty: ${{ steps.build-info.outputs.dirty }}
steps:
- name: Set Authorino build info
id: build-info
run: |
if [[ ${GITHUB_REF_NAME/\//-} =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
tag=${GITHUB_REF_NAME/\//-}
echo "version=${tag#v}" >> $GITHUB_OUTPUT
elif [[ ${GITHUB_REF_NAME/\//-} == "main" ]]; then
echo "version=latest" >> $GITHUB_OUTPUT
else
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
echo "git_sha=${{ github.sha }}" >> $GITHUB_OUTPUT
echo "dirty=false" >> $GITHUB_OUTPUT
build:
name: Build ${{ matrix.platform }}
runs-on: ${{ matrix.runner }}
needs: prepare
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-latest
- platform: linux/s390x
runner: ubuntu-latest
- platform: linux/ppc64le
runner: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to 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 and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
build-args: |
version=${{ needs.prepare.outputs.version }}
git_sha=${{ needs.prepare.outputs.git_sha }}
dirty=${{ needs.prepare.outputs.dirty }}
outputs: type=image,name=${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/authorino,push-by-digest=true,name-canonical=true,push=${{ !env.ACT }}
provenance: false
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ strategy.job-index }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: Create multi-platform manifest
runs-on: ubuntu-latest
needs: [ prepare, build ]
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/authorino
tags: |
type=ref,event=branch
type=raw,value=${{ github.sha }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Login to 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: Create manifest list and push
if: ${{ !env.ACT }}
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/authorino@sha256:%s ' *)
- name: Inspect image
if: ${{ !env.ACT }}
run: |
docker buildx imagetools inspect ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/authorino:${{ needs.prepare.outputs.version }}