feat(release): add static browser builds
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Package a fully static musl-linked dbx-web binary together with the built
|
||||
# frontend into a portable tarball that runs on any Linux (no glibc needed).
|
||||
|
||||
target="${DBX_STATIC_TARGET:-aarch64-unknown-linux-musl}"
|
||||
dist_dir="${DBX_FRONTEND_DIST:-dist}"
|
||||
output_dir="${DBX_STATIC_OUTPUT_DIR:-dist-web-static}"
|
||||
|
||||
case "$target" in
|
||||
x86_64-unknown-linux-musl*)
|
||||
arch_label="x64"
|
||||
;;
|
||||
aarch64-unknown-linux-musl*)
|
||||
arch_label="arm64"
|
||||
;;
|
||||
*)
|
||||
echo "unsupported static web target: $target" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
binary="${DBX_WEB_BINARY:-target/${target}/release/dbx-web}"
|
||||
package_name="${DBX_STATIC_PACKAGE_NAME:-dbx-linux-${arch_label}-browser-static}"
|
||||
package_dir="${output_dir}/${package_name}"
|
||||
tarball="${output_dir}/${package_name}.tar.gz"
|
||||
|
||||
if [ ! -x "$binary" ]; then
|
||||
echo "missing static dbx-web binary: $binary" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "${dist_dir}/index.html" ]; then
|
||||
echo "missing frontend build output: ${dist_dir}/index.html" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if readelf -l "$binary" | grep -q 'Requesting program interpreter'; then
|
||||
readelf -l "$binary" | grep 'Requesting program interpreter' >&2 || true
|
||||
echo "dbx-web is not fully static: ELF has a program interpreter" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if readelf -d "$binary" 2>/dev/null | grep -q 'Shared library:'; then
|
||||
readelf -d "$binary" | grep 'Shared library:' >&2 || true
|
||||
echo "dbx-web is not fully static: ELF has dynamic shared library dependencies" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf "$output_dir"
|
||||
mkdir -p \
|
||||
"$package_dir/bin" \
|
||||
"$package_dir/dist" \
|
||||
"$package_dir/data"
|
||||
|
||||
cp "$binary" "$package_dir/bin/dbx-web-bin"
|
||||
chmod +x "$package_dir/bin/dbx-web-bin"
|
||||
cp -a "${dist_dir}/." "$package_dir/dist/"
|
||||
|
||||
cat > "$package_dir/dbx" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ]; do
|
||||
DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE"
|
||||
done
|
||||
ROOT="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
||||
export DBX_PACKAGE_ROOT="$ROOT"
|
||||
export DBX_STATIC_DIR="${DBX_STATIC_DIR:-$ROOT/dist}"
|
||||
export DBX_DATA_DIR="${DBX_DATA_DIR:-$ROOT/data}"
|
||||
port="${DBX_PORT:-4224}"
|
||||
base_path="${DBX_PUBLIC_BASE_PATH:-/}"
|
||||
case "$base_path" in
|
||||
"") base_path="/" ;;
|
||||
/*) ;;
|
||||
*) base_path="/$base_path" ;;
|
||||
esac
|
||||
printf 'DBX browser UI: http://127.0.0.1:%s%s\n' "$port" "$base_path"
|
||||
cd "$ROOT"
|
||||
exec "$ROOT/bin/dbx-web-bin" "$@"
|
||||
EOF
|
||||
chmod +x "$package_dir/dbx"
|
||||
ln -sfn dbx "$package_dir/dbx-web"
|
||||
|
||||
cat > "$package_dir/README.txt" <<EOF
|
||||
DBX ${arch_label} static browser package
|
||||
|
||||
Run:
|
||||
./dbx
|
||||
|
||||
Then open:
|
||||
http://127.0.0.1:4224
|
||||
|
||||
This package runs a musl-linked static dbx-web binary and serves the bundled
|
||||
frontend from ./dist. The backend binary has no ELF interpreter and no DT_NEEDED
|
||||
shared library entries, so it runs on any Linux distribution regardless of the
|
||||
system glibc version (verified down to Ubuntu 14.04).
|
||||
|
||||
Useful environment variables:
|
||||
DBX_PORT=4224
|
||||
DBX_DATA_DIR=./data
|
||||
DBX_PASSWORD=your-password
|
||||
DBX_DISABLE_PASSWORD=1
|
||||
EOF
|
||||
|
||||
tar -C "$output_dir" -czf "$tarball" "$package_name"
|
||||
sha256sum "$tarball" | tee "${tarball}.sha256"
|
||||
file "$package_dir/bin/dbx-web-bin"
|
||||
du -sh "$package_dir" "$tarball"
|
||||
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Verify the static web package inside an old-glibc container (e.g.
|
||||
# ubuntu:14.04). The container arch matches the package arch, so the binary
|
||||
# runs natively. Confirms the ELF is fully static and the HTTP server serves
|
||||
# the bundled frontend.
|
||||
|
||||
package_tarball="${1:-${DBX_STATIC_TARBALL:-}}"
|
||||
if [ -z "$package_tarball" ]; then
|
||||
echo "usage: $0 <package-tarball>" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
verify_seconds="${DBX_STATIC_VERIFY_SECONDS:-30}"
|
||||
runtime_dir="${DBX_STATIC_VERIFY_DIR:-/tmp/dbx-web-static-verify}"
|
||||
|
||||
if [ ! -f "$package_tarball" ]; then
|
||||
echo "missing package tarball: $package_tarball" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v curl >/dev/null 2>&1 || ! command -v readelf >/dev/null 2>&1; then
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
# Archived releases (14.04, etc.) have moved to old-releases.ubuntu.com
|
||||
if [ -f /etc/apt/sources.list ] && ! apt-get update 2>/dev/null; then
|
||||
sed -i 's|archive\.ubuntu\.com|old-releases.ubuntu.com|g' /etc/apt/sources.list
|
||||
sed -i 's|security\.ubuntu\.com|old-releases.ubuntu.com|g' /etc/apt/sources.list
|
||||
apt-get -o Acquire::Check-Valid-Until=false update
|
||||
fi
|
||||
apt-get install -y --no-install-recommends ca-certificates bash binutils curl procps
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
fi
|
||||
|
||||
rm -rf "$runtime_dir"
|
||||
mkdir -p "$runtime_dir"
|
||||
tar -xzf "$package_tarball" -C "$runtime_dir" --strip-components=1
|
||||
|
||||
for required_runtime_path in \
|
||||
dbx \
|
||||
bin/dbx-web-bin \
|
||||
dist/index.html; do
|
||||
if [ ! -e "$runtime_dir/$required_runtime_path" ]; then
|
||||
echo "missing packaged static web runtime path: $required_runtime_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if readelf -l "$runtime_dir/bin/dbx-web-bin" | grep -q 'Requesting program interpreter'; then
|
||||
readelf -l "$runtime_dir/bin/dbx-web-bin" | grep 'Requesting program interpreter' >&2 || true
|
||||
echo "packaged dbx-web is not static: ELF has a program interpreter" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if readelf -d "$runtime_dir/bin/dbx-web-bin" 2>/dev/null | grep -q 'Shared library:'; then
|
||||
readelf -d "$runtime_dir/bin/dbx-web-bin" | grep 'Shared library:' >&2 || true
|
||||
echo "packaged dbx-web is not static: ELF has dynamic shared library dependencies" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$runtime_dir"
|
||||
export RUST_BACKTRACE="${RUST_BACKTRACE:-full}"
|
||||
export DBX_DISABLE_PASSWORD="${DBX_DISABLE_PASSWORD:-1}"
|
||||
export DBX_PORT="${DBX_PORT:-4224}"
|
||||
|
||||
echo "static web verification page size: $(getconf PAGE_SIZE 2>/dev/null || echo unknown)"
|
||||
./dbx >/tmp/dbx-web-static.log 2>&1 &
|
||||
pid=$!
|
||||
cleanup() {
|
||||
kill "$pid" >/dev/null 2>&1 || true
|
||||
wait "$pid" >/dev/null 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
for _ in $(seq 1 "$verify_seconds"); do
|
||||
if ! kill -0 "$pid" 2>/dev/null; then
|
||||
cat /tmp/dbx-web-static.log || true
|
||||
wait "$pid"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if curl -fsS "http://127.0.0.1:${DBX_PORT}/" >/tmp/dbx-web-static-index.html 2>/dev/null; then
|
||||
curl -fsS "http://127.0.0.1:${DBX_PORT}/api/auth/check" >/tmp/dbx-web-static-auth.json
|
||||
grep -q '"authenticated":true' /tmp/dbx-web-static-auth.json
|
||||
echo "static web verification HTTP check passed"
|
||||
tail -40 /tmp/dbx-web-static.log || true
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
done
|
||||
|
||||
cat /tmp/dbx-web-static.log || true
|
||||
echo "static dbx-web did not become ready within ${verify_seconds}s" >&2
|
||||
exit 1
|
||||
Reference in New Issue
Block a user