102 lines
2.6 KiB
Bash
Executable File
102 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Dev-parity build script for the ci-fleet-publish plugin image itself
|
|
# (oleks/ci-scripts#14, #15). CI runs this SAME script (cluster #196,
|
|
# emmett#44 convention) so CI and local can't drift; the only CI-specific
|
|
# overrides are BUILDKIT_ADDR (native per-arch remote buildkit) and
|
|
# PUBLISH=1 (local default is dry-run / --load).
|
|
set -euo pipefail
|
|
|
|
IMAGE="git.oleks.space/oleks/ci-fleet-publish"
|
|
PUBLISH="${PUBLISH:-0}"
|
|
VERSION="${CI_COMMIT_TAG:-dev}"
|
|
ARCHES=(amd64 arm64)
|
|
|
|
echo "▸ arch=$(uname -m)"
|
|
|
|
registry_login() {
|
|
if [ -n "${REGISTRY_TOKEN:-}" ]; then
|
|
echo "${REGISTRY_TOKEN}" | docker login git.oleks.space -u oleks --password-stdin
|
|
fi
|
|
}
|
|
|
|
ensure_builder() {
|
|
if [ -n "${BUILDKIT_ADDR:-}" ]; then
|
|
if ! docker buildx inspect ci-fleet-publish >/dev/null 2>&1; then
|
|
docker buildx create --name ci-fleet-publish --driver remote "${BUILDKIT_ADDR}"
|
|
fi
|
|
docker buildx use ci-fleet-publish
|
|
fi
|
|
}
|
|
|
|
usage() {
|
|
echo "usage: $0 --arch ARCH | --manifest" >&2
|
|
exit 1
|
|
}
|
|
|
|
mode=""
|
|
arch=""
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--arch)
|
|
arch="$2"
|
|
mode="build"
|
|
shift 2
|
|
;;
|
|
--manifest)
|
|
mode="manifest"
|
|
shift
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|
|
done
|
|
|
|
case "${mode}" in
|
|
build)
|
|
: "${arch:?--arch required}"
|
|
registry_login
|
|
ensure_builder
|
|
tag="${VERSION}-${arch}"
|
|
push_flag="--load"
|
|
if [ "${PUBLISH}" = "1" ]; then
|
|
push_flag="--push"
|
|
fi
|
|
echo "▸ building ${IMAGE}:${tag} for linux/${arch}"
|
|
docker buildx build --platform "linux/${arch}" "${push_flag}" -t "${IMAGE}:${tag}" .
|
|
;;
|
|
manifest)
|
|
registry_login
|
|
major="${VERSION%%.*}"
|
|
dest_tags=("${VERSION}" "${major}" "latest")
|
|
found=()
|
|
for a in "${ARCHES[@]}"; do
|
|
ref="${IMAGE}:${VERSION}-${a}"
|
|
echo "▸ probing ${ref}"
|
|
if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect "${ref}" >/dev/null 2>&1; then
|
|
echo "▸ found ${ref}"
|
|
found+=("${ref}")
|
|
else
|
|
echo "▸ missing ${ref} (oleks/ci-scripts#9: skip this arch, not the whole manifest)"
|
|
fi
|
|
done
|
|
if [ "${#found[@]}" -eq 0 ]; then
|
|
echo "no per-arch tags landed for ${IMAGE}:${VERSION}; failing manifest step" >&2
|
|
exit 1
|
|
fi
|
|
if [ "${PUBLISH}" != "1" ]; then
|
|
echo "▸ dry-run: would create manifest ${dest_tags[*]} from ${found[*]}"
|
|
exit 0
|
|
fi
|
|
for dest in "${dest_tags[@]}"; do
|
|
dest_ref="${IMAGE}:${dest}"
|
|
echo "▸ creating manifest ${dest_ref} from ${#found[@]}/${#ARCHES[@]} arches"
|
|
docker manifest create "${dest_ref}" "${found[@]}"
|
|
docker manifest push "${dest_ref}"
|
|
done
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|