146 lines
No EOL
6.2 KiB
Bash
146 lines
No EOL
6.2 KiB
Bash
#!/usr/bin/env bash
|
|
# Built standing on the shoulders of billions of dwarves
|
|
# Created by John A. Hoeven with the ethical assistance of Claude AI
|
|
# Licence: The Unlicense — https://unlicense.org
|
|
# ---------------------------------------------------------------------------
|
|
# llama-cpp-publish.sh
|
|
# /opt/llama-cpp/scripts/llama-cpp-publish.sh
|
|
# Version: v0.0.1 | Status: DEVELOPMENT
|
|
# Role: Orchestrator
|
|
# ---------------------------------------------------------------------------
|
|
# Purpose: Push a llama.cpp tag that has already been built, validated, and
|
|
# promoted live on BigBoy onward to the CE Forgejo mirror. This is
|
|
# the vetting gate: client deployments clone the Forgejo mirror,
|
|
# never GitHub directly, so they only ever see tags BigBoy has
|
|
# already proven work on real hardware.
|
|
#
|
|
# This publishes SOURCE ONLY, not a compiled binary. Client
|
|
# hardware varies (GPU architecture, or CPU-only) — each client
|
|
# still builds locally from this tag with their own
|
|
# CMAKE_CUDA_ARCHITECTURES. "Validated on BigBoy" means the
|
|
# pinned source at this tag builds clean and behaves correctly
|
|
# on real hardware once — it does not mean the binary is portable.
|
|
#
|
|
# Target: BigBoy — AlmaLinux 10.2
|
|
# Entry: ./llama-cpp-publish.sh <build-tag>
|
|
# e.g. ./llama-cpp-publish.sh b9985
|
|
# Refuses to run unless <build-tag> is the currently LIVE release
|
|
# (i.e. you promoted it first) — publishing is the last step,
|
|
# not a shortcut around validation.
|
|
# Depends: git, network access to FORGEJO_MIRROR_URL
|
|
# Note: Shallow-cloned tags push fine to Forgejo for content purposes;
|
|
# `git log` on the mirror will show truncated history for that
|
|
# tag. This is cosmetic — the tree/blob content is complete.
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# No 'set -e' — every operation is checked explicitly (CE OS standard §1.8).
|
|
|
|
# ── Configuration ────────────────────────────────────────────────────────
|
|
|
|
LLAMA_ROOT="/opt/llama-cpp"
|
|
RELEASES_DIR="${LLAMA_ROOT}/releases"
|
|
CURRENT_LINK="${LLAMA_ROOT}/current"
|
|
UPSTREAM_URL="https://github.com/ggml-org/llama.cpp"
|
|
|
|
# TODO: confirm this path matches the actual repo you create on Forgejo.
|
|
FORGEJO_MIRROR_URL="https://git.jhoeven.net/ceos/llama.cpp-vetted.git"
|
|
|
|
LOG_DIR="${HOME}/.local/logs/bigboy-llama-update"
|
|
LOG_FILE="${LOG_DIR}/publish-$(date '+%Y-%m-%d_%H%M%S').log"
|
|
|
|
BUILD_TAG="${1:-}"
|
|
|
|
# ── Logging ──────────────────────────────────────────────────────────────
|
|
|
|
mkdir -p "${LOG_DIR}"
|
|
|
|
_log() {
|
|
local level="${1}"
|
|
local msg="${2}"
|
|
local ts
|
|
ts="$(date '+%Y-%m-%d %H:%M:%S')"
|
|
printf '[%s] [%s] %s\n' "${ts}" "${level}" "${msg}" | tee -a "${LOG_FILE}"
|
|
}
|
|
log_info() { _log "INFO " "${1}"; }
|
|
log_warn() { _log "WARN " "${1}" >&2; }
|
|
log_error() { _log "ERROR" "${1}" >&2; }
|
|
|
|
# ── Cleanup ──────────────────────────────────────────────────────────────
|
|
|
|
PUBLISH_TMP=""
|
|
|
|
cleanup() {
|
|
if [[ -n "${PUBLISH_TMP}" && -d "${PUBLISH_TMP}" ]]; then
|
|
rm -rf "${PUBLISH_TMP}"
|
|
fi
|
|
log_info "Run finished. Log: ${LOG_FILE}"
|
|
}
|
|
trap cleanup EXIT INT TERM HUP
|
|
|
|
# ── Pre-flight checks ────────────────────────────────────────────────────
|
|
|
|
if [[ -z "${BUILD_TAG}" ]]; then
|
|
log_error "Usage: ${0} <build-tag>"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -d "${RELEASES_DIR}/${BUILD_TAG}" ]]; then
|
|
log_error "No staged release found for ${BUILD_TAG} at ${RELEASES_DIR}/${BUILD_TAG}"
|
|
exit 1
|
|
fi
|
|
|
|
CURRENT_TAG=""
|
|
if [[ -L "${CURRENT_LINK}" ]]; then
|
|
CURRENT_TAG="$(basename "$(readlink -f "${CURRENT_LINK}")")"
|
|
fi
|
|
|
|
if [[ "${CURRENT_TAG}" != "${BUILD_TAG}" ]]; then
|
|
log_error "${BUILD_TAG} is not the currently live release (live is: ${CURRENT_TAG:-none})."
|
|
log_error "Publish is the LAST step — promote it with llama-cpp-promote.sh first,"
|
|
log_error "and let it run long enough to confirm it's actually good before publishing."
|
|
exit 1
|
|
fi
|
|
|
|
# ── Confirmation ─────────────────────────────────────────────────────────
|
|
|
|
printf '\nThis will push tag %s to:\n %s\n' "${BUILD_TAG}" "${FORGEJO_MIRROR_URL}"
|
|
printf 'This makes it available to client deployments that clone from Forgejo.\n'
|
|
printf 'Confirm %s has been running live on BigBoy long enough to trust it.\n' "${BUILD_TAG}"
|
|
printf '\nProceed? [y/N] '
|
|
read -r response
|
|
case "${response}" in
|
|
[yY]|[yY][eE][sS]) ;;
|
|
*) log_info "Aborted by user."; exit 0 ;;
|
|
esac
|
|
|
|
# ── Push the tag (source only) to the Forgejo mirror ─────────────────────
|
|
|
|
PUBLISH_TMP="$(mktemp -d)"
|
|
log_info "Preparing tag ${BUILD_TAG} for publish via ${PUBLISH_TMP}"
|
|
|
|
if ! git clone --quiet --depth 1 --branch "${BUILD_TAG}" \
|
|
"${UPSTREAM_URL}" "${PUBLISH_TMP}/repo" >>"${LOG_FILE}" 2>&1; then
|
|
log_error "Could not re-fetch ${BUILD_TAG} from upstream for publishing."
|
|
exit 1
|
|
fi
|
|
|
|
if ! (cd "${PUBLISH_TMP}/repo" && git remote add forgejo-mirror "${FORGEJO_MIRROR_URL}") \
|
|
>>"${LOG_FILE}" 2>&1; then
|
|
log_error "Failed to add Forgejo remote."
|
|
exit 1
|
|
fi
|
|
|
|
log_info "Pushing ${BUILD_TAG} to Forgejo mirror"
|
|
if ! (cd "${PUBLISH_TMP}/repo" && git push forgejo-mirror "${BUILD_TAG}") \
|
|
>>"${LOG_FILE}" 2>&1; then
|
|
log_error "Push failed. Confirm the Forgejo repo exists at:"
|
|
log_error " ${FORGEJO_MIRROR_URL}"
|
|
log_error "and that this machine has push credentials configured."
|
|
exit 1
|
|
fi
|
|
|
|
log_info "Published: ${BUILD_TAG} is now available on the Forgejo mirror."
|
|
log_info "Client deployments cloning ${FORGEJO_MIRROR_URL} can now build this tag."
|
|
log_info ""
|
|
log_info "Reminder: this is source only. Each client still builds locally"
|
|
log_info "with CMAKE_CUDA_ARCHITECTURES matching their own hardware." |