Skip to content

Build and push multi-arch Docker image #214

Build and push multi-arch Docker image

Build and push multi-arch Docker image #214

name: Build and push multi-arch Docker image
on:
schedule:
- cron: '0 9 * * FRI'
release:
types: [published]
workflow_dispatch:
inputs:
tag:
type: string
description: Which tag to rebuild and push.
required: true
permissions:
contents: read
packages: write
jobs:
build:
name: Build
# We want a newer version of qemu: https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1815100
runs-on: ubuntu-20.04
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout latest stable release
if: ${{ github.event_name == 'schedule' }}
run: git checkout "$(git tag -l | grep -E "^[0-9]*\.[0-9]*\.[0-9]*$" | tail -n 1)"
- name: Checkout provided tag
if: ${{ inputs.tag }}
run: git checkout "${{ inputs.tag }}"
- name: Docker login
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin docker.io
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Log in to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
env:
PLATFORMS: linux/amd64,linux/arm64/v8,linux/arm/v7
run: |
set -euxo pipefail
VERSION="$(git describe --exact-match --tags HEAD)"
TAG="$VERSION"
MAJOR_TAG="$(sed -nre 's/^([0-9]+).*/\1/p' <<< "$VERSION")"
DOCKERHUB_IMAGE="thelounge/thelounge"
GITHUB_IMAGE="ghcr.io/thelounge/thelounge"
TAGS=(
"--tag" "${DOCKERHUB_IMAGE}:${TAG}"
"--tag" "${GITHUB_IMAGE}:${TAG}"
)
# If not a pre-release push :latest & MAJOR_TAG
if grep -qE "^[0-9]*\.[0-9]*\.[0-9]*$" <<< "${VERSION}"; then
TAGS+=(
"--tag" "${DOCKERHUB_IMAGE}:latest"
"--tag" "${DOCKERHUB_IMAGE}:${MAJOR_TAG}"
"--tag" "${GITHUB_IMAGE}:latest"
"--tag" "${GITHUB_IMAGE}:${MAJOR_TAG}"
)
fi
docker buildx build \
--label org.opencontainers.artifact.created="$(date --rfc-3339=seconds --utc)" \
--push \
--platform "${PLATFORMS}" \
"${TAGS[@]}" \
--file Dockerfile \
.