Build and push multi-arch Docker image #177
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v3 | |
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@v1 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v1 | |
with: | |
install: true | |
- name: Log in to ghcr.io | |
uses: docker/login-action@v2 | |
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 \ | |
. |