🐸 Frogue(Fed)

~ololduck/Frogue

Raw

#!/usr/bin/env bash
# Build the Frogue container image, deriving the version label from
# `frogue/Cargo.toml` so the image metadata cannot drift from the workspace
# manifest. Any extra arguments are forwarded to `podman build`.

set -euo pipefail

if ! command -v podman >/dev/null; then
	echo "build-container.sh: podman is required" >&2
	exit 1
fi

root="${FROGUE_ROOT:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}"
cd "$root"

if [ ! -f frogue/Cargo.toml ]; then
	echo "build-container.sh: $root is not a frogue checkout (no frogue/Cargo.toml)" >&2
	exit 1
fi

# Extract the first `version = "..."` under `[package]` in frogue/Cargo.toml.
# sed with `n` skips the header, then the first match is taken and the quotes
# stripped. A toml parser would be stricter, but none is a guaranteed runtime
# dependency and this file is not hand-edited enough to fool the pattern.
version=$(awk '
  /^\[package\]/ { in_pkg=1; next }
  /^\[/ { in_pkg=0 }
  in_pkg && /^version[[:space:]]*=/ {
    gsub(/^version[[:space:]]*=[[:space:]]*"/, "")
    gsub(/".*$/, "")
    print
    exit
  }
' frogue/Cargo.toml)

if [ -z "$version" ]; then
	echo "build-container.sh: could not extract version from frogue/Cargo.toml" >&2
	exit 1
fi

echo "build-container.sh: building frogue:${version}" >&2
exec podman build \
	--build-arg "FROGUE_VERSION=${version}" \
	-f Containerfile \
	-t "frogue:${version}" \
	"$@"