From 64970aa459ad937480845e60a135a5184ed0d75e24f563851846f57a3881f053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Sun, 22 Mar 2026 00:59:37 +0800 Subject: [PATCH] Basic alpine chroot --- alpine/build-rootfs.sh | 3 +++ alpine/prepare-chroot.sh | 16 ++++++++++++++++ build.env | 3 +++ docker/alpine.Dockerfile | 22 ++++++++++++++++++++++ makefile | 18 ++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100755 alpine/build-rootfs.sh create mode 100755 alpine/prepare-chroot.sh create mode 100644 docker/alpine.Dockerfile diff --git a/alpine/build-rootfs.sh b/alpine/build-rootfs.sh new file mode 100755 index 0000000..286c1d4 --- /dev/null +++ b/alpine/build-rootfs.sh @@ -0,0 +1,3 @@ +#!/bin/bash + + diff --git a/alpine/prepare-chroot.sh b/alpine/prepare-chroot.sh new file mode 100755 index 0000000..31c57d9 --- /dev/null +++ b/alpine/prepare-chroot.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +mkdir -p "$ROOTFS/var/cache/apk" +mount --bind /var/cache/apk "$ROOTFS/var/cache/apk" +mount --bind /dev "$ROOTFS/dev" +mount --bind /proc "$ROOTFS/proc" +mount --bind /sys "$ROOTFS/sys" +mount --bind /run "$ROOTFS/run" + +cp /usr/bin/qemu-aarch64-static "$ROOTFS/usr/bin/" +cp /etc/resolv.conf "$ROOTFS/etc/resolv.conf" + +chroot "$ROOTFS" /bin/sh -c "ln -s /var/cache/apk /etc/apk/cache" +chroot "$ROOTFS" /bin/sh -c "apk update; apk add bash curl" +cp "/build-rootfs.sh" "$ROOTFS/build-rootfs.sh" +chroot "$ROOTFS" /bin/bash /build-rootfs.sh diff --git a/build.env b/build.env index d810f01..462bfe7 100644 --- a/build.env +++ b/build.env @@ -19,3 +19,6 @@ CROSS_COMPILE=aarch64-linux-gnu- # Busybox for initramfs BUSYBOX_VERSION=1_36_1 +## Alpine Linux +ALPINE_VER=3.23.3 +ALPINE_ARCH=aarch64 diff --git a/docker/alpine.Dockerfile b/docker/alpine.Dockerfile new file mode 100644 index 0000000..c74c809 --- /dev/null +++ b/docker/alpine.Dockerfile @@ -0,0 +1,22 @@ +ARG TAG=dev +ARG DOCKER_IMAGE_ROOT=monok8s +FROM --platform=linux/amd64 ${DOCKER_IMAGE_ROOT}/build-base:${TAG} AS build-base + +ARG ALPINE_ARCH +ARG ALPINE_VER + +RUN apt-get update && apt-get install -y qemu-user-static --no-install-recommends + +RUN mkdir -p "/out/rootfs" + +# RUN curl -L \ +# "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/${ALPINE_ARCH}/alpine-minirootfs-${ALPINE_VER}-${ALPINE_ARCH}.tar.gz" \ +# -o alpine-minirootfs.tar.gz +# RUN tar -xzf alpine-minirootfs.tar.gz -C "/out/rootfs" + +# Dev-only shortcut +COPY dev/alpine.tar.gz ./ + +RUN tar -xf alpine.tar.gz -C "/out/rootfs" + +COPY alpine/*.sh / diff --git a/makefile b/makefile index 5105286..36000a3 100644 --- a/makefile +++ b/makefile @@ -39,3 +39,21 @@ itb: fit-build --build-arg DEVICE_TREE_TARGET=$(DEVICE_TREE_TARGET) \ --output type=local,dest=./out \ -t $(DOCKER_IMAGE_ROOT)/itb:$(TAG) . + +buildenv-alpine: build-base + docker build \ + -f docker/alpine.Dockerfile \ + --build-arg DOCKER_IMAGE_ROOT=$(DOCKER_IMAGE_ROOT) \ + --build-arg TAG=$(TAG) \ + --build-arg ALPINE_ARCH=$(ALPINE_ARCH) \ + --build-arg ALPINE_VER=$(ALPINE_VER) \ + -t $(DOCKER_IMAGE_ROOT)/buildenv-alpine:$(TAG) . + +alpine-rootfs: buildenv-alpine + docker run --rm -it \ + --privileged \ + -v /cache/apk:/var/cache/apk \ + -v /cache/artifacts:/artifacts \ + -e ROOTFS=/out/rootfs \ + $(DOCKER_IMAGE_ROOT)/buildenv-alpine:$(TAG) \ + bash -lc '/prepare-chroot.sh && /build-rootfs.sh'