shrub/sh/image

36 lines
774 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
build=${1:-}
if [[ -z "$build" ]]; then
build="urbit-image"
fi
say() {
echo "$1" >&2
}
git_sha="$(git rev-parse HEAD)"
git_sha="${git_sha:0:8}"
git_branch="$(git branch --show-current)"
git_tag="${git_branch}-${git_sha}"
say "Building $build..."
nix_out="$(nix-build default.nix --no-out-link -A $build)"
say "Loading $nix_out into Docker..."
nix_name="$(docker load --quiet --input $nix_out)"
nix_name="${nix_name#Loaded image: }"
say "Re-tagging with current git branch:$git_branch and SHA:$git_sha"
image_repo="$(docker images $nix_name --format '{{.Repository}}')"
image_name="${image_repo}:${git_tag}"
docker tag $nix_name $image_name
# Output only the tag on stdout for subsequent pipes/tooling.
echo $image_name