From 7844cb57aa6b6aa735394f49e15813fa5f6239a2 Mon Sep 17 00:00:00 2001 From: William Boman Date: Sun, 19 Mar 2023 19:52:16 +0100 Subject: [PATCH] ci: embed build & push script in workflow (#154) This is to make it possible to build previous versions via the workflow_dispatch event. --- .github/workflows/docker-image-push.yml | 30 ++++++++++++++++++++++- scripts/build-and-push.sh | 32 ------------------------- 2 files changed, 29 insertions(+), 33 deletions(-) delete mode 100755 scripts/build-and-push.sh diff --git a/.github/workflows/docker-image-push.yml b/.github/workflows/docker-image-push.yml index d743f30..47e7b57 100644 --- a/.github/workflows/docker-image-push.yml +++ b/.github/workflows/docker-image-push.yml @@ -58,4 +58,32 @@ jobs: - name: Build Docker image env: PLATFORMS: linux/amd64,linux/arm64/v8,linux/arm/v7 - run: ./scripts/build-and-push.sh + run: | + set -euo 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 \ + --push \ + --platform "${PLATFORMS}" \ + "${TAGS[@]}" \ + --file Dockerfile \ + . diff --git a/scripts/build-and-push.sh b/scripts/build-and-push.sh deleted file mode 100755 index 9ab600b..0000000 --- a/scripts/build-and-push.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash -# Script executed by GitHub actions. - -set -euo 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 \ - --push \ - --platform "${PLATFORMS}" \ - "${TAGS[@]}" \ - --file Dockerfile \ - .