Files
movim-rs/build-release.sh
T
2026-10-24 14:34:00 +07:00

53 lines
1.9 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 bookworm: Debian 12, also runs on 13 trixie),
# RUST_IMAGE (default rust:1-$DEBIAN), DOCKER (default docker; podman works).
set -eu
DEBIAN=${DEBIAN:-bookworm}
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"
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)"
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"
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'
echo "==> Packing dist/$name.tar.gz"
stage=$(mktemp -d)
trap 'rm -rf "$stage"' EXIT
mkdir "$stage/$name"
cp "$cache/release/movim" 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"