build: Tag container images with git branch/sha build information

This commit is contained in:
Brendan Hay 2019-10-05 11:16:59 -07:00
parent 8aeaf1610b
commit 7070650bf6
No known key found for this signature in database
GPG Key ID: 80E915C54A7C457D

View File

@ -12,12 +12,22 @@ say() {
echo "$1" >&2
}
git_sha="$(git rev-parse HEAD)"
git_sha="${git_sha:0:8}"
git_branch="$(git branch --show-current)"
git_tag="${build}:${git_branch}-${git_sha}"
say "Building $build..."
image="$(nix-build default.nix --no-out-link -A $build)"
say "Loading $image into Docker..."
tag="$(docker load --quiet --input $image)"
tag="${tag#Loaded image: }"
nix_tag="$(docker load --quiet --input $image)"
nix_tag="${nix_tag#Loaded image: }"
say "Re-tagging with current git branch:$git_branch SHA:$git_sha"
docker tag $nix_tag $git_tag
# Output only the tag on stdout for subsequent pipes/tooling.
echo $tag
echo $git_tag