71 lines
2.5 KiB
Bash
Executable File
71 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# Build a release tarball for Debian servers, in a Debian container so the
|
|
# binary links against Debian's glibc (a binary built on a newer distribution
|
|
# does not start on an older glibc).
|
|
#
|
|
# ./build-release.sh -> dist/movim-<version>-<debian>.tar.gz
|
|
#
|
|
# Copy it to the server, then: tar xzf movim-*.tar.gz && cd movim-* && ./install.sh
|
|
#
|
|
# Overridable: DEBIAN (default trixie: Debian 13 and newer; bookworm for 12),
|
|
# RUST_IMAGE (default rust:1-$DEBIAN), DOCKER (default docker; podman works),
|
|
# REBUILD (yes/no; asked when a binary exists, default yes without a terminal).
|
|
set -eu
|
|
|
|
DEBIAN=${DEBIAN:-trixie}
|
|
RUST_IMAGE=${RUST_IMAGE:-rust:1-$DEBIAN}
|
|
DOCKER=${DOCKER:-docker}
|
|
|
|
die() { echo "error: $*" >&2; exit 1; }
|
|
|
|
cd "$(dirname "$0")"
|
|
[ -f Cargo.toml ] || die "run this from the movim-rs repository"
|
|
|
|
version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)
|
|
name="movim-$version-$DEBIAN"
|
|
# Separate target and cargo cache per image: incremental rebuilds stay fast and
|
|
# never mix with host builds in target/release.
|
|
cache="target/docker-$DEBIAN"
|
|
mkdir -p "$cache/cargo"
|
|
|
|
bin="$cache/release/movim"
|
|
rebuild=${REBUILD:-}
|
|
if [ -z "$rebuild" ] && [ -x "$bin" ]; then
|
|
if [ -t 0 ]; then
|
|
printf 'A binary exists (built %s). Rebuild? [Y/n] ' "$(date -r "$bin" '+%Y-%m-%d %H:%M')"
|
|
read -r answer || answer=n
|
|
case $answer in [nN]*) rebuild=no ;; *) rebuild=yes ;; esac
|
|
else
|
|
rebuild=yes
|
|
fi
|
|
fi
|
|
|
|
if [ "$rebuild" = no ]; then
|
|
[ -x "$bin" ] || die "REBUILD=no but there is no binary at $bin"
|
|
echo "==> Reusing $bin"
|
|
else
|
|
command -v "$DOCKER" >/dev/null || die "$DOCKER not found"
|
|
"$DOCKER" info >/dev/null 2>&1 || die "cannot reach $DOCKER; start it (sudo systemctl start docker) and make sure you may use it (docker group)"
|
|
echo "==> Building $name in $RUST_IMAGE"
|
|
"$DOCKER" run --rm \
|
|
--user "$(id -u):$(id -g)" \
|
|
-v "$PWD:/src" -w /src \
|
|
-e CARGO_HOME="/src/$cache/cargo" \
|
|
-e CARGO_TARGET_DIR="/src/$cache" \
|
|
"$RUST_IMAGE" \
|
|
sh -c 'rustc --version && cargo build --release --locked'
|
|
fi
|
|
|
|
echo "==> Packing dist/$name.tar.gz"
|
|
stage=$(mktemp -d)
|
|
trap 'rm -rf "$stage"' EXIT
|
|
mkdir "$stage/$name"
|
|
cp "$bin" install.sh "$stage/$name/"
|
|
cp -R frontend templates "$stage/$name/"
|
|
mkdir -p dist
|
|
tar -C "$stage" -czf "dist/$name.tar.gz" "$name"
|
|
|
|
echo
|
|
echo "dist/$name.tar.gz ($(du -h "dist/$name.tar.gz" | cut -f1))"
|
|
echo "On the server: tar xzf $name.tar.gz && cd $name && ./install.sh"
|