Skip to content

Build and push OCI image #964

Build and push OCI image

Build and push OCI image #964

Workflow file for this run

name: Build and push OCI image
on:
schedule:
- cron: '5 3 * * *' # UTC
push:
branches:
- master
- '[0-9].[0-9]'
- '[0-9].[0-9]p[0-9]'
workflow_dispatch:
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: -e SC3037
- name: Max. 79 characters per line
run: |
wc -L *.sh | sort -nr
MLL=$(gawk '{ if(length > L) { L=length } } END { print L }' *.sh)
(( ${MLL:-80} <= 79 )) || exit 1
main:
needs: shellcheck
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=openbgpd/openbgpd
QUAY_IMAGE=quay.io/openbgpd/openbgpd
TAG=noop
PORTABLE_COMMIT=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
TAG=edge
PORTABLE_COMMIT=master
elif [[ ${GITHUB_REF} == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
PORTABLE_COMMIT=${TAG}
elif [[ ${GITHUB_REF} == refs/heads/* ]]; then
TAG=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
PORTABLE_COMMIT=${TAG}
if [ "${{ github.event.repository.default_branch }}" = "${TAG}" ]; then
TAG=edge
PORTABLE_COMMIT=master
fi
fi
TAGS="${DOCKER_IMAGE}:${TAG},${QUAY_IMAGE}:${TAG}"
if [[ $TAG =~ ^[0-9]{1,3}\.[0-9]{1,3}(p[0-9]{1,3})*$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest,${QUAY_IMAGE}:latest"
BUILD_ARGS="VERSION=${TAG}"
else
BUILD_ARGS="PORTABLE_COMMIT=${PORTABLE_COMMIT}"
fi
echo "version=${TAG}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "args=${BUILD_ARGS}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Quay Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/riscv64,linux/s390x
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
build-args: ${{ steps.prep.outputs.args }}
labels: |
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.label-schema.version=${{ steps.prep.outputs.version }}
org.label-schema.build-date=${{ steps.prep.outputs.created }}
org.label-schema.vcs-ref=${{ github.sha }}
provenance: false