#!/usr/bin/env sh set -eu RELEASE_VERSION="${RELEASE_VERSION:-20260513-330373b-11}" BASE_URL="${BASE_URL:-http://10.8.0.1/ai_deploy}" BUNDLE_NAME="${BUNDLE_NAME:-managed-portal-${RELEASE_VERSION}.zip}" INSTALL_ROOT="${INSTALL_ROOT:-/opt/managed-portal-releases}" TARGET_DIR="${TARGET_DIR:-${INSTALL_ROOT}/managed-portal-${RELEASE_VERSION}}" require_command() { if ! command -v "$1" >/dev/null 2>&1; then echo "missing required command: $1" >&2 exit 1 fi } run_compose() { if command -v docker-compose >/dev/null 2>&1; then docker-compose "$@" return 0 fi docker compose "$@" } download_bundle() { tmp_dir="$1" bundle_zip="$tmp_dir/$BUNDLE_NAME" bundle_url="${BASE_URL%/}/$BUNDLE_NAME" echo "downloading $bundle_url" >&2 curl -fL "$bundle_url" -o "$bundle_zip" echo "$bundle_zip" } build_overlay_image() { overlay_name="$1" base_image="$2" overlay_root="$3" overlay_image="$4" overlay_context="$(dirname "$overlay_root")" if [ ! -d "$overlay_root" ]; then printf '%s\n' "$base_image" return 0 fi if [ -z "$(find "$overlay_root" -mindepth 1 -print -quit)" ]; then printf '%s\n' "$base_image" return 0 fi echo "building runtime overlay for $overlay_name" >&2 docker build \ -f "$TARGET_DIR/deploy/Dockerfile.runtime-overlay" \ --build-arg "BASE_IMAGE=$base_image" \ -t "$overlay_image" \ "$overlay_context" >/dev/null printf '%s\n' "$overlay_image" } require_command curl require_command unzip require_command docker tmp_dir="$(mktemp -d)" trap 'rm -rf "$tmp_dir"' EXIT INT TERM mkdir -p "$INSTALL_ROOT" bundle_zip="$(download_bundle "$tmp_dir")" rm -rf "$TARGET_DIR" unzip -oq "$bundle_zip" -d "$INSTALL_ROOT" if [ ! -f "$TARGET_DIR/release-manifest.env" ]; then echo "release-manifest.env not found in $TARGET_DIR" >&2 exit 1 fi set -a . "$TARGET_DIR/release-manifest.env" set +a echo "pulling release images" docker pull "$MANAGED_PORTAL_IMAGE" docker pull "$MANAGED_PORTAL_WEB_IMAGE" docker pull "$PEOPLE_FLOW_PROJECT_IMAGE" docker pull "$STORE_DWELL_ALERT_IMAGE" PEOPLE_FLOW_PROJECT_IMAGE="$(build_overlay_image \ people-flow-project \ "$PEOPLE_FLOW_PROJECT_IMAGE" \ "$TARGET_DIR/runtime-overlays/people-flow-project/rootfs" \ "managed-portal-runtime/people-flow-project:${RELEASE_VERSION}")" STORE_DWELL_ALERT_IMAGE="$(build_overlay_image \ store-dwell-alert \ "$STORE_DWELL_ALERT_IMAGE" \ "$TARGET_DIR/runtime-overlays/store-dwell-alert/rootfs" \ "managed-portal-runtime/store-dwell-alert:${RELEASE_VERSION}")" export MANAGED_PORTAL_IMAGE export MANAGED_PORTAL_WEB_IMAGE export PEOPLE_FLOW_PROJECT_IMAGE export STORE_DWELL_ALERT_IMAGE cd "$TARGET_DIR/deploy" run_compose \ --env-file managed-portal.release.env \ -f docker-compose.ota-release.yml \ up -d echo "release installed under $TARGET_DIR"