feat: subpackages support & linux refactor for subpackages

This commit is contained in:
Lance R. Vick 2024-09-08 14:49:32 -07:00
parent baed331bd3
commit 2b223c8e89
No known key found for this signature in database
GPG key ID: 8E47A1EC35A1551D
10 changed files with 47 additions and 216 deletions

View file

@ -1,57 +0,0 @@
FROM scratch AS base
ENV VERSION=6.7
ENV SRC_HASH=ef31144a2576d080d8c31698e83ec9f66bf97c677fa2aaf0d5bbb9f3345b1069
ENV SRC_FILE=linux-${VERSION}.tar.xz
ENV SRC_SITE=http://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/${SRC_FILE}
FROM base AS fetch
ADD --checksum=sha256:${SRC_HASH} ${SRC_SITE} .
FROM fetch AS build
COPY --from=stagex/musl . /
COPY --from=stagex/make . /
COPY --from=stagex/binutils . /
COPY --from=stagex/linux-headers . /
COPY --from=stagex/elfutils . /
COPY --from=stagex/openssl . /
COPY --from=stagex/perl . /
COPY --from=stagex/m4 . /
COPY --from=stagex/gcc . /
COPY --from=stagex/bison . /
COPY --from=stagex/libzstd . /
COPY --from=stagex/zlib . /
COPY --from=stagex/flex . /
COPY --from=stagex/pkgconf . /
COPY --from=stagex/coreutils . /
COPY --from=stagex/findutils . /
COPY --from=stagex/diffutils . /
COPY --from=stagex/tar . /
COPY --from=stagex/gzip . /
COPY --from=stagex/xz . /
COPY --from=stagex/sed . /
COPY --from=stagex/grep . /
COPY --from=stagex/gawk . /
COPY --from=stagex/bc . /
COPY --from=stagex/bash . /
COPY --from=stagex/bash /bin/bash /bin/sh
RUN tar -xf ${SRC_FILE}
WORKDIR /linux-${VERSION}
ADD linux.config .config
ENV KBUILD_BUILD_HOST=stagex
ENV KBUILD_BUILD_USER=user
ENV KBUILD_BUILD_TIMESTAMP=1
RUN <<-EOF
set -eux
make -j "$(nproc)" bzImage
EOF
FROM build AS install
RUN <<-EOF
set -eux
mkdir /rootfs
cp .config /rootfs/linux.config
cp arch/x86_64/boot/bzImage /rootfs
EOF
FROM stagex/filesystem AS package
COPY --from=install /rootfs/. /

View file

@ -1,57 +0,0 @@
FROM scratch AS base
ENV VERSION=6.7
ENV SRC_HASH=ef31144a2576d080d8c31698e83ec9f66bf97c677fa2aaf0d5bbb9f3345b1069
ENV SRC_FILE=linux-${VERSION}.tar.xz
ENV SRC_SITE=http://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/${SRC_FILE}
FROM base AS fetch
ADD --checksum=sha256:${SRC_HASH} ${SRC_SITE} .
FROM fetch AS build
COPY --from=stagex/musl . /
COPY --from=stagex/make . /
COPY --from=stagex/binutils . /
COPY --from=stagex/linux-headers . /
COPY --from=stagex/elfutils . /
COPY --from=stagex/openssl . /
COPY --from=stagex/perl . /
COPY --from=stagex/m4 . /
COPY --from=stagex/gcc . /
COPY --from=stagex/bison . /
COPY --from=stagex/libzstd . /
COPY --from=stagex/zlib . /
COPY --from=stagex/flex . /
COPY --from=stagex/pkgconf . /
COPY --from=stagex/coreutils . /
COPY --from=stagex/findutils . /
COPY --from=stagex/diffutils . /
COPY --from=stagex/tar . /
COPY --from=stagex/gzip . /
COPY --from=stagex/xz . /
COPY --from=stagex/sed . /
COPY --from=stagex/grep . /
COPY --from=stagex/gawk . /
COPY --from=stagex/bc . /
COPY --from=stagex/bash . /
COPY --from=stagex/bash /bin/bash /bin/sh
RUN tar -xf ${SRC_FILE}
WORKDIR /linux-${VERSION}
ADD linux.config .config
ENV KBUILD_BUILD_HOST=stagex
ENV KBUILD_BUILD_USER=user
ENV KBUILD_BUILD_TIMESTAMP=1
RUN <<-EOF
set -eux
make -j "$(nproc)" bzImage
EOF
FROM build AS install
RUN <<-EOF
set -eux
mkdir /rootfs
cp .config /rootfs/linux.config
cp arch/x86_64/boot/bzImage /rootfs
EOF
FROM stagex/filesystem AS package
COPY --from=install /rootfs/. /

