Files
memind/scripts/install-imgproxy-native-prod.sh
T
john 78e5a6c026
Memind CI / Test, build, and release guards (pull_request) Failing after 18s
feat(ops): add imgproxy native runtime tooling and record 103 deployment
Bundle vendored imgproxy with Mach-O dylibs for 103 launchd, fix install to exec the binary directly with launchctl enable, and document the live native release in the runtime topology.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-31 05:38:14 +08:00

129 lines
4.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Runs only on 103 from a verified imgproxy native release directory.
set -euo pipefail
ROOT="${ROOT:-/Users/john/Project/Memind}"
RUNTIME_BASE="${IMGPROXY_RUNTIME_BASE:-/Users/john/Project/imgproxy-runtime}"
RUNTIME_DIR="${IMGPROXY_RUNTIME_DIR:?IMGPROXY_RUNTIME_DIR is required}"
IMGPROXY_BIN="${RUNTIME_DIR}/vendor/imgproxy-runtime/bin/imgproxy"
RUN_SCRIPT="${RUNTIME_DIR}/scripts/run-imgproxy-prod.sh"
NODE_BIN="${NODE_BIN:-/opt/homebrew/opt/node@24/bin/node}"
DOCKER_BIN="${DOCKER_BIN:-/opt/homebrew/bin/docker}"
CONTAINER="${IMGPROXY_CONTAINER:-memind-imgproxy}"
NATIVE_LABEL="cn.tkmind.imgproxy"
COMPAT_LABEL="cn.tkmind.imgproxy-compat"
NATIVE_PLIST="${HOME}/Library/LaunchAgents/${NATIVE_LABEL}.plist"
COMPAT_PLIST="${HOME}/Library/LaunchAgents/${COMPAT_LABEL}.plist"
LOG_DIR="${HOME}/Library/Logs"
GUI="gui/$(id -u)"
[[ -x "${IMGPROXY_BIN}" ]] || {
echo "missing vendor imgproxy binary: ${IMGPROXY_BIN}" >&2
exit 1
}
[[ -x "${RUN_SCRIPT}" ]] || {
echo "missing imgproxy run script: ${RUN_SCRIPT}" >&2
exit 1
}
set -a
source "${ROOT}/.env"
set +a
: "${IMGPROXY_SIGNING_KEY:?missing IMGPROXY_SIGNING_KEY}"
: "${IMGPROXY_SIGNING_SALT:?missing IMGPROXY_SIGNING_SALT}"
: "${MINDSPACE_STORAGE_ROOT:?missing MINDSPACE_STORAGE_ROOT}"
cd "${RUNTIME_DIR}/vendor/imgproxy-runtime"
shasum -a 256 -c SHA256SUMS >/dev/null
mkdir -p "${HOME}/Library/LaunchAgents" "${LOG_DIR}"
cat > "${NATIVE_PLIST}" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>${NATIVE_LABEL}</string>
<key>ProgramArguments</key>
<array>
<string>${IMGPROXY_BIN}</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>IMGPROXY_BIND</key>
<string>127.0.0.1:20082</string>
<key>IMGPROXY_LOCAL_FILESYSTEM_ROOT</key>
<string>${MINDSPACE_STORAGE_ROOT}</string>
<key>IMGPROXY_KEY</key>
<string>${IMGPROXY_SIGNING_KEY}</string>
<key>IMGPROXY_SALT</key>
<string>${IMGPROXY_SIGNING_SALT}</string>
<key>IMGPROXY_USE_ETAG</key>
<string>true</string>
<key>IMGPROXY_ENABLE_WEBP_DETECTION</key>
<string>true</string>
</dict>
<key>WorkingDirectory</key>
<string>${ROOT}</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>ThrottleInterval</key>
<integer>10</integer>
<key>StandardOutPath</key>
<string>${LOG_DIR}/imgproxy.log</string>
<key>StandardErrorPath</key>
<string>${LOG_DIR}/imgproxy.log</string>
</dict>
</plist>
EOF
xattr -cr "${RUNTIME_DIR}" 2>/dev/null || true
if [[ -x "${DOCKER_BIN}" ]]; then
"${DOCKER_BIN}" stop "${CONTAINER}" >/dev/null 2>&1 || true
"${DOCKER_BIN}" rm -f "${CONTAINER}" >/dev/null 2>&1 || true
"${DOCKER_BIN}" update --restart=no "${CONTAINER}" >/dev/null 2>&1 || true
fi
launchctl bootout "${GUI}/${NATIVE_LABEL}" 2>/dev/null || true
plutil -lint "${NATIVE_PLIST}" >/dev/null
launchctl enable "${GUI}/${NATIVE_LABEL}" 2>/dev/null || true
launchctl bootstrap "${GUI}" "${NATIVE_PLIST}"
launchctl kickstart -k "${GUI}/${NATIVE_LABEL}"
for _ in $(seq 1 30); do
curl -fsS --max-time 2 http://127.0.0.1:20082/health >/dev/null && break
sleep 1
done
curl -fsS --max-time 3 http://127.0.0.1:20082/health >/dev/null
cat > "${COMPAT_PLIST}" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>${COMPAT_LABEL}</string>
<key>ProgramArguments</key><array><string>${NODE_BIN}</string><string>${RUNTIME_DIR}/imgproxy-compat-proxy.mjs</string></array>
<key>WorkingDirectory</key><string>${RUNTIME_DIR}</string>
<key>EnvironmentVariables</key><dict><key>IMGPROXY_COMPAT_HOST</key><string>10.10.0.2</string><key>IMGPROXY_COMPAT_PORT</key><string>20081</string><key>IMGPROXY_UPSTREAM</key><string>http://127.0.0.1:20082</string></dict>
<key>RunAtLoad</key><true/><key>KeepAlive</key><true/><key>ThrottleInterval</key><integer>10</integer>
<key>StandardOutPath</key><string>${LOG_DIR}/imgproxy-compat.log</string><key>StandardErrorPath</key><string>${LOG_DIR}/imgproxy-compat.log</string>
</dict></plist>
EOF
launchctl bootout "${GUI}/${COMPAT_LABEL}" 2>/dev/null || true
plutil -lint "${COMPAT_PLIST}" >/dev/null
launchctl enable "${GUI}/${COMPAT_LABEL}" 2>/dev/null || true
launchctl bootstrap "${GUI}" "${COMPAT_PLIST}"
launchctl kickstart -k "${GUI}/${COMPAT_LABEL}"
for _ in $(seq 1 30); do
curl -fsS --max-time 2 http://10.10.0.2:20081/health >/dev/null && break
sleep 1
done
curl -fsS --max-time 3 http://10.10.0.2:20081/health >/dev/null
printf 'imgproxy native installed from %s (%s)\n' "${RUNTIME_DIR}" "$("${IMGPROXY_BIN}" version)"