#!/usr/bin/env bash # Usage: tools/build-rootfs [-h] [--base] # # Builds the werkrevisor image and exports its file system # as werkrevisor-rootfs-.tar.zst for hosts without Docker (werkdock). # Run it from the repository root. # It runs with docker, else podman; CONTAINER_ENGINE overrides the choice. # The archive does not keep image metadata; run it with # PATH=/app/.venv/bin:/usr/local/bin:/usr/bin:/bin PYTHONPATH=/werkrevisor:/app PYTHONNOUSERSITE=1 python -s -m werkrevisor # After a successful build it keeps only the two newest archives in the repository directory # and the two newest image tags; each release adds about 183 MB. # With --base it exports only the stage `base` of the Dockerfile (PR-Agent, Node.js and PR Lens), # as werkrevisor-base-.tar.zst, from which tools/release_rootfs.py assembles a release # on a host without a container engine. set -euo pipefail if [[ "${1:-}" =~ ^(-h|-\?|--help)$ ]]; then awk 'NR > 1 && /^#/ { sub(/^# ?/, ""); print; next } NR > 1 { exit }' "$0" exit 0 fi version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' werkrevisor/__init__.py) image="werkrevisor:${version}" archive="werkrevisor-rootfs-${version}.tar.zst" container_engine="${CONTAINER_ENGINE:-$(command -v docker || command -v podman || true)}" [[ -n "$container_engine" ]] || { echo "tools/build-rootfs: neither docker nor podman found; set CONTAINER_ENGINE" >&2; exit 2; } if [[ "${1:-}" == "--base" ]]; then base=$(python3 tools/release_rootfs.py base-name) "$container_engine" build --target base -t werkrevisor-base:latest . container=$("$container_engine" create werkrevisor-base:latest) trap '"$container_engine" rm -f "$container" >/dev/null' EXIT "$container_engine" export "$container" | zstd -q -T0 -10 -f -o "$base" echo "archive: $base ($(du -h "$base" | cut -f1))" sha256sum "$base" exit 0 fi "$container_engine" build -t "$image" . container=$("$container_engine" create "$image") trap '"$container_engine" rm -f "$container" >/dev/null' EXIT "$container_engine" export "$container" | zstd -q -T0 -10 -f -o "$archive" echo "image: $image" echo "archive: $archive ($(du -h "$archive" | cut -f1))" sha256sum "$archive" for old in $(python3 tools/release_files.py 2 -- werkrevisor-rootfs-*.tar.zst); do rm -f -- "$old" echo "removed: $old" done for old in $(python3 tools/release_files.py 2 -- $("$container_engine" images werkrevisor --format 'werkrevisor:{{.Tag}}')); do "$container_engine" rmi "$old" >/dev/null echo "removed: $old" done