Files
llama-link/scripts/build-deb.sh
T
darroyo f88b8e099b
CI / test (push) Failing after 17m30s
Add .deb packaging, GitHub Actions CI/CD, and release workflows
- Makefile: add 'deb' and 'release' targets; fix migrate/create syntax
- scripts/build-deb.sh: build .deb with systemd unit, postinst/prerm/postrm
- .github/workflows/ci.yml: go build, test, lint on PR/push to main
- .github/workflows/release.yml: multi-platform build (linux/darwin/windows
  × amd64/arm64), .deb for Linux, tarballs, draft GitHub Release on tag v*
- README.md: add CI/Release badges, Install section with .deb and binary
  release instructions
2026-07-30 12:42:10 -04:00

117 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# build-deb.sh — Build a .deb package for LlamaLink
set -euo pipefail
VERSION="${1:-}"
ARCH="${2:-$(dpkg --print-architecture 2>/dev/null || echo "amd64")}"
if [[ -z "$VERSION" ]]; then
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
VERSION="${VERSION#v}"
fi
if ! command -v dpkg-deb &>/dev/null; then
echo "Error: dpkg-deb not found. Install with: sudo apt install dpkg" >&2
exit 1
fi
if [[ "$(uname)" != "Linux" ]]; then
echo "Error: .deb packages can only be built on Linux." >&2
exit 1
fi
DEB_VERSION="${VERSION}-1"
BUILD_DIR="dist/deb-build"
PKG_DIR="${BUILD_DIR}/llamalink-${DEB_VERSION}_${ARCH}"
echo "==> Building llamalink_${DEB_VERSION}_${ARCH}.deb"
rm -rf "$BUILD_DIR"
mkdir -p "$PKG_DIR"/{DEBIAN,usr/local/bin,etc/llamalink,etc/systemd/system,opt/llamalink/data,var/log/llamalink}
# Binary (must exist)
if [[ ! -f "bin/llamalink" ]]; then
echo "Error: bin/llamalink not found. Run 'make build' first." >&2
exit 1
fi
cp bin/llamalink "$PKG_DIR/usr/local/bin/"
chmod 755 "$PKG_DIR/usr/local/bin/llamalink"
# Config template
cp .env.example "$PKG_DIR/etc/llamalink/env"
chmod 644 "$PKG_DIR/etc/llamalink/env"
# Systemd unit
cp deploy/llamalink.service "$PKG_DIR/etc/systemd/system/llamalink.service"
# DEBIAN/control
cat > "$PKG_DIR/DEBIAN/control" <<EOF
Package: llamalink
Version: ${DEB_VERSION}
Section: net
Priority: optional
Architecture: ${ARCH}
Maintainer: LlamaLink <hello@llamalink.dev>
Description: API Gateway for local LLM inference via llama.cpp
Provides a REST API with API key authentication, rate limiting,
and multi-model hot-swap for llama.cpp server instances.
Homepage: https://github.com/llamalink/llamalink
Depends: libc6
EOF
# DEBIAN/conffiles
echo "/etc/llamalink/env" > "$PKG_DIR/DEBIAN/conffiles"
# DEBIAN/postinst
cat > "$PKG_DIR/DEBIAN/postinst" <<'POSTINST'
#!/bin/sh
set -e
if [ "$1" = "configure" ]; then
if ! id llamalink > /dev/null 2>&1; then
useradd --system --no-create-home --shell /usr/sbin/nologin llamalink 2>/dev/null || true
fi
mkdir -p /opt/llamalink/data /var/log/llamalink
chown llamalink:llamalink /opt/llamalink/data /var/log/llamalink 2>/dev/null || true
if command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload 2>/dev/null || true
fi
fi
POSTINST
chmod 755 "$PKG_DIR/DEBIAN/postinst"
# DEBIAN/prerm
cat > "$PKG_DIR/DEBIAN/prerm" <<'PRERM'
#!/bin/sh
set -e
if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
if command -v systemctl >/dev/null 2>&1; then
systemctl stop llamalink.service 2>/dev/null || true
systemctl disable llamalink.service 2>/dev/null || true
fi
fi
PRERM
chmod 755 "$PKG_DIR/DEBIAN/prerm"
# DEBIAN/postrm
cat > "$PKG_DIR/DEBIAN/postrm" <<'POSTRM'
#!/bin/sh
set -e
if [ "$1" = "purge" ]; then
rm -rf /opt/llamalink/data /var/log/llamalink
if id llamalink > /dev/null 2>&1; then
userdel llamalink 2>/dev/null || true
fi
if command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload 2>/dev/null || true
fi
fi
POSTRM
chmod 755 "$PKG_DIR/DEBIAN/postrm"
# Build .deb
mkdir -p dist
dpkg-deb --build "$PKG_DIR" "dist/llamalink_${DEB_VERSION}_${ARCH}.deb"
echo "==> Created dist/llamalink_${DEB_VERSION}_${ARCH}.deb"
rm -rf "$BUILD_DIR"