2019-10-03 21:19:07 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2019-10-04 21:29:18 +03:00
|
|
|
build=${1:-}
|
2019-10-03 21:19:07 +03:00
|
|
|
|
2019-10-04 21:29:18 +03:00
|
|
|
if [[ -z "$build" ]]; then
|
|
|
|
build="urbit-image"
|
|
|
|
fi
|
|
|
|
|
|
|
|
say() {
|
|
|
|
echo "$1" >&2
|
|
|
|
}
|
|
|
|
|
2019-10-05 21:16:59 +03:00
|
|
|
git_sha="$(git rev-parse HEAD)"
|
|
|
|
git_sha="${git_sha:0:8}"
|
|
|
|
|
|
|
|
git_branch="$(git branch --show-current)"
|
|
|
|
|
2019-10-06 20:44:02 +03:00
|
|
|
git_tag="${git_branch}-${git_sha}"
|
2019-10-05 21:16:59 +03:00
|
|
|
|
2019-10-04 21:29:18 +03:00
|
|
|
say "Building $build..."
|
2019-10-06 20:44:02 +03:00
|
|
|
nix_out="$(nix-build default.nix --no-out-link -A $build)"
|
2019-10-04 21:29:18 +03:00
|
|
|
|
2019-10-06 20:44:02 +03:00
|
|
|
say "Loading $nix_out into Docker..."
|
|
|
|
nix_name="$(docker load --quiet --input $nix_out)"
|
|
|
|
nix_name="${nix_name#Loaded image: }"
|
2019-10-05 21:16:59 +03:00
|
|
|
|
2019-10-06 20:44:02 +03:00
|
|
|
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
|
2019-10-04 21:29:18 +03:00
|
|
|
|
|
|
|
# Output only the tag on stdout for subsequent pipes/tooling.
|
2019-10-06 20:44:02 +03:00
|
|
|
echo $image_name
|