Skip to content

Build and push container image #24

Build and push container image

Build and push container image #24

name: Build and push container image
on:
workflow_dispatch:
inputs:
release_tags:
required: false
default: "next"
release:
types: [released]
jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set environment
run: |
if [ "${{ github.event_name }}" == "release" ]; then
# https://github.com/orgs/community/discussions/64736
latest_tag=$(
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases/latest |
jq -r '.tag_name'
)
tags=${{ github.ref_name }}
if [ "${latest_tag}" == "${{ github.ref_name }}" ]; then
tags="${tags} latest"
fi
echo "RELEASE_TAGS=${tags}" >> $GITHUB_ENV
else
if [ -z "${{ github.event.inputs.release_tags }}" ]; then
exit 1
fi
echo "RELEASE_TAGS=${{ github.event.inputs.release_tags }}" >> $GITHUB_ENV
fi
- name: Build container image
id: build_image
uses: redhat-actions/buildah-build@v2
with:
containerfiles: ./Containerfile
image: retis
tags: ${{ env.RELEASE_TAGS }}
- name: Push container image
id: push_image
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: quay.io/retis
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Summary
run: |
echo "${{ toJSON(steps.push_image.outputs) }}"