scripts/image-build.sh 4.0 KiB 112 lines Raw
1 #!/bin/sh2 # Build the inf3r OCI image out of band, then import/sign it into a3 # deterministic OCI layout. The release image is the minimal glibc control4 # and probe image from docker/Containerfile.release; docker/release.lock5 # pins the base images.6 #7 #   scripts/image-build.sh <REPO> <VERSION> <TAG> <OUT>8 #9 # INF3R_IMAGE_PLATFORMS defaults to linux/amd64. HU13_BIN selects the hu1310 # executable. HU13_SIGNING_KEY is optional here but required before a11 # publish build. HU13_IMAGE_SOURCE defaults to the public source offer.12 set -eu13 repo="${1:?usage: image-build.sh <REPO> <VERSION> <TAG> <OUT>}"14 version="${2:?usage: image-build.sh <REPO> <VERSION> <TAG> <OUT>}"15 tag="${3:-$version}"16 out="${4:?usage: image-build.sh <REPO> <VERSION> <TAG> <OUT>}"17 name="${INF3R_IMAGE_NAME:-inf3r}"18 commit=$(git -C "$repo" rev-parse HEAD)19 epoch="${SOURCE_DATE_EPOCH:-$(git -C "$repo" show -s --format=%ct "$commit")}"20 created=$(date -u -d "@$epoch" +%Y-%m-%dT%H:%M:%SZ)21 source="${INF3R_IMAGE_SOURCE:-${HU13_IMAGE_SOURCE:-https://inf3r.gl0w.world/repo.git}}"22 platforms="${INF3R_IMAGE_PLATFORMS:-${HU13_IMAGE_PLATFORMS:-linux/amd64}}"23 case "$source" in24     http://*|https://*) ;;25     *) echo "image-build: set INF3R_IMAGE_SOURCE to the canonical http(s) source URL" >&2; exit 2 ;;26 esac27 key="${HU13_SIGNING_KEY:-}"28 if [ -n "${HU13_BIN:-}" ]; then29     hu13_bin="$HU13_BIN"30 elif [ -x "$(dirname "$0")/../target/release/hu13" ]; then31     hu13_bin="$(cd "$(dirname "$0")/.." && pwd)/target/release/hu13"32 elif [ -x "$(dirname "$0")/../../hu13/target/release/hu13" ]; then33     hu13_bin="$(cd "$(dirname "$0")/../../hu13" && pwd)/target/release/hu13"34 else35     hu13_bin=hu1336 fi37 tmp=$(mktemp -d)38 trap 'rm -rf "$tmp"' EXIT INT TERM39 40 # Build one image with the local Docker daemon, then export its OCI layout.41 # The rootless legacy builder on the release host has no OCI exporter, so42 # `docker save` is the portable step; modern Docker writes the OCI layout43 # that hu13 imports.44 image_tag="inf3r-release-build:$$"45 docker build \46     --pull=false \47     --file "$repo/docker/Containerfile.release" \48     --tag "$image_tag" \49     --build-arg "INF3R_VERSION=$version" \50     --build-arg "INF3R_COMMIT=$commit" \51     --build-arg "INF3R_TAG=$tag" \52     --build-arg "HU13_VERSION=$version" \53     --build-arg "HU13_REVISION=$commit" \54     --build-arg "HU13_SOURCE=$source" \55     --build-arg "HU13_CREATED=$created" \56     --build-arg "SOURCE_DATE_EPOCH=$epoch" \57     "$repo"58 docker save "$image_tag" --output "$tmp/image.tar"59 docker image rm "$image_tag" >/dev/null 2>&1 || true60 61 mkdir -p "$tmp/layout" "$tmp/platforms"62 tar -xf "$tmp/image.tar" -C "$tmp/layout"63 python3 "$(dirname "$0")/oci-gzip.py" "$tmp/layout"64 65 layouts=""66 i=067 oldifs=$IFS68 IFS=,69 for platform in $platforms; do70     IFS=$oldifs71     case "$platform" in72         */*) ;;73         *) echo "image-build: invalid platform '$platform'" >&2; exit 2 ;;74     esac75     platform_out="$tmp/platforms/$i"76     set -- "$hu13_bin" image build "$repo" \77         --from-oci "$tmp/layout" \78         --tag "$tag" \79         --version "$version" \80         --commit "$commit" \81         --name "$name" \82         --source "$source" \83         --created "$epoch" \84         --license AGPL-3.0-only \85         --platform "$platform" \86         -o "$platform_out"87     if [ -n "$key" ]; then88         set -- "$@" --signing-key "$key"89     fi90     "$@"91     layouts="$layouts --layout $platform_out"92     i=$((i + 1))93     IFS=,94 done95 IFS=$oldifs96 97 # shellcheck disable=SC2086 # layouts is a deliberately word-split list98 set -- "$hu13_bin" image index $layouts -o "$out"99 if [ -n "$key" ]; then100     set -- "$@" --signing-key "$key"101 fi102 "$@"103 104 # A deliberately generous budget: the runtime + base layers for two arches105 # are large, but an unexpected multi-gigabyte tree should stop a release.106 max="${INF3R_MAX_IMAGE_BYTES:-${HU13_MAX_IMAGE_BYTES:-67108864}}"107 size=$(du -sb "$out" | cut -f1)108 if [ "$size" -gt "$max" ]; then109     echo "image-build: OCI tree is $size bytes (budget $max); set HU13_MAX_IMAGE_BYTES to override" >&2110     exit 1111 fi112 echo "image-build: OCI tree size $size bytes (budget $max)"