feat: multi-architecture builds (x86_64 + arm64)
- build-rpm.sh: --arch flag for targeting x86_64 or arm64, --all for both Uses bun cross-compile with --target=bun-linux-x64/arm64 - build-bastion.sh: --arch flag for Docker platform targeting - release.sh: builds both architectures by default - CI: builds + publishes RPM/DEB for both architectures Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,14 +11,72 @@ if [ -f .env ]; then
|
||||
set -a; source .env; set +a
|
||||
fi
|
||||
|
||||
# ── Argument parsing ───────────────────────────────────────────────
|
||||
TARGET_ARCH=""
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "$0") [OPTIONS] [TAG]
|
||||
|
||||
Build bastion container image and optionally push to registry.
|
||||
|
||||
Options:
|
||||
--arch ARCH Target platform: x86_64 or arm64 (default: host arch)
|
||||
-h, --help Show this help message
|
||||
|
||||
Arguments:
|
||||
TAG Image tag (default: version from package.json)
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
POSITIONAL_ARGS=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--arch)
|
||||
TARGET_ARCH="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
POSITIONAL_ARGS+=("$1")
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Registry defaults to internal address (external proxy has body size limit)
|
||||
REGISTRY="${GITEA_REGISTRY:-mysources.co.uk}"
|
||||
IMAGE="lab-bastion"
|
||||
VERSION=$(node -p "require('./package.json').version")
|
||||
TAG="${1:-$VERSION}"
|
||||
TAG="${POSITIONAL_ARGS[0]:-$VERSION}"
|
||||
|
||||
echo "==> Building bastion image (tag: $TAG)..."
|
||||
podman build -t "$IMAGE:$TAG" -f stack/Dockerfile .
|
||||
# ── Resolve target platform ───────────────────────────────────────
|
||||
detect_host_arch() {
|
||||
local machine
|
||||
machine="$(uname -m)"
|
||||
case "$machine" in
|
||||
x86_64) echo "x86_64" ;;
|
||||
aarch64) echo "arm64" ;;
|
||||
arm64) echo "arm64" ;;
|
||||
*) echo "$machine" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
docker_platform_for() {
|
||||
case "$1" in
|
||||
x86_64) echo "linux/amd64" ;;
|
||||
arm64) echo "linux/arm64" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
ARCH="${TARGET_ARCH:-$(detect_host_arch)}"
|
||||
PLATFORM="$(docker_platform_for "$ARCH")"
|
||||
|
||||
echo "==> Building bastion image (tag: $TAG, platform: $PLATFORM)..."
|
||||
podman build --platform "$PLATFORM" -t "$IMAGE:$TAG" -f stack/Dockerfile .
|
||||
|
||||
echo "==> Tagging as $REGISTRY/michal/$IMAGE:$TAG..."
|
||||
podman tag "$IMAGE:$TAG" "$REGISTRY/michal/$IMAGE:$TAG"
|
||||
@@ -41,3 +99,4 @@ fi
|
||||
|
||||
echo "==> Done!"
|
||||
echo " Image: $REGISTRY/michal/$IMAGE:$TAG"
|
||||
echo " Platform: $PLATFORM"
|
||||
|
||||
@@ -13,9 +13,147 @@ fi
|
||||
# Ensure tools are on PATH
|
||||
export PATH="$HOME/.npm-global/bin:$HOME/.bun/bin:$HOME/.local/bin:$PATH"
|
||||
|
||||
echo "==> Running unit tests..."
|
||||
pnpm test:run
|
||||
echo ""
|
||||
# ── Argument parsing ───────────────────────────────────────────────
|
||||
BUILD_ALL=false
|
||||
TARGET_ARCH=""
|
||||
SKIP_TESTS=false
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "$0") [OPTIONS]
|
||||
|
||||
Build lab binary and produce RPM/DEB packages.
|
||||
|
||||
Options:
|
||||
--arch ARCH Target architecture: x86_64 or arm64 (default: host arch)
|
||||
--all Build for both x86_64 and arm64
|
||||
--skip-tests Skip unit tests (useful in CI where tests ran separately)
|
||||
-h, --help Show this help message
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--arch)
|
||||
TARGET_ARCH="$2"
|
||||
shift 2
|
||||
;;
|
||||
--all)
|
||||
BUILD_ALL=true
|
||||
shift
|
||||
;;
|
||||
--skip-tests)
|
||||
SKIP_TESTS=true
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ── Resolve host architecture ─────────────────────────────────────
|
||||
detect_host_arch() {
|
||||
local machine
|
||||
machine="$(uname -m)"
|
||||
case "$machine" in
|
||||
x86_64) echo "x86_64" ;;
|
||||
aarch64) echo "arm64" ;;
|
||||
arm64) echo "arm64" ;;
|
||||
*) echo "$machine" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ── Architecture mapping helpers ──────────────────────────────────
|
||||
# Maps our canonical arch names to the values each tool expects.
|
||||
bun_target_for() {
|
||||
case "$1" in
|
||||
x86_64) echo "bun-linux-x64" ;;
|
||||
arm64) echo "bun-linux-arm64" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
nfpm_arch_for() {
|
||||
case "$1" in
|
||||
x86_64) echo "amd64" ;;
|
||||
arm64) echo "arm64" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
rpm_arch_for() {
|
||||
case "$1" in
|
||||
x86_64) echo "x86_64" ;;
|
||||
arm64) echo "aarch64" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
deb_arch_for() {
|
||||
case "$1" in
|
||||
x86_64) echo "amd64" ;;
|
||||
arm64) echo "arm64" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ── Build one architecture ────────────────────────────────────────
|
||||
build_arch() {
|
||||
local arch="$1"
|
||||
local bun_target nfpm_arch binary_name
|
||||
|
||||
bun_target="$(bun_target_for "$arch")"
|
||||
nfpm_arch="$(nfpm_arch_for "$arch")"
|
||||
binary_name="dist/lab-${arch}"
|
||||
|
||||
echo ""
|
||||
echo "==> Bundling standalone binary for ${arch}..."
|
||||
bun build src/cli/src/index.ts --compile --target="${bun_target}" --outfile "${binary_name}"
|
||||
|
||||
echo "==> Packaging RPM (${arch})..."
|
||||
# Create a temporary nfpm config with the correct arch and binary path
|
||||
local tmpconfig
|
||||
tmpconfig="$(mktemp /tmp/nfpm-XXXXXX.yaml)"
|
||||
sed -e "s|^arch:.*|arch: ${nfpm_arch}|" \
|
||||
-e "s|src: ./dist/lab$|src: ./${binary_name}|" \
|
||||
nfpm.yaml > "$tmpconfig"
|
||||
|
||||
nfpm pkg --config "$tmpconfig" --packager rpm --target dist/
|
||||
rm -f "$tmpconfig"
|
||||
|
||||
local rpm_arch
|
||||
rpm_arch="$(rpm_arch_for "$arch")"
|
||||
RPM_FILE=$(ls dist/lab-*.${rpm_arch}.rpm 2>/dev/null | head -1)
|
||||
echo "==> Built: $RPM_FILE"
|
||||
echo " Size: $(du -h "$RPM_FILE" | cut -f1)"
|
||||
|
||||
echo ""
|
||||
echo "==> Packaging DEB (${arch})..."
|
||||
local deb_arch
|
||||
deb_arch="$(deb_arch_for "$arch")"
|
||||
|
||||
tmpconfig="$(mktemp /tmp/nfpm-XXXXXX.yaml)"
|
||||
sed -e "s|^arch:.*|arch: ${nfpm_arch}|" \
|
||||
-e "s|src: ./dist/lab$|src: ./${binary_name}|" \
|
||||
nfpm.yaml > "$tmpconfig"
|
||||
|
||||
nfpm pkg --config "$tmpconfig" --packager deb --target dist/
|
||||
rm -f "$tmpconfig"
|
||||
|
||||
DEB_FILE=$(ls dist/lab_*_${deb_arch}.deb 2>/dev/null | head -1)
|
||||
echo "==> Built: $DEB_FILE"
|
||||
echo " Size: $(du -h "$DEB_FILE" | cut -f1)"
|
||||
}
|
||||
|
||||
# ── Main ──────────────────────────────────────────────────────────
|
||||
|
||||
if [ "$SKIP_TESTS" = false ]; then
|
||||
echo "==> Running unit tests..."
|
||||
pnpm test:run
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo "==> Building TypeScript..."
|
||||
pnpm build
|
||||
@@ -23,25 +161,20 @@ pnpm build
|
||||
echo "==> Generating shell completions..."
|
||||
pnpm completions:generate
|
||||
|
||||
echo "==> Bundling standalone binary..."
|
||||
mkdir -p dist
|
||||
rm -f dist/lab dist/lab-*.rpm dist/lab*.deb
|
||||
rm -f dist/lab dist/lab-x86_64 dist/lab-arm64 dist/lab-*.rpm dist/lab*.deb
|
||||
|
||||
bun build src/cli/src/index.ts --compile --outfile dist/lab
|
||||
|
||||
echo "==> Packaging RPM..."
|
||||
nfpm pkg --packager rpm --target dist/
|
||||
|
||||
RPM_FILE=$(ls dist/lab-*.rpm 2>/dev/null | head -1)
|
||||
echo "==> Built: $RPM_FILE"
|
||||
echo " Size: $(du -h "$RPM_FILE" | cut -f1)"
|
||||
rpm -qpi "$RPM_FILE"
|
||||
if [ "$BUILD_ALL" = true ]; then
|
||||
build_arch "x86_64"
|
||||
build_arch "arm64"
|
||||
elif [ -n "$TARGET_ARCH" ]; then
|
||||
build_arch "$TARGET_ARCH"
|
||||
else
|
||||
# Default to host architecture
|
||||
HOST_ARCH="$(detect_host_arch)"
|
||||
build_arch "$HOST_ARCH"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "==> Packaging DEB..."
|
||||
rm -f dist/lab*.deb
|
||||
nfpm pkg --packager deb --target dist/
|
||||
|
||||
DEB_FILE=$(ls dist/lab*.deb 2>/dev/null | head -1)
|
||||
echo "==> Built: $DEB_FILE"
|
||||
echo " Size: $(du -h "$DEB_FILE" | cut -f1)"
|
||||
echo "==> Build complete. Artifacts in dist/:"
|
||||
ls -lh dist/lab* 2>/dev/null || echo " (none)"
|
||||
|
||||
@@ -13,8 +13,8 @@ fi
|
||||
echo "=== lab-bastion release ==="
|
||||
echo ""
|
||||
|
||||
# 1. Build binaries & packages
|
||||
bash scripts/build-rpm.sh
|
||||
# 1. Build binaries & packages (both architectures)
|
||||
bash scripts/build-rpm.sh --all
|
||||
|
||||
echo ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user