View file

@ -1,26 +0,0 @@
FROM scratch AS base
ENV VERSION=6.6
ENV SRC_HASH=d926a06c63dd8ac7df3f86ee1ffc2ce2a3b81a2d168484e76b5b389aba8e56d0
ENV SRC_FILE=linux-${VERSION}.tar.xz
ENV SRC_SITE=https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/${SRC_FILE}
FROM base AS fetch
ADD --checksum=sha256:${SRC_HASH} ${SRC_SITE} .
FROM fetch AS build
COPY --from=stagex/stage3 . /
RUN tar -xf linux-${VERSION}.tar.xz
WORKDIR /linux-${VERSION}
RUN --network=none make headers
FROM build AS install
RUN <<-EOF
set -eux
mkdir -p /rootfs/usr
cp -a usr/include /rootfs/usr/
find /rootfs/usr/include/ ! -iname "*.h" -type f -exec rm -v {} \+
rm -rf /rootfs/usr/include/drm
EOF
FROM stagex/filesystem AS package
COPY --from=install /rootfs/. /

View file

@ -1,69 +0,0 @@
FROM scratch AS base
ENV VERSION=5.19.6
ENV SRC_HASH=41a4f824af614460c429a7c723e8dcbb0e042f0047d328c18b4ed6f2b4efa63a
ENV SRC_FILE=linux-${VERSION}.tar.xz
ENV SRC_SITE=http://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/${SRC_FILE}
ENV NSM_VERSION=ed24913346a34d719afa2031299253160a2e3460
ENV NSM_SRC_HASH=720916a640f7579a1e9a972ddd43448d201b9ce4d4750079d8256e83be3e937c
ENV NSM_SRC_FILE=nsm.tgz
ENV NSM_SRC_SITE=https://codeload.github.com/aws/aws-nitro-enclaves-sdk-bootstrap/legacy.tar.gz/${NSM_VERSION}
FROM base AS fetch
ADD --checksum=sha256:${SRC_HASH} ${SRC_SITE} .
ADD --checksum=sha256:${NSM_SRC_HASH} ${NSM_SRC_SITE} ${NSM_SRC_FILE}
FROM fetch AS build
COPY --from=stagex/musl . /
COPY --from=stagex/make . /
COPY --from=stagex/binutils . /
COPY --from=stagex/linux-headers . /
COPY --from=stagex/elfutils . /
COPY --from=stagex/openssl . /
COPY --from=stagex/perl . /
COPY --from=stagex/m4 . /
COPY --from=stagex/gcc . /
COPY --from=stagex/bison . /
COPY --from=stagex/libzstd . /
COPY --from=stagex/zlib . /
COPY --from=stagex/flex . /
COPY --from=stagex/pkgconf . /
COPY --from=stagex/coreutils . /
COPY --from=stagex/findutils . /
COPY --from=stagex/diffutils . /
COPY --from=stagex/tar . /
COPY --from=stagex/gzip . /
COPY --from=stagex/xz . /
COPY --from=stagex/sed . /
COPY --from=stagex/grep . /
COPY --from=stagex/gawk . /
COPY --from=stagex/bc . /
COPY --from=stagex/bash . /
COPY --from=stagex/bash /bin/bash /bin/sh
RUN mkdir nitro-bootstrap
RUN tar -xf ${NSM_SRC_FILE} -C nitro-bootstrap --strip-components 1
RUN tar -xf ${SRC_FILE}
WORKDIR /linux-${VERSION}
ADD linux.config .config
ENV KBUILD_BUILD_HOST=stagex
ENV KBUILD_BUILD_USER=user
ENV KBUILD_BUILD_TIMESTAMP=1
RUN <<-EOF
set -eux
make olddefconfig
make -j "$(nproc)" bzImage
make -j "$(nproc)" modules_prepare
cd ../nitro-bootstrap
make -C ../linux-${VERSION} M=../nitro-bootstrap/nsm-driver
EOF
FROM build AS install
RUN <<-EOF
set -eux
mkdir /rootfs
cp .config /rootfs/linux.config
cp arch/x86_64/boot/bzImage /rootfs
cp /nitro-bootstrap/nsm-driver/nsm.ko /rootfs
EOF
FROM stagex/filesystem AS package
COPY --from=install /rootfs/. /

