Skip to content

Commit e4d32b5

Browse files
committed
including example to docs/
1 parent 7efe47b commit e4d32b5

15 files changed

Lines changed: 178 additions & 0 deletions

File tree

docs/example/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.build

docs/example/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Builder Example
2+
3+
This is a basic example of utilizing the *Garden Linux Builder*.
4+
5+
To build this example run
6+
7+
./build base
8+
9+

docs/example/build

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env bash
2+
3+
set -eufo pipefail
4+
5+
container_image=ghcr.io/gardenlinux/builder:5d05982bf4132b0d7814080ea3042344d500adc3
6+
container_engine=podman
7+
8+
container_run_opts=(
9+
--security-opt seccomp=unconfined
10+
--security-opt apparmor=unconfined
11+
--security-opt label=disable
12+
--read-only
13+
)
14+
15+
container_mount_opts=(
16+
-v "$PWD/features:/builder/features:ro"
17+
-v "$PWD/keyring.gpg:/builder/keyring.gpg:ro"
18+
-v "$PWD/.build:/builder/.build"
19+
)
20+
21+
use_kms=0
22+
resolve_cname=0
23+
24+
while [ $# -gt 0 ]; do
25+
case "$1" in
26+
--container-image)
27+
container_image="$2"
28+
shift 2
29+
;;
30+
--container-engine)
31+
container_engine="$2"
32+
shift 2
33+
;;
34+
--container-run-opts)
35+
declare -a "container_run_opts=($2)"
36+
shift 2
37+
;;
38+
--kms)
39+
use_kms=1
40+
shift
41+
;;
42+
--print-container-image)
43+
printf '%s\n' "$container_image"
44+
exit 0
45+
;;
46+
--resolve-cname)
47+
resolve_cname=1
48+
shift
49+
;;
50+
*)
51+
break
52+
;;
53+
esac
54+
done
55+
56+
if [ "$container_image" = localhost/builder ]; then
57+
dir="$(dirname -- "$(realpath -- "${BASH_SOURCE[0]}")")"
58+
"$container_engine" build -t "$container_image" "$dir"
59+
fi
60+
61+
repo="$(./get_repo)"
62+
commit="$(./get_commit)"
63+
timestamp="$(./get_timestamp)"
64+
default_version="$(./get_version)"
65+
66+
[ -d .build ] || mkdir .build
67+
68+
if [ "$resolve_cname" = 1 ]; then
69+
arch="$("$container_engine" run --rm "${container_run_opts[@]}" "${container_mount_opts[@]}" "$container_image" dpkg --print-architecture)"
70+
cname="$("$container_engine" run --rm "${container_run_opts[@]}" "${container_mount_opts[@]}" "$container_image" /builder/parse_features --feature-dir /builder/features --default-arch "$arch" --default-version "$default_version" --cname "$1")"
71+
short_commit="$(head -c 8 <<< "$commit")"
72+
echo "$cname-$short_commit"
73+
exit 0
74+
fi
75+
76+
make_opts=(
77+
REPO="$repo"
78+
COMMIT="$commit"
79+
TIMESTAMP="$timestamp"
80+
DEFAULT_VERSION="$default_version"
81+
)
82+
83+
if [ "$use_kms" = 1 ]; then
84+
for e in AWS_DEFAULT_REGION AWS_REGION AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN; do
85+
if [ -n "${!e-}" ]; then
86+
make_opts+=("$e=${!e}")
87+
fi
88+
done
89+
fi
90+
91+
if [ -d cert ]; then
92+
container_mount_opts+=(-v "$PWD/cert:/builder/cert:ro")
93+
fi
94+
95+
"$container_engine" run --rm "${container_run_opts[@]}" "${container_mount_opts[@]}" "$container_image" make --no-print-directory -C /builder "${make_opts[@]}" "$@"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
systemctl enable systemd-networkd
6+
systemctl enable systemd-resolved
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
mkdir -p /etc/kernel
6+
echo "root=LABEL=ROOT ro" > /etc/kernel/cmdline
7+
8+
mkdir -p /boot/efi/Default
9+
10+
kernel="$(find /boot -name 'vmlinuz-*' | sort -V | tail -n 1)"
11+
version="${kernel#*-}"
12+
13+
unshare --mount bash -c 'mount -t tmpfs none /sys && mount --bind /usr/bin/false /usr/bin/systemd-detect-virt && "$@"' \
14+
DRACUT_COMPRESS_XZ="$(command -v xz)" dracut \
15+
--no-hostonly \
16+
--force \
17+
--kver "$version" \
18+
--modules "bash dash systemd systemd-initrd kernel-modules kernel-modules-extra terminfo udev-rules dracut-systemd base fs-lib shutdown" \
19+
--reproducible \
20+
"/boot/initrd.img-$version"
21+
22+
kernel-install add "$version" "$kernel"
23+
24+
sed 's/boot\/efi\///' -i /boot/efi/loader/entries/*.conf
25+
26+
SYSTEMD_ESP_PATH=/boot/efi bootctl --no-variables install
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Match]
2+
Name=en* eth*
3+
4+
[Network]
5+
DHCP=yes
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[Service]
2+
ExecStart=
3+
ExecStart=-/sbin/agetty --autologin root -o '-p -f -- \\u' --keep-baud 115200,38400,9600 %I $TERM

docs/example/features/base/fstab

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# <file system> <dir> <type> <options> <makeimg args>
2+
LABEL=EFI /boot/efi vfat umask=0077 type=uefi
3+
LABEL=ROOT / ext4 rw,errors=remount-ro,prjquota,discard
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
description: base
2+
type: platform
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dracut
2+
iproute2
3+
linux-image-$arch
4+
systemd
5+
systemd-boot
6+
systemd-resolved

0 commit comments

Comments
 (0)