Split OTA weights for Ubuntu installs
This commit is contained in:
@@ -12,7 +12,9 @@ STAGE_DIR="${OUTPUT_DIR}/managed-portal-${RELEASE_VERSION}"
|
||||
BUNDLE_PATH="${OUTPUT_DIR}/managed-portal-${RELEASE_VERSION}.zip"
|
||||
INSTALLER_PATH="${OUTPUT_DIR}/install-managed-portal-${RELEASE_VERSION}.sh"
|
||||
INCLUDE_WEIGHTS="${INCLUDE_WEIGHTS:-0}"
|
||||
GENERATE_WEIGHTS_ARCHIVE="${GENERATE_WEIGHTS_ARCHIVE:-1}"
|
||||
PEOPLE_FLOW_WEIGHTS_SOURCE="${PEOPLE_FLOW_WEIGHTS_SOURCE:-$REPO_ROOT/managed/people_flow_project/weights}"
|
||||
WEIGHTS_ARCHIVE_PATH="${OUTPUT_DIR}/people-flow-weights-${RELEASE_VERSION}.tar.gz"
|
||||
|
||||
require_path() {
|
||||
target="$1"
|
||||
@@ -28,6 +30,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() {
|
||||
source_dir="$1"
|
||||
target_dir="$2"
|
||||
@@ -56,7 +63,7 @@ copy_dir "$REPO_ROOT/managed/store_dwell_alert/config" "$STAGE_DIR/managed/store
|
||||
copy_dir "$REPO_ROOT/managed/people_flow_project/config" "$STAGE_DIR/managed/people_flow_project/config"
|
||||
|
||||
if [ "$INCLUDE_WEIGHTS" = "1" ]; then
|
||||
if ! dir_has_files "$PEOPLE_FLOW_WEIGHTS_SOURCE"; then
|
||||
if ! dir_has_payload_files "$PEOPLE_FLOW_WEIGHTS_SOURCE"; then
|
||||
echo "people-flow weights requested but missing under $PEOPLE_FLOW_WEIGHTS_SOURCE" >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -86,8 +93,47 @@ with zipfile.ZipFile(bundle_path, "w", compression=zipfile.ZIP_DEFLATED) as arch
|
||||
archive.write(path, arcname.as_posix())
|
||||
PY
|
||||
|
||||
cp "$SCRIPT_DIR/install-managed-portal-ota.sh" "$INSTALLER_PATH"
|
||||
chmod +x "$INSTALLER_PATH"
|
||||
python3 - "$SCRIPT_DIR/install-managed-portal-ota.sh" "$INSTALLER_PATH" "$RELEASE_VERSION" <<'PY'
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
|
||||
source_path = Path(sys.argv[1])
|
||||
target_path = Path(sys.argv[2])
|
||||
release_version = sys.argv[3]
|
||||
|
||||
content = source_path.read_text(encoding="utf-8")
|
||||
content = re.sub(
|
||||
r'^RELEASE_VERSION="\$\{RELEASE_VERSION:-[^"]+\}"$',
|
||||
f'RELEASE_VERSION="${{RELEASE_VERSION:-{release_version}}}"',
|
||||
content,
|
||||
count=1,
|
||||
flags=re.MULTILINE,
|
||||
)
|
||||
target_path.write_text(content, encoding="utf-8")
|
||||
target_path.chmod(0o755)
|
||||
PY
|
||||
|
||||
if [ "$GENERATE_WEIGHTS_ARCHIVE" = "1" ] && dir_has_payload_files "$PEOPLE_FLOW_WEIGHTS_SOURCE"; then
|
||||
python3 - "$PEOPLE_FLOW_WEIGHTS_SOURCE" "$WEIGHTS_ARCHIVE_PATH" <<'PY'
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import tarfile
|
||||
|
||||
source_dir = Path(sys.argv[1])
|
||||
archive_path = Path(sys.argv[2])
|
||||
|
||||
if archive_path.exists():
|
||||
archive_path.unlink()
|
||||
|
||||
with tarfile.open(archive_path, "w:gz") as archive:
|
||||
for path in sorted(source_dir.rglob("*")):
|
||||
if path.name == ".gitkeep":
|
||||
continue
|
||||
arcname = Path("people_flow_project") / "weights" / path.relative_to(source_dir)
|
||||
archive.add(path, arcname=arcname.as_posix(), recursive=False)
|
||||
PY
|
||||
fi
|
||||
|
||||
echo "OTA bundle created: $BUNDLE_PATH"
|
||||
echo "Versioned installer created: $INSTALLER_PATH"
|
||||
@@ -95,4 +141,9 @@ if [ "$INCLUDE_WEIGHTS" = "1" ]; then
|
||||
echo "Bundle includes managed/people_flow_project/weights"
|
||||
else
|
||||
echo "Bundle excludes managed/people_flow_project/weights; the installer will reuse the shared host weights directory if available"
|
||||
fi
|
||||
fi
|
||||
if [ "$GENERATE_WEIGHTS_ARCHIVE" = "1" ] && dir_has_payload_files "$PEOPLE_FLOW_WEIGHTS_SOURCE"; then
|
||||
echo "Separate weights archive created: $WEIGHTS_ARCHIVE_PATH"
|
||||
else
|
||||
echo "Separate weights archive skipped; no people-flow weights payload found under $PEOPLE_FLOW_WEIGHTS_SOURCE"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user