diff --git a/alpine/build-rootfs.sh b/alpine/build-rootfs.sh index fe65074..7c1de54 100755 --- a/alpine/build-rootfs.sh +++ b/alpine/build-rootfs.sh @@ -12,6 +12,7 @@ cp -a "${REGISTRY_DATA_DIR}/." "${ROOTFS}/var/lib/registry/" mkdir -p "$ROOTFS/var/cache/apk" mkdir -p "$ROOTFS/var/cache/k8s-images" mkdir -p "$ROOTFS/build" + mount --bind /var/cache/apk "$ROOTFS/var/cache/apk" mount --bind /var/cache/k8s-images "$ROOTFS/var/cache/k8s-images" mount --bind /dev "$ROOTFS/dev" @@ -22,7 +23,6 @@ mount --bind /run "$ROOTFS/run" cp /usr/bin/qemu-aarch64-static "$ROOTFS/usr/bin/" cp /etc/resolv.conf "$ROOTFS/etc/resolv.conf" cp /build/crio.tar.gz "$ROOTFS/build/" -cp /build/registry.tar.gz "$ROOTFS/build/" cp -r /build/rootfs/* "$ROOTFS/" chroot "$ROOTFS" /bin/sh -c "ln -s /var/cache/apk /etc/apk/cache" @@ -32,6 +32,12 @@ cp "/install-packages.sh" "$ROOTFS/install-packages.sh" chroot "$ROOTFS" /bin/bash /install-packages.sh || exit 1 rm "$ROOTFS/install-packages.sh" +/merge-rootfs.sh "/build/rootfs-extra" "$ROOTFS" + +cp "/configure-system.sh" "$ROOTFS/configure-system.sh" +chroot "$ROOTFS" /bin/bash /configure-system.sh || exit 1 +rm "$ROOTFS/configure-system.sh" + umount "$ROOTFS/var/cache/apk" umount "$ROOTFS/var/cache/k8s-images" umount "$ROOTFS/dev" @@ -41,10 +47,8 @@ umount "$ROOTFS/run" rm -r "$ROOTFS/build" -/merge-rootfs.sh "/build/rootfs-extra" "$ROOTFS" - ### Begin making full disk image for the device -echo "=========================== RootFS "$( du -sh "$ROOTFS/" ) +echo "##################################################### Packaging RootFS "$( du -sh "$ROOTFS/" ) IMG=output.img SIZE=1536MB @@ -78,5 +82,5 @@ umount /mnt/img-root losetup -d "$LOOP" -echo "GZipping the image" +echo "##################################################### Compressing Image" gzip "/build/$IMG" diff --git a/alpine/configure-system.sh b/alpine/configure-system.sh new file mode 100755 index 0000000..e27d0d2 --- /dev/null +++ b/alpine/configure-system.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +cd /build + +echo "##################################################### Install RC Services" +rc-update add devfs sysinit +rc-update add procfs sysinit +rc-update add sysfs sysinit +rc-update add fancontrol boot +rc-update add loopback boot +rc-update add hostname boot +rc-update add localmount boot +rc-update add crio default diff --git a/alpine/install-packages.sh b/alpine/install-packages.sh index 5510301..d87444e 100755 --- a/alpine/install-packages.sh +++ b/alpine/install-packages.sh @@ -6,33 +6,16 @@ echo "##################################################### Installing basic pac apk add alpine-base \ openrc busybox-openrc bash nftables \ lm-sensors lm-sensors-fancontrol lm-sensors-fancontrol-openrc -rc-update add devfs sysinit -rc-update add procfs sysinit -rc-update add sysfs sysinit -rc-update add loopback boot -rc-update add hostname boot -rc-update add localmount boot -rc-update add fancontrol default echo '[ -x /bin/bash ] && exec /bin/bash -l' >> "/root/.profile" -# We need this to ship k8s components. (coredns, kube-apiserver, etc) -echo "##################################################### Install Local Registry" -mkdir -p /usr/local/bin - -apk add skopeo - -tar zxf registry.tar.gz -mv registry /usr/local/bin/registry -/usr/local/bin/registry --version - echo "##################################################### Installing CRI-O" +mkdir -p /usr/local/bin tar zxf crio.tar.gz cd cri-o ./install -crio --version crio config 2>&1 > /dev/null if [ $? -ne 0 ]; then crio config @@ -42,14 +25,19 @@ fi mv /etc/cni/net.d/10-crio-bridge.conflist.disabled \ /etc/cni/net.d/10-crio-bridge.conflist -echo "--------------" sed -i "s/default_runtime = \"crun\"/\0\ncgroup_manager = \"cgroupfs\"/g" /etc/crio/crio.conf.d/10-crio.conf grep cgroup_manager /etc/crio/crio.conf.d/10-crio.conf || exit 1 +chmod +x /opt/scripts/* +chmod +x /etc/init.d/* + mkdir -p /var/run/crio mkdir -p /var/lib/containers/storage mkdir -p /var/lib/cni +mkdir -p /var/log/crio mkdir -p /etc/cni/net.d mkdir -p /opt/cni/bin mkdir -p /run/crun mkdir -p /run/runc + +touch /var/log/crio/crio.log diff --git a/alpine/rootfs-extra/etc/init.d/crio b/alpine/rootfs-extra/etc/init.d/crio new file mode 100755 index 0000000..c0c49d3 --- /dev/null +++ b/alpine/rootfs-extra/etc/init.d/crio @@ -0,0 +1,39 @@ +#!/sbin/openrc-run +# Copyright 2015-2019 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +export PATH="/usr/local/bin:/usr/local/sbin:$PATH" + +description="OCI Kubernetes Container Runtime daemon" +pidfile=${pidfile:-"/run/${RC_SVCNAME}.pid"} +extra_started_commands="reload" +command="/usr/local/bin/${RC_SVCNAME}" +command_args="${command_args}" +command_background="true" +start_stop_daemon_args=" \ + --stdout /var/log/${RC_SVCNAME}/${RC_SVCNAME}.log \ + --stderr /var/log/${RC_SVCNAME}/${RC_SVCNAME}.log" + +depend() { + need net +} + +checkconfig() { + checkpath --directory --owner root:root --mode 0775 \ + /var/log/${RC_SVCNAME} + checkpath --file --owner root:root --mode 0644 \ + /var/log/${RC_SVCNAME}/${RC_SVCNAME}.log + checkpath --directory --owner root:root --mode 0750 \ + /var/lib/crio +} + +start() { + checkconfig + default_start +} + +reload() { + ebegin "Reloading ${RC_SVCNAME}" + start-stop-daemon --signal HUP --pidfile "${pidfile}" + eend $? +} diff --git a/build.env b/build.env index 769dd46..ead4d6d 100644 --- a/build.env +++ b/build.env @@ -8,9 +8,6 @@ NXP_VERSION=lf-6.18.2-1.0.0 CRIO_VERSION=cri-o.arm64.v1.35.1 KUBE_VERSION=v1.35.3 -# Local registry for exporting k8s images -REGISTRY_VERSION=2.8.3 - # Mono's tutorial said fsl-ls1046a-rdb.dtb but our shipped board is not that one # We need fsl-ls1046a-rdb-sdk.dtb here DEVICE_TREE_TARGET=mono-gateway-dk-sdk diff --git a/docker/alpine.Dockerfile b/docker/alpine.Dockerfile index 9d5a594..cdf5407 100644 --- a/docker/alpine.Dockerfile +++ b/docker/alpine.Dockerfile @@ -6,14 +6,12 @@ FROM --platform=$BUILDPLATFORM ${DOCKER_IMAGE_ROOT}/build-base:${TAG} AS build-b ARG ALPINE_ARCH ARG ALPINE_VER ARG CRIO_VERSION -ARG REGISTRY_VERSION ARG DEVICE_TREE_TARGET RUN mkdir -p "/out/rootfs" COPY packages/alpine-minirootfs-${ALPINE_VER}-${ALPINE_ARCH}.tar.gz ./alpine.tar.gz COPY packages/${CRIO_VERSION}.tar.gz ./crio.tar.gz -COPY packages/registry-${REGISTRY_VERSION}.tar.gz ./registry.tar.gz COPY out/board.itb ./ COPY out/rootfs ./rootfs COPY out/${DEVICE_TREE_TARGET}.dtb ./ diff --git a/makefile b/makefile index 04c5a8b..4c40939 100644 --- a/makefile +++ b/makefile @@ -10,7 +10,6 @@ BUSYBOX_TAR := $(PACKAGES_DIR)/busybox-$(BUSYBOX_VERSION).tar.gz ALPINE_TAR := $(PACKAGES_DIR)/alpine-minirootfs-$(ALPINE_VER)-$(ALPINE_ARCH).tar.gz NXP_TAR := $(PACKAGES_DIR)/$(NXP_VERSION).tar.gz CRIO_TAR := $(PACKAGES_DIR)/$(CRIO_VERSION).tar.gz -REGISTRY_TAR := $(PACKAGES_DIR)/registry-$(REGISTRY_VERSION).tar.gz # Kubernetes components KUBELET_BIN := $(PACKAGES_DIR)/kubernetes/kubelet @@ -71,7 +70,6 @@ RELEASE_DEPS := \ $(KUBELET_BIN) \ $(KUBEADM_BIN) \ $(KUBECTL_BIN) \ - $(REGISTRY_TAR) \ docker/alpine.Dockerfile \ $(ALPINE_SRCS) \ build.env \ @@ -105,9 +103,6 @@ $(BUSYBOX_TAR): | $(PACKAGES_DIR) $(ALPINE_TAR): | $(PACKAGES_DIR) curl -L -o $@ "https://dl-cdn.alpinelinux.org/alpine/v$(ALPINE_SERIES)/releases/$(ALPINE_ARCH)/alpine-minirootfs-$(ALPINE_VER)-$(ALPINE_ARCH).tar.gz" -$(REGISTRY_TAR): | $(PACKAGES_DIR) - curl -L -o $@ "https://github.com/distribution/distribution/releases/download/v$(REGISTRY_VERSION)/registry_$(REGISTRY_VERSION)_linux_$(ARCH).tar.gz" - $(NXP_TAR): | $(PACKAGES_DIR) curl -L -o $@ "https://github.com/nxp-qoriq/linux/archive/refs/tags/$(NXP_VERSION).tar.gz" @@ -164,7 +159,6 @@ $(RELEASE_IMAGE): $(RELEASE_DEPS) | $(OUT_DIR) --build-arg ALPINE_ARCH=$(ALPINE_ARCH) \ --build-arg ALPINE_VER=$(ALPINE_VER) \ --build-arg CRIO_VERSION=$(CRIO_VERSION) \ - --build-arg REGISTRY_VERSION=$(REGISTRY_VERSION) \ --build-arg DEVICE_TREE_TARGET=$(DEVICE_TREE_TARGET) \ -t $(DOCKER_IMAGE_ROOT)/buildenv-alpine:$(TAG) .