#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) ROOT=${MAXKB_ROOT:-$(cd "$SCRIPT_DIR/.." && pwd)} TOOLS_DIR=${RELEASE_TOOLS_DIR:-$ROOT/deploy_artifacts} 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} BUILD_NETWORK=${BUILD_NETWORK:-default} [[ "$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-mineru-2.7.6"; 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 --network "$BUILD_NETWORK" -f "$TOOLS_DIR/Dockerfile.kb" --build-arg UV_INDEX_URL --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" case "$GPU_FLAVOR" in cuda) parser_dockerfile="$TOOLS_DIR/Dockerfile.mineru.cuda.slim" ;; corex) parser_dockerfile="$TOOLS_DIR/Dockerfile.mineru.corex" ;; esac docker build --network "$BUILD_NETWORK" -f "$parser_dockerfile" --build-arg UV_INDEX_URL --build-arg PIP_INDEX_URL --build-arg "BASE_IMAGE=${CUDA_BASE_IMAGE:-unis-mindmap-api:cuda}" \ --label io.unis.component=parser --label io.unis.layout=refact \ --label "io.unis.gpu=$GPU_FLAVOR" \ --label "org.opencontainers.image.revision=$(git -C "$MINERU_ROOT" rev-parse HEAD)" \ -t "unis-mineru:$VERSION-$GPU_FLAVOR" "$MINERU_ROOT" docker save "unis-kb:$VERSION" | gzip -1 > "$OUT/unis-kb.tar.gz" docker save "unis-gateway:$VERSION" | gzip -1 > "$OUT/unis-gateway.tar.gz" docker save "unis-mineru:$VERSION-$GPU_FLAVOR" | gzip -1 > "$OUT/unis-mineru-$GPU_FLAVOR.tar.gz" cp "$TOOLS_DIR/upgrade.py" "$TOOLS_DIR/seed_local_v2_parsers.py" "$TOOLS_DIR/README_UPGRADE_276.md" "$TOOLS_DIR/build-release.sh" "$TOOLS_DIR/Dockerfile.kb" "$TOOLS_DIR/Dockerfile.kb.dockerignore" "$TOOLS_DIR/Dockerfile.mineru.cuda.slim" "$TOOLS_DIR/Dockerfile.mineru.cuda.slim.dockerignore" "$TOOLS_DIR/Dockerfile.mineru.corex" "$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 unis-*.tar.gz upgrade.py seed_local_v2_parsers.py README_UPGRADE_276.md build-release.sh Dockerfile.kb Dockerfile.kb.dockerignore Dockerfile.mineru.cuda.slim Dockerfile.mineru.cuda.slim.dockerignore Dockerfile.mineru.corex SOURCES.txt > SHA256SUMS.txt) echo "Offline release created: $OUT"