From 000b6f4bb1a6b6c1b43d5faa13e64c814a42315e Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Wed, 28 Feb 2024 15:55:28 +0200 Subject: [PATCH] switch kernel builds to linuxkit pkg build for simplicity Signed-off-by: Avi Deitcher --- docs/kernels.md | 9 ++- kernel/6.6.x/build-args | 3 + kernel/Dockerfile | 5 +- kernel/Dockerfile.bcc | 3 +- kernel/Dockerfile.perf | 3 +- kernel/Makefile | 124 ++++++++++++---------------------------- kernel/build-args-debug | 1 + kernel/build-bcc.yml | 2 + kernel/build-kernel.yml | 2 + kernel/build-perf.yml | 2 + 10 files changed, 60 insertions(+), 94 deletions(-) create mode 100644 kernel/6.6.x/build-args create mode 100644 kernel/build-args-debug create mode 100644 kernel/build-bcc.yml create mode 100644 kernel/build-kernel.yml create mode 100644 kernel/build-perf.yml diff --git a/docs/kernels.md b/docs/kernels.md index 0b4fa0e89..d35b4cd1b 100644 --- a/docs/kernels.md +++ b/docs/kernels.md @@ -333,7 +333,7 @@ Finally, test that you can build the kernel with that config as `make build-`, e.g. `make build-5.15.148`. ## Adding a new kernel series @@ -353,6 +354,12 @@ To add a new kernel series, you need to: 1. Create new directory for the series, e.g. `6.7.x` 1. Create config files for each architecture in that directory 1. Optionally, create a `patches/` subdirectory in that directory with any patches to add +1. Create a `build-args` file in that directory with at least the following settings: +```bash +KERNEL_VERSION= +KERNEL_SERIES= +BUILD_IMAGE=linuxkit/alpine: +``` 1. Update the list of kernels to build in the `Makefile` Since the last major series likely is the best basis for the new one, subject to additional modifications, you can use diff --git a/kernel/6.6.x/build-args b/kernel/6.6.x/build-args new file mode 100644 index 000000000..7a790d428 --- /dev/null +++ b/kernel/6.6.x/build-args @@ -0,0 +1,3 @@ +KERNEL_VERSION=6.6.13 +KERNEL_SERIES=6.6.x +BUILD_IMAGE=linuxkit/alpine:146f540f25cd92ec8ff0c5b0c98342a9a95e479e diff --git a/kernel/Dockerfile b/kernel/Dockerfile index 53f0235f8..9d08f7134 100644 --- a/kernel/Dockerfile +++ b/kernel/Dockerfile @@ -11,6 +11,7 @@ RUN apk add \ build-base \ curl \ diffutils \ + findutils \ flex \ git \ gmp-dev \ @@ -54,7 +55,7 @@ RUN KERNEL_MAJOR=$(echo ${KERNEL_VERSION} | cut -d . -f 1) && \ KERNEL_SHA256_SUMS=https://www.kernel.org/pub/linux/kernel/${KERNEL_MAJOR}/sha256sums.asc && \ KERNEL_PGP2_SIGN=https://www.kernel.org/pub/linux/kernel/${KERNEL_MAJOR}/linux-${KERNEL_VERSION}.tar.sign && \ curl -fsSLO ${KERNEL_SHA256_SUMS} && \ - gpg2 -q --import keys.asc && \ + gpg2 -q --import /src/keys.asc && \ gpg2 --verify sha256sums.asc && \ KERNEL_SHA256=$(grep linux-${KERNEL_VERSION}.tar.xz sha256sums.asc | cut -d ' ' -f 1) && \ [ -f linux-${KERNEL_VERSION}.tar.xz ] || curl -fsSLO ${KERNEL_SOURCE} && \ @@ -177,8 +178,10 @@ RUN DVER=$(basename $(find /tmp/kernel-modules/lib/modules/ -mindepth 1 -maxdept RUN printf "${BUILD_IMAGE}" > /out/kernel-builder +ARG BUILD_IMAGE FROM scratch ENTRYPOINT [] CMD [] WORKDIR / +LABEL org.mobyproject.linuxkit.kernel.buildimage=${BUILD_IMAGE} COPY --from=kernel-build /out/* / diff --git a/kernel/Dockerfile.bcc b/kernel/Dockerfile.bcc index a2129910b..9d500a405 100644 --- a/kernel/Dockerfile.bcc +++ b/kernel/Dockerfile.bcc @@ -1,7 +1,6 @@ -ARG IMAGE ARG BUILD_IMAGE -FROM ${IMAGE} as ksrc +FROM ${KERNEL_VERSION}-${HASH} as ksrc FROM ${BUILD_IMAGE} AS build RUN apk update && apk upgrade -a && \ diff --git a/kernel/Dockerfile.perf b/kernel/Dockerfile.perf index d25849f2d..becca6a7a 100644 --- a/kernel/Dockerfile.perf +++ b/kernel/Dockerfile.perf @@ -1,9 +1,8 @@ # This Dockerfile extracts the source code and headers from a kernel package, # builds the perf utility, and places it into a scratch image -ARG IMAGE ARG BUILD_IMAGE -FROM ${IMAGE} AS ksrc +FROM ${KERNEL_VERSION}-${HASH} AS ksrc FROM ${BUILD_IMAGE} AS build RUN apk add \ diff --git a/kernel/Makefile b/kernel/Makefile index 5d14beafb..5ba82057e 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -15,10 +15,7 @@ RM = rm -f # Name and Org on Hub ORG?=linuxkit -PLATFORMS?=linux/amd64,linux/arm64 IMAGE?=kernel -IMAGE_BCC:=kernel-bcc -IMAGE_PERF:=kernel-perf IMAGE_BUILDER=linuxkit/alpine:146f540f25cd92ec8ff0c5b0c98342a9a95e479e # You can specify an extra options for the Makefile. This will: @@ -42,7 +39,7 @@ PUSH_MANIFEST:=$(shell git rev-parse --show-toplevel)/scripts/push-manifest.sh # determine our architecture BUILDERARCH= -ARCH := $(shell uname -m) +ifneq ($(ARCH),) ifeq ($(ARCH),$(filter $(ARCH),x86_64 amd64)) SUFFIX=-amd64 override ARCH=x86_64 @@ -53,22 +50,14 @@ SUFFIX=-arm64 override ARCH=aarch64 BUILDERARCH=arm64 endif +endif + +ifneq ($(BUILDERARCH),) +PLATFORMS=--platforms linux/$(BUILDERARCH) +endif HASHTAG=$(HASH)$(DIRTY) -BUILD_LABEL=--label org.mobyproject.linuxkit.kernel.buildimage=$(IMAGE_BUILDER) - -REPO?=https://github.com/linuxkit/linuxkit -ifneq ($(REPO),) -REPO_LABEL=--label org.opencontainers.image.source=$(REPO) -endif -ifeq ($(DIRTY),) -REPO_COMMIT=$(shell git rev-parse HEAD) -COMMIT_LABEL=--label org.opencontainers.image.revision=$(REPO_COMMIT) -endif - -LABELS=$(REPO_LABEL) $(COMMIT_LABEL) $(BUILD_LABEL) - .PHONY: notdirty notdirty: @if [ x"$(DIRTY)" != x ]; then echo "Your repository is not clean. Will not push image"; exit 1; fi @@ -82,15 +71,9 @@ series = $(word 1,$(subst ., ,$(1))).$(word 2,$(subst ., ,$(1))).x RELEASESEP := PART toolname = $(word 2, $(subst $(RELEASESEP), ,$(1))) toolkernel = $(word 1, $(subst $(RELEASESEP), ,$(1))) -toolimageextension = -$(call toolname,$(1)):$(call toolkernel,$(1))$(EXTRA)$(DEBUG) -toolimagebase = $(ORG)/$(IMAGE)$(call toolimageextension,$(1)) -toolimagehash = $(call toolimagebase,$(1))-$(HASHTAG)$(SUFFIX) -toolimagenohash = $(call toolimagebase,$(1))$(SUFFIX) -toolkernelimage = $(ORG)/$(IMAGE):$(call toolkernel,$(1))$(EXTRA)$(DEBUG)-$(HASHTAG)$(SUFFIX) baseimageextension = :$(1)$(EXTRA)$(DEBUG) baseimage = $(ORG)/$(IMAGE)$(call baseimageextension,$(1)) uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) -cross_product = $(foreach p,$(1),$(addprefix $(p),$(2))) # @@ -124,7 +107,7 @@ list: @echo "Tools: $(TOOLS)" setforce: - $(eval FORCE=1) + $(eval FORCE=--force) build: $(addprefix build-,$(KERNELS)) push: $(addprefix push-,$(KERNELS)) show-tags: $(addprefix show-tag-,$(KERNELS)) @@ -135,46 +118,13 @@ buildkernel-%: buildkerneldeps-% buildplainkernel-% builddebugkernel-%; buildkerneldeps-%: Dockerfile Makefile $(wildcard patches-$(call series,$*)/*) $(wildcard config-$(call series,$*)*) ; -BUILDER?= -BUILDER_TEMPLATE = linuxkit-linux-{{.Arch}}-builder -BULDER_ARG = - - -# Phony target for conditional logic -.PHONY: getbuilder -# determine the builder -# if it was set by user, just add `--builder `. -# If not, see if our default builder pattern is available, and use that, else -# fall back to usual docker. -getbuilder: -ifeq ($(BUILDER),) - $(eval BUILDERNAME=$(subst {{.Arch}},$(BUILDERARCH),$(BUILDER_TEMPLATE))) - $(eval BUILDER_FOUND=$(shell docker builder inspect $(BUILDERNAME) 2>/dev/null || true)) - $(eval BUILDER_ARG=$(if $(BUILDER_FOUND),--builder $(BUILDERNAME),)) -else - $(eval BUILDERNAME=$(subst {{.Arch}},$(BUILDERARCH),$(BUILDER))) - $(eval BUILDER_ARG=--builder $(BUILDERNAME)) -endif - -buildplainkernel-%: buildkerneldeps-% getbuilder - $(eval BASEIMAGE=$(call baseimage,$*)) - $(eval TARGETIMAGE=$(BASEIMAGE)-$(HASHTAG)$(SUFFIX)) - $(eval EXTRATOOL=$(addprefix -,$(word 2,$(subst -, ,$*)))) - ([ -z "$(FORCE)" ] && docker manifest inspect $(TARGETIMAGE) >/dev/null 2>&1) || \ - docker build \ - $(BUILDER_ARG) \ - --platform linux/$(BUILDERARCH) \ - --build-arg KERNEL_VERSION=$* \ - --build-arg KERNEL_SERIES=$(call series,$*) \ - --build-arg EXTRA=$(EXTRATOOL) \ - --build-arg DEBUG=$(DEBUG) \ - --build-arg BUILD_IMAGE=$(IMAGE_BUILDER) \ - $(LABELS) \ - --load \ - --no-cache -t $(TARGETIMAGE) . +buildplainkernel-%: buildkerneldeps-% + $(eval KERNEL_SERIES=$(call series,$*)) + linuxkit pkg build . $(FORCE) $(PLATFORMS) --build-yml ./build-kernel.yml --tag "$*-{{.Hash}}" --build-arg-file $(KERNEL_SERIES)/build-args builddebugkernel-%: buildkerneldeps-% - $(MAKE) buildplainkernel-$* DEBUG=-dbg + $(eval KERNEL_SERIES=$(call series,$*)) + linuxkit pkg build . $(FORCE) $(PLATFORMS) --build-yml ./build-kernel.yml --tag "$*-dbg-{{.Hash}}" --build-arg-file $(KERNEL_SERIES)/build-args --build-arg-file build-args-debug push-%: notdirty build-% pushkernel-% tagbuilder-% pushtools-%; @@ -184,43 +134,41 @@ tagbuilder-%: notdirty docker push $(BUILDER_IMAGE)$(SUFFIX) && \ $(PUSH_MANIFEST) $(BUILDER_IMAGE) -pushtagpush-%: - $(eval BASEIMAGE=$(ORG)/$(IMAGE)$*) - $(eval HASHIMAGE=$(BASEIMAGE)-$(HASHTAG)) - $(eval SUFFIXEDIMAGE=$(BASEIMAGE)$(SUFFIX)) - $(eval HASHANDSUFFIXIMAGE=$(HASHIMAGE)$(SUFFIX)) - ([ -z "$(FORCE)" ] && docker manifest inspect $(HASHANDSUFFIXIMAGE) >/dev/null 2>&1) || \ - (docker push $(HASHANDSUFFIXIMAGE) && \ - docker tag $(HASHANDSUFFIXIMAGE) $(SUFFIXEDIMAGE) && \ - docker push $(SUFFIXEDIMAGE) && \ - $(PUSH_MANIFEST) $(HASHIMAGE) && \ - $(PUSH_MANIFEST) $(BASEIMAGE)) +pushkernel-%: pushplainkernel-% pushdebugkernel-%; -pushkernel-%: - $(MAKE) pushtagpush-$(call baseimageextension,$*) +pushplainkernel-%: buildplainkernel-% + $(eval HASHED_IMAGE=$(shell linuxkit pkg show-tag . --build-yml ./build-kernel.yml --tag "$*-{{.Hash}}")) + $(eval PLAIN_IMAGE=$(shell linuxkit pkg show-tag . --build-yml ./build-kernel.yml --tag "$*")) + linuxkit cache push $(HASHED_IMAGE) + linuxkit cache push $(HASHED_IMAGE) --remote-name $(PLAIN_IMAGE) + +pushdebugkernel-%: builddebugkernel-% + $(eval HASHED_IMAGE=$(shell linuxkit pkg show-tag . --build-yml ./build-kernel.yml --tag "$*-dbg-{{.Hash}}")) + $(eval PLAIN_IMAGE=$(shell linuxkit pkg show-tag . --build-yml ./build-kernel.yml --tag "$*-dbg")) + linuxkit cache push $(HASHED_IMAGE) + linuxkit cache push $(HASHED_IMAGE) --remote-name $(PLAIN_IMAGE) show-tag-%: @echo $(eval BASEIMAGE=$(call baseimage,$*))-$(HASHTAG) buildtools-%: $(addprefix buildtool-%$(RELEASESEP),$(TOOLS)); -buildtool-%: getbuilder - $(eval TARGETIMAGE=$(call toolimagehash,$*)) - $(eval KERNELIMAGE=$(call toolkernelimage,$*)) +buildtool-%: $(eval TOOL=$(call toolname,$*)) - ([ -z "$(FORCE)" ] && docker manifest inspect $(TARGETIMAGE) >/dev/null 2>&1) || \ - docker build -f Dockerfile.$(TOOL) \ - $(BUILDER_ARG) \ - --platform linux/$(BUILDERARCH) \ - --build-arg IMAGE=$(KERNELIMAGE) \ - --build-arg BUILD_IMAGE=$(IMAGE_BUILDER) \ - --load \ - --no-cache $(LABEL) -t $(TARGETIMAGE) . + $(eval KERNEL_VERSION=$(call toolkernel,$*)) + $(eval KERNEL_SERIES=$(call series,$(KERNEL_VERSION))) + linuxkit pkg build . $(FORCE) $(PLATFORMS) --build-yml ./build-$(TOOL).yml --tag "$(KERNEL_VERSION)-{{.Hash}}" --build-arg-file $(KERNEL_SERIES)/build-args pushtools-%: $(addprefix pushtool-%$(RELEASESEP),$(TOOLS)); -pushtool-%: - $(MAKE) pushtagpush-$(call toolimageextension,$*) +pushtool-%: buildtool-% + $(eval TOOL=$(call toolname,$*)) + $(eval KERNEL_VERSION=$(call toolkernel,$*)) + $(eval KERNEL_SERIES=$(call series,$(KERNEL_VERSION))) + $(eval HASHED_IMAGE=$(shell linuxkit pkg show-tag . --build-yml ./build-$(TOOL).yml --tag "$(KERNEL_VERSION)-{{.Hash}}")) + $(eval PLAIN_IMAGE=$(shell linuxkit pkg show-tag . --build-yml ./build-$(TOOL).yml --tag "$(KERNEL_VERSION)")) + linuxkit cache push $(HASHED_IMAGE) + linuxkit cache push $(HASHED_IMAGE) --remote-name $(PLAIN_IMAGE) # Target for kernel config kconfig: diff --git a/kernel/build-args-debug b/kernel/build-args-debug new file mode 100644 index 000000000..d3cb6fdf7 --- /dev/null +++ b/kernel/build-args-debug @@ -0,0 +1 @@ +DEBUG=-dbg diff --git a/kernel/build-bcc.yml b/kernel/build-bcc.yml new file mode 100644 index 000000000..de0cc8c2c --- /dev/null +++ b/kernel/build-bcc.yml @@ -0,0 +1,2 @@ +image: kernel-bcc +network: true diff --git a/kernel/build-kernel.yml b/kernel/build-kernel.yml new file mode 100644 index 000000000..c6fc6c92b --- /dev/null +++ b/kernel/build-kernel.yml @@ -0,0 +1,2 @@ +image: kernel +network: true diff --git a/kernel/build-perf.yml b/kernel/build-perf.yml new file mode 100644 index 000000000..5fb9a8b0c --- /dev/null +++ b/kernel/build-perf.yml @@ -0,0 +1,2 @@ +image: kernel-perf +network: true