docker-icinga2/action.bash
2020-09-08 17:54:23 +02:00

63 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# Icinga 2 Docker image | (c) 2020 Icinga GmbH | GPLv2+
set -exo pipefail
TARGET=icinga/icinga2
cache () {
INPUT_KEY=docker-image/ccache INPUT_PATH=ccache \
STATE_CACHE_KEY=1 STATE_CACHE_RESULT=2 \
node "/actions/cache/dist/${1}/index.js"
}
mkimg () {
test -n "$TAG"
node /actions/checkout/dist/index.js |grep -vFe ::add-matcher::
cache restore
mkdir -p ccache
ln -vs "$(pwd)/ccache" ~/.ccache
/compile.bash
cache save
docker build -f /Dockerfile -t "${TARGET}:$TAG" .
STATE_isPost=1 node /actions/checkout/dist/index.js
}
push () {
test -n "$TAG"
if [ "$(tr -d '\n' <<<"$DOCKER_HUB_PASSWORD" |wc -c)" -gt 0 ]; then
docker login -u icingaadmin --password-stdin <<<"$DOCKER_HUB_PASSWORD"
docker push "${TARGET}:$TAG"
docker logout
fi
}
case "$GITHUB_EVENT_NAME" in
pull_request)
grep -qEe '^refs/pull/[0-9]+' <<<"$GITHUB_REF"
TAG="pr$(grep -oEe '[0-9]+' <<<"$GITHUB_REF")"
mkimg
;;
push)
grep -qEe '^refs/heads/.' <<<"$GITHUB_REF"
TAG="$(cut -d / -f 3- <<<"$GITHUB_REF")"
mkimg
push
;;
release)
grep -qEe '^refs/tags/v[0-9]' <<<"$GITHUB_REF"
TAG="$(cut -d v -f 2- <<<"$GITHUB_REF")"
mkimg
push
;;
*)
echo "Unknown event: $GITHUB_EVENT_NAME" >&2
false
;;
esac