Skip to content

Commit 00670ab

Browse files
authored
Add helper script to build incus images (#26)
Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
1 parent f3cf9be commit 00670ab

3 files changed

Lines changed: 444 additions & 0 deletions

File tree

incus/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
all:
2+
3+
clean:
4+
./build.sh clean
5+
6+
build:
7+
./build.sh image
8+
9+
simplestreams:
10+
sudo rm -rf images streams
11+
sudo incus-simplestreams add --alias ubuntu/20.04 --alias ubuntu/focal ./build/focal-amd64/incus.tar.xz ./build/focal-amd64/rootfs.squashfs
12+
sudo incus-simplestreams add --alias ubuntu/20.04 --alias ubuntu/focal ./build/focal-arm64/incus.tar.xz ./build/focal-arm64/rootfs.squashfs
13+
sudo incus-simplestreams add --alias ubuntu/26.04 --alias ubuntu/resolute ./build/resolute-amd64/incus.tar.xz ./build/resolute-amd64/rootfs.squashfs
14+
sudo incus-simplestreams add --alias ubuntu/26.04 --alias ubuntu/resolute ./build/resolute-arm64/incus.tar.xz ./build/resolute-arm64/rootfs.squashfs

incus/build.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/bash
2+
3+
function error()
4+
{
5+
MSG="$1"
6+
echo -e "\e[31;40m[ERROR]\e[0m $MSG"
7+
}
8+
9+
function info()
10+
{
11+
MSG="$1"
12+
echo -e "\e[32;40m[INFO]\e[0m $MSG"
13+
}
14+
15+
function clean()
16+
{
17+
sudo rm -fr build images streams focal.arm64.yaml resolute.arm64.yaml focal.amd64.yaml resolute.amd64.yaml
18+
}
19+
20+
function usage()
21+
{
22+
echo "Usage: $0 image"
23+
exit 0
24+
}
25+
26+
27+
function build_image()
28+
{
29+
TARGET_CODE=$1
30+
TARGET_VARIANT=$2
31+
TARGET_ARCH=$3
32+
OUTPUT_DIR="build/${TARGET_CODE}-${TARGET_ARCH}"
33+
mkdir -p build
34+
sudo distrobuilder build-incus "${TARGET_CODE}.${TARGET_ARCH}.yaml" "$OUTPUT_DIR"
35+
printf "ubuntu\n${TARGET_CODE}\n${TARGET_VARIANT}\n${TARGET_ARCH}\n\n" | sudo incus-simplestreams generate-metadata "$OUTPUT_DIR/incus.tar.xz"
36+
}
37+
38+
function build_all_images()
39+
{
40+
for code in focal resolute; do
41+
for arch in amd64 arm64; do
42+
if [ -f "build/${code}-${arch}/rootfs.squashfs" ] && [ -f "build/${code}-${arch}/incus.tar.xz" ]; then
43+
info "skip ${code} ${arch}"
44+
continue
45+
fi
46+
info "generate ${code}.${arch}.yaml"
47+
rm -f ${code}.${arch}.yaml
48+
case $arch in
49+
arm64)
50+
sed -e "s/architecture: amd64/architecture: ${arch}/g" \
51+
-e "s/focal-amd64/${code}-arm64/g" \
52+
-e "s/release: focal/release: ${code}/g" \
53+
-e 's,url: http://ftp.riken.jp/Linux/ubuntu,url: https://linux.yz.yamagata-u.ac.jp/pub/linux/ubuntu-ports/,' \
54+
template.yaml > ${code}.${arch}.yaml
55+
;;
56+
amd64)
57+
sed -e "s/architecture: amd64/architecture: ${arch}/g" \
58+
-e "s/release: focal/release: ${code}/g" \
59+
-e "s/focal-amd64/${code}-amd64/g" \
60+
template.yaml > ${code}.${arch}.yaml
61+
;;
62+
esac
63+
case $code in
64+
focal)
65+
build_image ${code} 20.04 ${arch}
66+
;;
67+
resolute)
68+
build_image ${code} 26.04 ${arch}
69+
;;
70+
esac
71+
done
72+
done
73+
}
74+
75+
case $1 in
76+
clean)
77+
clean
78+
;;
79+
image)
80+
build_all_images
81+
;;
82+
*)
83+
usage
84+
;;
85+
esac

0 commit comments

Comments
 (0)