Files
faerro-kb/scripts/publish-image.sh
T

30 lines
859 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
image="gitea.faerro.it/andrea/faerro-kb"
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if ! command -v docker >/dev/null 2>&1; then
echo "Docker is required to build and publish the image." >&2
exit 1
fi
if ! command -v git >/dev/null 2>&1; then
echo "Git is required to determine the release version." >&2
exit 1
fi
tag="$(git -C "$repo_root" describe --tags --exact-match HEAD 2>/dev/null || true)"
version="${tag#v}"
if [[ ! "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "The checked-out commit must have a SemVer tag (for example, 0.0.2 or v0.0.2)." >&2
exit 1
fi
cd "$repo_root"
docker build --tag "$image:$version" --tag "$image:latest" .
docker push "$image:$version"
docker push "$image:latest"
echo "Published $image:$version and $image:latest"