diff --git a/action.yml b/action.yml index 68d10ac..71ea36a 100644 --- a/action.yml +++ b/action.yml @@ -26,6 +26,7 @@ runs: shell: bash run: | '${{ github.action_path }}/build.bash' . push "$(tr -d v <<<'${{ github.ref_name }}')" + '${{ github.action_path }}/mktags.bash' '${{ github.ref_name }}' - if: github.event_name == 'push' shell: bash diff --git a/build.bash b/build.bash index 5499f0e..259f318 100755 --- a/build.bash +++ b/build.bash @@ -24,9 +24,9 @@ if ! docker buildx version; then false fi -COMMON_ARGS=(-t "icinga/icinga2:$TAG" --build-context "icinga2-git=$(realpath "$I2SRC")/.git" "$(realpath "$(dirname "$0")")") - -BUILDX=(docker buildx build --platform "$(echo linux/{amd64,arm{/v7,64/v8}} |tr ' ' ,)") +OUR_DIR="$(realpath "$(dirname "$0")")" +COMMON_ARGS=(-t "icinga/icinga2:$TAG" --build-context "icinga2-git=$(realpath "$I2SRC")/.git" "$OUR_DIR") +BUILDX=(docker buildx build --platform "$(cat "${OUR_DIR}/platforms.txt")") case "$ACTION" in all) diff --git a/mktags.bash b/mktags.bash new file mode 100755 index 0000000..7deffa4 --- /dev/null +++ b/mktags.bash @@ -0,0 +1,32 @@ +#!/bin/bash +# Icinga 2 Docker image | (c) 2023 Icinga GmbH | GPLv2+ +set -exo pipefail + +if [[ "$1" =~ ^v((([0-9]+).([0-9]+)).[0-9]+)$ ]]; then + XYZ="${BASH_REMATCH[1]}" + XY="${BASH_REMATCH[2]}" + X="${BASH_REMATCH[3]}" + Y="${BASH_REMATCH[4]}" + + BUILDX=(docker buildx build --platform "$(cat "$(realpath "$(dirname "$0")")/platforms.txt")" --push) + cd "$(mktemp -d)" + + echo "FROM icinga/icinga2:$XYZ" >Dockerfile + + "${BUILDX[@]}" -t "icinga/icinga2:$XY" . + + NEXT="${X}.$(($Y+1))" + + case "$(curl --head -sSLo /dev/null -w '%{http_code}' "https://hub.docker.com/v2/namespaces/icinga/repositories/icinga2/tags/$NEXT")" in + 200) + ;; + 404) + "${BUILDX[@]}" -t "icinga/icinga2:$X" . + "${BUILDX[@]}" -t icinga/icinga2 . + ;; + *) + echo "Can't check for icinga/icinga2:$NEXT" + false + ;; + esac +fi diff --git a/platforms.txt b/platforms.txt new file mode 100644 index 0000000..d08026c --- /dev/null +++ b/platforms.txt @@ -0,0 +1 @@ +linux/amd64,linux/arm/v7,linux/arm64/v8