1414#
1515# SPDX-License-Identifier: Apache-2.0
1616
17- # debhelper-compat (= 12) needed for kernels >= 6.3
18- FROM ubuntu:20.04@sha256:8feb4d8ca5354def3d8fce243717141ce31e2c428701f6682bd2fafe15388214
17+ ARG BASE_IMAGE
18+ FROM ${BASE_IMAGE}
19+
20+ ARG KERN_VERSION
21+ ARG ARCH
22+ ARG CROSS_COMPILE="false"
1923
2024# Install required packages
2125ENV DEBIAN_FRONTEND=noninteractive
26+ ENV KERN_VERSION=${KERN_VERSION}
27+ ENV ARCH=${ARCH}
28+ ENV CROSS_COMPILE=${CROSS_COMPILE}
29+
2230RUN apt-get update
2331RUN apt-get upgrade -y -q
2432RUN apt-get install -y -q build-essential \
@@ -37,47 +45,15 @@ RUN apt-get install -y -q build-essential \
3745 debhelper \
3846 python3
3947
40- ARG KERN_VERSION
41-
42- # Download Linux sources
43- WORKDIR /px/src
44- RUN KERN_MAJ="$(echo " ${KERN_VERSION}" | cut -d'.' -f1)" ; \
45- wget -nv http://mirrors.edge.kernel.org/pub/linux/kernel/v${KERN_MAJ}.x/linux-${KERN_VERSION}.tar.gz
46- RUN tar zxf linux-${KERN_VERSION}.tar.gz
47-
4848WORKDIR /configs
4949ADD x86_64_config /configs/x86_64
5050ADD arm64_config /configs/arm64
5151
52- ARG ARCH
53- ARG CROSS_COMPILE
54-
55- # Build Linux kernel
56- WORKDIR /px/src/linux-${KERN_VERSION}
57- RUN cp /configs/${ARCH} .config
58- RUN make ARCH=${ARCH} olddefconfig
59- RUN make ARCH=${ARCH} clean
60- RUN make ARCH=${ARCH} -j $(nproc) bindeb-pkg LOCALVERSION=-pl
61-
62- # Extract headers into a tarball
6352WORKDIR /px
64- # Unlike the bionic container build, Linux 6.3 and later name the resulting package without the additional -pl suffix.
65- # This difference stems from changes in the Linux build process itself, not from any modifications on our end.
66- RUN DEB_ARCH=$(echo ${ARCH} | sed 's/x86_64/amd64/g' ); dpkg -x src/linux-headers-${KERN_VERSION}-pl_${KERN_VERSION}-1_${DEB_ARCH}.deb .
6753
68- # Remove broken symlinks
69- RUN find usr/src/linux-headers-${KERN_VERSION}-pl -xtype l -exec rm {} +
54+ ADD build_linux_headers.sh /px/build_linux_headers.sh
7055
71- # Remove uneeded files to reduce size
72- # Keep only:
73- # - usr/src/linux-headers-x.x.x-pl/include
74- # - usr/src/linux-headers-x.x.x-pl/arch/${ARCH}
75- # This reduces the size by a little over 2x.
76- RUN rm -rf usr/share
77- RUN find usr/src/linux-headers-${KERN_VERSION}-pl -maxdepth 1 -mindepth 1 ! -name include ! -name arch -type d \
78- -exec rm -rf {} +
79- RUN find usr/src/linux-headers-${KERN_VERSION}-pl/arch -maxdepth 1 -mindepth 1 ! -name $(echo ${ARCH} | sed 's/x86_64/x86/g' ) -type d -exec rm -rf {} +
80- RUN tar zcf linux-headers-${ARCH}-${KERN_VERSION}.tar.gz usr
56+ RUN chmod +x /px/build_linux_headers.sh
8157
8258VOLUME /output
83- CMD ["sh" , "-c" , "cp linux-headers-*.tar.gz /output/ " ]
59+ CMD ["sh" , "-c" , "/px/build_linux_headers.sh /px ${KERN_VERSION} ${ARCH} ${CROSS_COMPILE} /output " ]
0 commit comments