-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·65 lines (55 loc) · 2.27 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·65 lines (55 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Droidspaces RootFS build engine. Builds one template for one architecture.
#
# ./build.sh -a <arch> -i <Name> [-v <version>]
# ./build.sh -a aarch64 -i Ubuntu-24.04-Minimal -v v20260101-000000
#
# <arch> is a key in archs.json and a folder under templates/.
# <Name> is templates/<arch>/<Name>.Dockerfile.
# Output: <Name>-Droidspaces-rootfs-<arch>-<YYYYMMDD>-<version>.tar.xz
set -euo pipefail
cd "$(dirname "$0")"
VERSION="dev"
while getopts "a:i:v:" opt; do
case $opt in
a) ARCH="$OPTARG" ;;
i) NAME="${OPTARG%.Dockerfile}" ;;
v) VERSION="$OPTARG" ;;
*) echo "Usage: $0 -a <arch> -i <Name> [-v <version>]" >&2; exit 1 ;;
esac
done
[ -n "${ARCH:-}" ] && [ -n "${NAME:-}" ] || { echo "Usage: $0 -a <arch> -i <Name> [-v <version>]" >&2; exit 1; }
DOCKERFILE="templates/$ARCH/$NAME.Dockerfile"
[ -f "$DOCKERFILE" ] || { echo "Error: $DOCKERFILE not found" >&2; exit 1; }
PLATFORM=$(jq -er --arg a "$ARCH" '.[$a].platform' archs.json) \
|| { echo "Error: arch '$ARCH' not in archs.json" >&2; exit 1; }
FINAL_NAME="${NAME}-Droidspaces-rootfs-${ARCH}-$(date +%Y%m%d)-${VERSION}.tar.xz"
TEMP_TAR="custom-${ARCH}-${NAME}-rootfs.tar"
echo "========================================================="
echo " Template : $DOCKERFILE"
echo " Platform : $PLATFORM"
echo " Version : $VERSION"
echo "========================================================="
# Register QEMU handlers only when the host cannot run the target natively.
if ! docker run --rm --platform "$PLATFORM" alpine:3.23 true >/dev/null 2>&1; then
echo "Host cannot run $PLATFORM natively; installing binfmt/QEMU..."
docker run --privileged --rm tonistiigi/binfmt --install all >/dev/null
fi
if ! docker buildx inspect droidspaces-builder >/dev/null 2>&1; then
docker buildx create --name droidspaces-builder --driver docker-container --use
else
docker buildx use droidspaces-builder
fi
docker buildx inspect --bootstrap >/dev/null
docker buildx build \
--platform "$PLATFORM" \
--target export \
--output "type=tar,dest=$TEMP_TAR" \
-f "$DOCKERFILE" \
.
echo "Compressing (xz -T0 -9)..."
xz -T0 -9 -f "$TEMP_TAR"
mv "${TEMP_TAR}.xz" "$FINAL_NAME"
echo "========================================================="
echo " Done: $FINAL_NAME"
echo "========================================================="