View file

@ -1,3 +1,5 @@
ARG SUBPACKAGE=generic
FROM scratch AS base
ENV VERSION=6.6
ENV SRC_HASH=d926a06c63dd8ac7df3f86ee1ffc2ce2a3b81a2d168484e76b5b389aba8e56d0
@ -7,7 +9,7 @@ ENV SRC_SITE=http://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/${SRC_FILE}
FROM base AS fetch
ADD --checksum=sha256:${SRC_HASH} ${SRC_SITE} .
FROM fetch AS build
FROM fetch AS prepare
COPY --from=stagex/musl . /
COPY --from=stagex/make . /
COPY --from=stagex/binutils . /
@ -55,11 +57,29 @@ RUN <<-EOF
! grep -q "^$conf=" .config
done
make oldconfig
mkdir /rootfs
EOF
FROM prepare AS build-headers
RUN --network=none make headers
FROM build-headers AS install-linux-headers
RUN <<-EOF
set -eux
mkdir -p /rootfs/usr
cp -a usr/include /rootfs/usr/
find /rootfs/usr/include/ ! -iname "*.h" -type f -exec rm -v {} \+
rm -rf /rootfs/usr/include/drm
EOF
FROM prepare AS build-generic
RUN <<-EOF
set -eux
make -j "$(nproc)" bzImage
make -j "$(nproc)" modules INSTALL_MOD_PATH=/rootfs
EOF
FROM build AS install
FROM build-generic AS install-linux-generic
RUN <<-EOF
set -eux
mkdir -p /rootfs/usr/lib/modules
@ -68,5 +88,18 @@ RUN <<-EOF
cp arch/x86_64/boot/bzImage /rootfs
EOF
FROM prepare AS build
ADD ${SUBPACKAGE}.config .config
RUN --network=none make -j "$(nproc)" bzImage
FROM build AS install-linux-airgap
RUN cp arch/x86_64/boot/bzImage
FROM build AS install-linux-nitro
RUN cp arch/x86_64/boot/bzImage
FROM build AS install-linux-guest
RUN cp arch/x86_64/boot/bzImage
FROM stagex/filesystem AS package
COPY --from=install /rootfs/. /
COPY --from=install-${SUBPACKAGE} /rootfs/. /

View file

@ -33,7 +33,7 @@ include src/macros.mk
out:
mkdir out
all_packages := $(shell $(call folder-list,packages))
all_packages := $(shell $(call package-list))
$(all_packages): %: out/%/index.json

View file

@ -54,6 +54,16 @@ define folder-list
ls -1 $(FOLDER) 2>/dev/null | while IFS= read -r f; do printf "$$f "; done
endef
define package-list
ls -1 packages 2>/dev/null | while IFS= read -r f; do \
grep -Ri "AS install-" packages/$${f}/Containerfile \
| sed -e 's/.*install-//g' \
| tr '\n' ' '; \
grep -Ri "AS install$$" packages/$${f}/Containerfile >/dev/null \
&& printf "$${f} "; \
done
endef
define gen-target
out/$(1)/index.json: $(shell $(call dep-list,$(1))) $(shell find packages/$(1)) | out
$(call build,$(1))
@ -65,9 +75,6 @@ define build-context-args
| sed -e 's/COPY --from=stagex\/\([a-z0-9._-]\+\) .*/\1/g' \
| uniq \
| while IFS= read -r package; do \
if [ "$$package" = "$(PACKAGE)" ]; then
continue; \
fi; \
printf -- ' --build-context %s=oci-layout://./out/%s' "stagex/$${package}" "$${package}"; \
done
endef