#!/usr/bin/env bash # The release's OCI images: the relay's and the room service's, each built from its Containerfile, # held to its check-image.sh, and pushed to a registry. # # bash wai/quickstart/release-images.sh # # Builds joule-code/joule-code-rs/crates/joule-moq-relay/deploy/Containerfile and # .../joule-moq-room/deploy/Containerfile from this checkout, runs the relay's check-image.sh on the # relay's image and then the room service's on the service's beside it (the clock connected to that # relay), and only when both pass saves each image and pushes it with wai/quickstart/oci-push.py # as /wai-relay: and /wai-room: to (its base URL), for # the platform of the engine's host. An image that fails its check is not pushed, nor is the # other. The images built are removed at the end. # # ENGINE is the container engine's command (default: the first of the two the check-image.sh # scripts take that is on PATH); JOBS bounds the builds. RELAY_IMAGE and ROOM_IMAGE check and push # those images instead of building them. # The registry's credentials are oci-push.py's (OCI_USER, OCI_TOKEN, OCI_TOKEN_URL). set -euo pipefail die() { echo "release-images: $*" >&2; exit 1; } [ $# -eq 3 ] || { echo "usage: bash wai/quickstart/release-images.sh " >&2; exit 2; } V="$1" REG="$2" OWNER="$3" ROOT=$(cd "$(dirname "$0")/../.." && pwd) CRATES="$ROOT/joule-code/joule-code-rs/crates" ENGINE=${ENGINE:-$(command -v docker || command -v podman || true)} [ -n "$ENGINE" ] || die "no container engine on PATH (ENGINE names one)" "$ENGINE" info >/dev/null 2>&1 || die "$ENGINE does not reach its engine" export ENGINE case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; aarch64 | arm64) arch=arm64 ;; *) die "no image platform for $(uname -m)" ;; esac T=$(mktemp -d) made=() cleanup() { for i in ${made[@]+"${made[@]}"}; do "$ENGINE" image rm -f "$i" >/dev/null 2>&1 || true; done rm -rf "$T" } trap cleanup EXIT port() { python3 -I -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])'; } relay=${RELAY_IMAGE:-wai-relay-release:$V-$$} room=${ROOM_IMAGE:-wai-room-release:$V-$$} if [ -n "${RELAY_IMAGE:-}" ]; then IMAGE="$relay" VERSION="$V" PORT=$(port) bash "$CRATES/joule-moq-relay/deploy/check-image.sh" else made+=("$relay") TAG="$relay" KEEP=1 VERSION="$V" PORT=$(port) bash "$CRATES/joule-moq-relay/deploy/check-image.sh" fi || die "the relay's image did not pass its check: nothing is pushed" if [ -n "${ROOM_IMAGE:-}" ]; then IMAGE="$room" RELAY_IMAGE="$relay" VERSION="$V" PORT=$(port) bash "$CRATES/joule-moq-room/deploy/check-image.sh" else made+=("$room") TAG="$room" KEEP=1 RELAY_IMAGE="$relay" VERSION="$V" PORT=$(port) bash "$CRATES/joule-moq-room/deploy/check-image.sh" fi || die "the room service's image did not pass its check: nothing is pushed" for pair in "wai-relay=$relay" "wai-room=$room"; do name=${pair%%=*} image=${pair#*=} if [ "$(basename "$ENGINE")" = podman ]; then "$ENGINE" save --format oci-archive -o "$T/$name.tar" "$image" else "$ENGINE" save -o "$T/$name.tar" "$image" fi python3 -I "$ROOT/wai/quickstart/oci-push.py" "$T/$name.tar" "$REG" "$OWNER/$name" "$V" --platform "linux/$arch" done echo "release-images: $OWNER/wai-relay:$V and $OWNER/wai-room:$V (linux/$arch) pushed to $REG"