Split OTA weights for Ubuntu installs
This commit is contained in:
@@ -4,6 +4,7 @@ set -eu
|
||||
RELEASE_VERSION="${RELEASE_VERSION:-20260518-7b32b21-11}"
|
||||
BASE_URL="${BASE_URL:-http://10.8.0.1/ai_deploy}"
|
||||
BUNDLE_NAME="${BUNDLE_NAME:-managed-portal-${RELEASE_VERSION}.zip}"
|
||||
WEIGHTS_ARCHIVE_NAME="${WEIGHTS_ARCHIVE_NAME:-people-flow-weights-${RELEASE_VERSION}.tar.gz}"
|
||||
INSTALL_ROOT="${INSTALL_ROOT:-/opt/managed-portal-releases}"
|
||||
TARGET_DIR="${TARGET_DIR:-${INSTALL_ROOT}/managed-portal-${RELEASE_VERSION}}"
|
||||
SHARED_ROOT="${SHARED_ROOT:-${INSTALL_ROOT}/shared}"
|
||||
@@ -16,6 +17,46 @@ require_command() {
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_ubuntu_package() {
|
||||
package_name="$1"
|
||||
command_name="$2"
|
||||
|
||||
if command -v "$command_name" >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ ! -r /etc/os-release ]; then
|
||||
echo "missing required command: $command_name; unable to detect OS for automatic installation" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
os_id="$(. /etc/os-release && printf '%s' "${ID:-}")"
|
||||
os_like="$(. /etc/os-release && printf '%s' "${ID_LIKE:-}")"
|
||||
|
||||
case "$os_id:$os_like" in
|
||||
ubuntu:*|*:ubuntu*|debian:*|*:debian*)
|
||||
;;
|
||||
*)
|
||||
echo "missing required command: $command_name; automatic installation is only supported on Ubuntu/Debian hosts" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "missing required command: $command_name; rerun installer as root on Ubuntu to auto-install $package_name" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update
|
||||
apt-get install -y "$package_name"
|
||||
|
||||
if ! command -v "$command_name" >/dev/null 2>&1; then
|
||||
echo "failed to install required command: $command_name" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
pull_or_use_local() {
|
||||
image="$1"
|
||||
|
||||
@@ -46,6 +87,11 @@ dir_has_files() {
|
||||
[ -d "$directory" ] && [ -n "$(find "$directory" -mindepth 1 -print -quit 2>/dev/null)" ]
|
||||
}
|
||||
|
||||
dir_has_payload_files() {
|
||||
directory="$1"
|
||||
[ -d "$directory" ] && [ -n "$(find "$directory" -type f ! -name '.gitkeep' -print -quit 2>/dev/null)" ]
|
||||
}
|
||||
|
||||
copy_dir_contents() {
|
||||
source_dir="$1"
|
||||
target_dir="$2"
|
||||
@@ -64,6 +110,16 @@ download_bundle() {
|
||||
echo "$bundle_zip"
|
||||
}
|
||||
|
||||
download_weights_archive() {
|
||||
tmp_dir="$1"
|
||||
weights_archive="$tmp_dir/$WEIGHTS_ARCHIVE_NAME"
|
||||
weights_url="${BASE_URL%/}/$WEIGHTS_ARCHIVE_NAME"
|
||||
|
||||
echo "downloading $weights_url" >&2
|
||||
curl -fL "$weights_url" -o "$weights_archive"
|
||||
echo "$weights_archive"
|
||||
}
|
||||
|
||||
build_overlay_image() {
|
||||
overlay_name="$1"
|
||||
base_image="$2"
|
||||
@@ -126,17 +182,36 @@ find_existing_people_flow_weights() {
|
||||
return 1
|
||||
}
|
||||
|
||||
extract_people_flow_weights_archive() {
|
||||
tmp_dir="$1"
|
||||
bundle_weights_dir="$TARGET_DIR/managed/people_flow_project/weights"
|
||||
weights_archive="$(download_weights_archive "$tmp_dir")"
|
||||
|
||||
mkdir -p "$TARGET_DIR/managed"
|
||||
tar -xzf "$weights_archive" -C "$TARGET_DIR/managed"
|
||||
|
||||
if ! dir_has_payload_files "$bundle_weights_dir"; then
|
||||
echo "downloaded weights archive did not populate $bundle_weights_dir" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%s\n' "$bundle_weights_dir"
|
||||
}
|
||||
|
||||
prepare_people_flow_weights() {
|
||||
tmp_dir="$1"
|
||||
bundle_weights_dir="$TARGET_DIR/managed/people_flow_project/weights"
|
||||
source_weights_dir=""
|
||||
|
||||
if dir_has_files "$bundle_weights_dir"; then
|
||||
if dir_has_payload_files "$bundle_weights_dir"; then
|
||||
source_weights_dir="$bundle_weights_dir"
|
||||
echo "seeding shared people-flow weights from bundle" >&2
|
||||
elif source_weights_dir="$(find_existing_people_flow_weights 2>/dev/null)"; then
|
||||
echo "reusing existing people-flow weights from $source_weights_dir" >&2
|
||||
elif source_weights_dir="$(extract_people_flow_weights_archive "$tmp_dir" 2>/dev/null)"; then
|
||||
echo "seeding shared people-flow weights from downloaded archive" >&2
|
||||
else
|
||||
echo "people-flow weights not found; seed $MANAGED_PEOPLE_FLOW_WEIGHTS_DIR or include managed/people_flow_project/weights in the release zip" >&2
|
||||
echo "people-flow weights not found; seed $MANAGED_PEOPLE_FLOW_WEIGHTS_DIR, publish $WEIGHTS_ARCHIVE_NAME, or include managed/people_flow_project/weights in the release zip" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -151,7 +226,8 @@ prepare_people_flow_weights() {
|
||||
}
|
||||
|
||||
require_command curl
|
||||
require_command unzip
|
||||
ensure_ubuntu_package unzip unzip
|
||||
require_command tar
|
||||
require_command docker
|
||||
|
||||
tmp_dir="$(mktemp -d)"
|
||||
@@ -174,7 +250,7 @@ set +a
|
||||
MANAGED_PEOPLE_FLOW_WEIGHTS_DIR="${MANAGED_PEOPLE_FLOW_WEIGHTS_DIR:-$DEFAULT_PEOPLE_FLOW_WEIGHTS_DIR}"
|
||||
|
||||
ensure_runtime_directories
|
||||
prepare_people_flow_weights
|
||||
prepare_people_flow_weights "$tmp_dir"
|
||||
|
||||
clear_stale_runtime_state
|
||||
|
||||
@@ -208,4 +284,4 @@ run_compose \
|
||||
-f docker-compose.ota-release.yml \
|
||||
up -d
|
||||
|
||||
echo "release installed under $TARGET_DIR"
|
||||
echo "release installed under $TARGET_DIR"
|
||||
|
||||
Reference in New Issue
Block a user