#!/usr/bin/env bash # Materialize a darwin/arm64 imgproxy vendor binary into .runtime/imgproxy-native/. # Prefers the local Homebrew Cellar binary; bundles non-system dylibs for 103. set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" OUT_DIR="${IMGPROXY_NATIVE_OUT_DIR:-${ROOT}/.runtime/imgproxy-native}" VENDOR_DIR="${OUT_DIR}/vendor/imgproxy-runtime" BIN_DIR="${VENDOR_DIR}/bin" LIB_DIR="${VENDOR_DIR}/lib" IMGPROXY_VERSION="${IMGPROXY_VERSION:-4.0.7}" BREW_PREFIX="${HOMEBREW_PREFIX:-/opt/homebrew}" DRY_RUN=0 # shellcheck source=scripts/lib/bundle-mach-dylibs.sh source "${ROOT}/scripts/lib/bundle-mach-dylibs.sh" case "${1:-}" in --dry-run) DRY_RUN=1 ;; --help|-h) cat <<'EOF' Usage: bash scripts/build-imgproxy-runtime-native.sh [--dry-run] Builds .runtime/imgproxy-native with: vendor/imgproxy-runtime/bin/imgproxy vendor/imgproxy-runtime/lib/*.dylib vendor/imgproxy-runtime/VERSION.txt vendor/imgproxy-runtime/SHA256SUMS scripts/install-imgproxy-native-prod.sh scripts/run-imgproxy-prod.sh imgproxy-compat-proxy.mjs RUNBOOK.txt Set IMGPROXY_SOURCE_BIN to copy a specific binary, or IMGPROXY_VERSION for Cellar lookup. EOF exit 0 ;; esac resolve_imgproxy_binary() { if [[ -n "${IMGPROXY_SOURCE_BIN:-}" ]]; then [[ -x "${IMGPROXY_SOURCE_BIN}" ]] || { echo "IMGPROXY_SOURCE_BIN is not executable: ${IMGPROXY_SOURCE_BIN}" >&2 exit 1 } printf '%s\n' "${IMGPROXY_SOURCE_BIN}" return fi local cellar_bin="${BREW_PREFIX}/Cellar/imgproxy/${IMGPROXY_VERSION}/bin/imgproxy" if [[ -x "${cellar_bin}" ]]; then printf '%s\n' "${cellar_bin}" return fi if command -v brew >/dev/null 2>&1; then local tmp cache_glob candidate tmp="$(mktemp -d "${TMPDIR:-/tmp}/imgproxy-bottle.XXXXXX")" brew fetch --force-bottle imgproxy >/dev/null cache_glob="${HOME}/Library/Caches/Homebrew/downloads/*imgproxy*${IMGPROXY_VERSION}*.bottle.tar.gz" candidate="$(ls -1 ${cache_glob} 2>/dev/null | head -1 || true)" [[ -n "${candidate}" ]] || { echo "imgproxy ${IMGPROXY_VERSION} bottle not found after brew fetch" >&2 exit 1 } tar -xzf "${candidate}" -C "${tmp}" find "${tmp}" -path "*/bin/imgproxy" -type f | head -1 return fi echo "imgproxy binary not found; install via brew or set IMGPROXY_SOURCE_BIN" >&2 exit 1 } if [[ "${DRY_RUN}" == 1 ]]; then candidate="$(resolve_imgproxy_binary || true)" printf 'version=%s\nsource=%s\nout_dir=%s\n' "${IMGPROXY_VERSION}" "${candidate:-missing}" "${OUT_DIR}" exit 0 fi mkdir -p "${BIN_DIR}" "${LIB_DIR}" "${OUT_DIR}/scripts" source_bin="$(resolve_imgproxy_binary)" cp "${source_bin}" "${BIN_DIR}/imgproxy" chmod 755 "${BIN_DIR}/imgproxy" bundle_mach_dylibs "${BIN_DIR}/imgproxy" "${LIB_DIR}" "${source_bin}" "${BIN_DIR}/imgproxy" version > "${VENDOR_DIR}/VERSION.txt" ( cd "${VENDOR_DIR}" shasum -a 256 bin/imgproxy VERSION.txt lib/* > SHA256SUMS ) cp "${ROOT}/scripts/install-imgproxy-native-prod.sh" "${OUT_DIR}/scripts/" cp "${ROOT}/scripts/run-imgproxy-prod.sh" "${OUT_DIR}/scripts/" cp "${ROOT}/scripts/imgproxy-compat-proxy.mjs" "${OUT_DIR}/" chmod 755 "${OUT_DIR}/scripts/install-imgproxy-native-prod.sh" "${OUT_DIR}/scripts/run-imgproxy-prod.sh" cat > "${OUT_DIR}/RUNBOOK.txt" < releases// LaunchAgent: cn.tkmind.imgproxy (127.0.0.1:20082) Compat proxy: cn.tkmind.imgproxy-compat (10.10.0.2:20081) Health: http://127.0.0.1:20082/health Public: https://img.tkmind.cn/health Vendor binary: vendor/imgproxy-runtime/bin/imgproxy Bundled libs: vendor/imgproxy-runtime/lib/ Built from: ${source_bin} This runtime replaces the Docker imgproxy container on 103. Portal runtime releases stay separate. EOF lib_count="$(find "${LIB_DIR}" -name '*.dylib' | wc -l | tr -d ' ')" printf 'imgproxy native runtime built at %s (%s, %s dylibs)\n' \ "${OUT_DIR}" "$(cat "${VENDOR_DIR}/VERSION.txt")" "${lib_count}"