2019-10-03 21:19:07 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2019-10-04 21:29:18 +03:00
|
|
|
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-14 10:17:40 +03:00
|
|
|
say "Building nix/ops/image..."
|
|
|
|
nix_out="$(nix-build nix/ops -A image --no-out-link "$@")"
|
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-14 10:17:40 +03:00
|
|
|
say "Re-tagging with git metadata..."
|
2019-10-06 20:44:02 +03:00
|
|
|
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
|
|
|
|
2019-10-14 10:17:40 +03:00
|
|
|
# Output only the new tag on stdout for subsequent pipes/tooling.
|
|
|
|
say $nix_name
|
2019-10-06 20:44:02 +03:00
|
|
|
echo $image_name
|