First commit : Add first scripts to build an ISO

This commit is contained in:
vfebvre 2022-10-19 11:48:25 +02:00
parent ab7c3a7184
commit 10e3f00059
3 changed files with 223 additions and 1 deletions

View File

@ -3,3 +3,33 @@
Cadoles Kubernetes Operating System Cadoles Kubernetes Operating System
a.k.a. CadolesKube/os a.k.a. CadolesKube/os
Creating a build server for AlpineLinux
On Alpine server run : at-begining.sh to install necessary tools.
Change to the build user :
su - build
Create signing key:
abuild-keygen -i -a (-i installs them in /etc/apk/keys)
Quick check :
ls -lah /etc/apk/keys/build-xxxxxxxx.rsa.pub
Clone the git repository :
git clone --depth=1 https://gitlab.alpinelinux.org/alpine/aports.git
Update :
sudo apk update
Copy script create-iso.sh in /home/build
You must enter a profile name to launch the creation of the iso. The iso is built with Edge sources to have Kubernetes tools.
For example ./create-iso.sh myKube.
The iso is generated in the ~/iso folder.

24
at-begining.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/sh
# Install base builder
if test $(id -u) -ne 0; then
echo "Be root is better for this action !!"
exit 1
fi
if test ! -f /etc/apk/world; then
echo "Maybe, You should try on an Alpine !"
exit 1
fi
# Packages needed
apk add alpine-sdk build-base apk-tools alpine-conf busybox fakeroot syslinux xorriso squashfs-tools sudo
# User setup
adduser build -G abuild
# Grant unrestricted sudo to abuild group
echo "%abuild ALL=(ALL) ALL" > /etc/sudoers.d/abuild
# Also, update apk
apk update

168
create-iso.sh Normal file
View File

@ -0,0 +1,168 @@
#!/bin/sh
#if [[ -z $1 || -z $2 ]]; then
if [[ -z $1 ]]; then
echo -e "ERREUR : paramétre(s) manquant(s) "
echo -e "Passer en paramétre : "
echo -e "1. Nom du profil (ex : kubauto)"
# echo -e "2. Version de l'Alpine (forcé à edge pour le moment)"
echo ""
exit 1
else
PROFILENAME=$1
ALPINE_VERSION=edge
export $PROFILENAME
cat << EOF > ~/aports/scripts/mkimg.$PROFILENAME.sh
profile_$PROFILENAME() {
profile_standard
kernel_cmdline="unionfs_size=512M console=tty0 console=ttyS0,115200"
syslinux_serial="0 115200"
apks="\$apks mtools parted rsync vim util-linux curl coreutils strace dhcp dhcpcd kubeadm lvm2 dfc cni-plugin-flannel cni-plugins
flannel flannel-contrib-cni kubelet kubeadm kubectl uuidgen docker docker-compose
"
local _k _a
for _k in \$kernel_flavors; do
apks="\$apks linux-\$_k"
for _a in \$kernel_addons; do
apks="\$apks \$_a-\$_k"
done
done
apks="\$apks linux-firmware"
hostname="$PROFILENAME"
apkovl="genapkovl-$PROFILENAME.sh"
}
EOF
chmod +x ~/aports/scripts/mkimg.$PROFILENAME.sh
cat << 'EOP' > ~/aports/scripts/genapkovl-$PROFILENAME.sh
#!/bin/sh -e
HOSTNAME="$1"
if [ -z "$HOSTNAME" ]; then
echo "usage: $0 hostname"
exit 1
fi
cleanup() {
rm -rf "$tmp"
}
makefile() {
OWNER="$1"
PERMS="$2"
FILENAME="$3"
cat > "$FILENAME"
chown "$OWNER" "$FILENAME"
chmod "$PERMS" "$FILENAME"
}
rc_add() {
mkdir -p "$tmp"/etc/runlevels/"$2"
ln -sf /etc/init.d/"$1" "$tmp"/etc/runlevels/"$2"/"$1"
}
tmp="$(mktemp -d)"
trap cleanup EXIT
mkdir -p "$tmp"/etc
makefile root:root 0644 "$tmp"/etc/hostname <<EOF
$HOSTNAME
EOF
mkdir -p "$tmp"/etc/network
makefile root:root 0644 "$tmp"/etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF
mkdir -p "$tmp/root/.ssh"
mkdir -p "$tmp/etc/apk"
echo '/media/cdrom' >> "$tmp/etc/apk/repositories"
echo 'http://dl-cdn.alpinelinux.org/alpine/$ALPINE_VERSION/main' >> "$tmp/etc/apk/repositories"
echo 'http://dl-cdn.alpinelinux.org/alpine/$ALPINE_VERSION/community' >> "$tmp/etc/apk/repositories"
echo 'http://dl-cdn.alpinelinux.org/alpine/$ALPINE_VERSION/testing' >> "$tmp/etc/apk/repositories"
mkdir -p "$tmp"/etc/apk
makefile root:root 0644 "$tmp"/etc/apk/world <<EOF
alpine-base
util-linux
xfsprogs
vim
dfc
cni-plugin-flannel
cni-plugins
flannel
flannel-contrib-cni
kubelet
kubeadm
kubectl
uuidgen
docker
docker-compose
EOF
mkdir -p "$tmp"/etc/local.d
# =------------------------------------------------------------=
# Hello preseed script, my new friend.
#
# Note the single quotes around the EOF, to avoid evaluation
# at the time genapkovl runs.
# =------------------------------------------------------------=
makefile root:root 0755 "$tmp"/etc/local.d/preseed.start <<'EOF'
#!/bin/sh
# Fail fast, if we make it onto a live system.
test "$(hostname)" = "" || exit 111
# Here would be the preseed script in earnest. One that sets
# the hostname to something else than `preseed`, or at least
# makes sure the /etc/local.d/preseed.start isn't carried over.
# Lest you're a glutton for punishment.
echo "preseeded at $(date)" >> /root/preseeded.txt
EOF
rc_add devfs sysinit
rc_add dmesg sysinit
rc_add mdev sysinit
rc_add hwdrivers sysinit
rc_add modloop sysinit
rc_add hwclock boot
rc_add modules boot
rc_add sysctl boot
rc_add hostname boot
rc_add bootmisc boot
rc_add syslog boot
# we want our preseed to run & have network while at it
rc_add networking boot
rc_add local boot
rc_add mount-ro shutdown
rc_add killprocs shutdown
rc_add savecache shutdown
tar -c -C "$tmp" etc | gzip -9n > $HOSTNAME.apkovl.tar.gz
EOP
chmod +x ~/aports/scripts/genapkovl-$PROFILENAME.sh
# Create output dir
if test ! -d ~/iso; then
echo "Creating output dir"
mkdir -p ~/iso
fi
echo "ISO generation"
cd ~/aports/scripts/
sh mkimage.sh --tag $ALPINE_VERSION \
--outdir ~/iso \
--arch x86_64 \
--repository http://dl-cdn.alpinelinux.org/alpine/$ALPINE_VERSION/main \
--repository http://dl-cdn.alpinelinux.org/alpine/$ALPINE_VERSION/community \
--repository http://dl-cdn.alpinelinux.org/alpine/$ALPINE_VERSION/testing \
--profile $PROFILENAME
fi