UnisKB/deploy_artifacts/build-release.sh

29 lines
1.9 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
ROOT=$(cd "$(dirname "$0")/.." && pwd)
MINERU_ROOT=${MINERU_ROOT:-$(cd "$ROOT/../markitdown" && pwd)}
VERSION=${VERSION:?Set an immutable VERSION, e.g. refact-20261106-1}
GPU_FLAVOR=${GPU_FLAVOR:?Set GPU_FLAVOR=cuda or corex}
[[ "$VERSION" =~ ^[a-zA-Z0-9_][a-zA-Z0-9_.-]*$ ]] || exit 2
case "$GPU_FLAVOR" in cuda|corex) ;; *) echo 'GPU_FLAVOR must be cuda or corex' >&2; exit 2 ;; esac
for item in "$ROOT:v3.2-refact" "$MINERU_ROOT:develop-refact"; do
repo=${item%:*}; branch=${item##*:}
test "$(git -C "$repo" branch --show-current)" = "$branch" || { echo "Wrong source branch: $branch required" >&2; exit 2; }
test -z "$(git -C "$repo" status --porcelain --untracked-files=normal)" || {
echo "Source tree is dirty. Commit release sources and exclude local outputs before building: $repo" >&2; exit 2;
}
done
OUT=${ARTIFACT_DIR:-$ROOT/deploy_artifacts/releases/$VERSION-$GPU_FLAVOR}
test ! -e "$OUT" || { echo 'Artifact directory already exists' >&2; exit 2; }
mkdir -p "$OUT"
docker build -f "$ROOT/deploy_artifacts/Dockerfile.kb" --build-arg RELEASE_VERSION="$VERSION" \
--build-arg GITHUB_COMMIT="$(git -C "$ROOT" rev-parse HEAD)" -t "unis-kb:$VERSION" "$ROOT"
docker build -f "$ROOT/deploy_artifacts/gateway/Dockerfile" -t "unis-gateway:$VERSION" "$ROOT/deploy_artifacts/gateway"
API_FLAVOR="$GPU_FLAVOR" VERSION="$VERSION" bash "$MINERU_ROOT/scripts/build-images.sh"
docker save -o "$OUT/images.tar" "unis-kb:$VERSION" "unis-gateway:$VERSION" "unis-mineru:$VERSION-$GPU_FLAVOR"
cp "$ROOT/deploy_artifacts/upgrade.py" "$ROOT/deploy_artifacts/README_UPGRADE.md" "$OUT/"
printf 'MAXKB_COMMIT=%s\nMINERU_COMMIT=%s\nVERSION=%s\nGPU_FLAVOR=%s\n' \
"$(git -C "$ROOT" rev-parse HEAD)" "$(git -C "$MINERU_ROOT" rev-parse HEAD)" "$VERSION" "$GPU_FLAVOR" > "$OUT/SOURCES.txt"
(cd "$OUT" && sha256sum images.tar upgrade.py README_UPGRADE.md SOURCES.txt > SHA256SUMS.txt)
echo "Offline release created: $OUT"