Files
cairnobs/scripts/build-image.sh
T
jcoffey-dev 2bc05da433
ci / check (pull_request) Successful in 4m48s
ci / postgres (pull_request) Successful in 9m55s
The image's binaries are executable when built from a download
A release's binaries download as 0644 and the image keeps the mode it's
given, so v0.1.0's first image couldn't start (exec: permission denied).
build-image.sh now makes them executable in its build context, the GitHub
workflow does too after checking them, and the workflow then runs both
binaries from the pushed image and checks their version.
2026-11-15 14:10:02 -07:00

39 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2026 Coffey Labs LLC
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# build-image.sh TAG DIST [IMAGE]: the obs-beacond image for linux/amd64 and
# linux/arm64 from a release's binaries in DIST (scripts/build-release.sh).
# Without IMAGE it writes an OCI archive, DIST/obs-beacond-image-TAG.tar,
# that `skopeo copy oci-archive:...` or `oc image mirror` can push anywhere.
# With IMAGE (e.g. registry.example.org/ops/obs-beacond) it pushes
# IMAGE:VERSION. Needs docker buildx.
#
# Each release's image is published as ghcr.io/coffey-labs/cairnobs by
# .github/workflows/release.yml; this script is how it's built.
set -euo pipefail
TAG="${1:?usage: build-image.sh TAG DIST [IMAGE]}"
DIST="${2:?usage: build-image.sh TAG DIST [IMAGE]}"
IMAGE="${3:-}"
VERSION="${TAG#v}"
for arch in amd64 arm64; do
for bin in obs-beacond obs-beacon-agent; do
[ -f "$DIST/$bin-linux-$arch" ] || { echo "$DIST/$bin-linux-$arch is missing: run scripts/build-release.sh $TAG $DIST first" >&2; exit 1; }
done
done
# A small build context: only what the image holds.
ctx="$(mktemp -d)"; trap 'rm -rf "$ctx"' EXIT
cp LICENSE THIRD_PARTY_NOTICES.md "$DIST"/obs-beacond-linux-{amd64,arm64} "$DIST"/obs-beacon-agent-linux-{amd64,arm64} "$ctx/"
# Binaries downloaded from a release aren't executable, and the image keeps
# the mode it's given.
chmod 0755 "$ctx"/obs-beacond-linux-* "$ctx"/obs-beacon-agent-linux-*
args=(--file deploy/container/Containerfile --platform linux/amd64,linux/arm64
--build-arg "VERSION=$VERSION" --provenance=false)
if [ -n "$IMAGE" ]; then
docker buildx build "${args[@]}" --tag "$IMAGE:$VERSION" --push "$ctx"
else
out="$(cd "$DIST" && pwd)/obs-beacond-image-$TAG.tar"
docker buildx build "${args[@]}" --output "type=oci,dest=$out" "$ctx"
echo "$out"
fi