|
| 1 | +# Copyright 2018- The Pixie Authors. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# SPDX-License-Identifier: Apache-2.0 |
| 16 | + |
| 17 | +FROM ubuntu:18.04@sha256:8aa9c2798215f99544d1ce7439ea9c3a6dfd82de607da1cec3a8a2fae005931b |
| 18 | + |
| 19 | +# Install required packages |
| 20 | +RUN apt-get update |
| 21 | +RUN apt-get upgrade -y -q |
| 22 | +RUN apt-get install -y -q build-essential \ |
| 23 | + bc \ |
| 24 | + libelf-dev \ |
| 25 | + libssl-dev \ |
| 26 | + flex \ |
| 27 | + bison \ |
| 28 | + kmod \ |
| 29 | + cpio \ |
| 30 | + rsync \ |
| 31 | + wget \ |
| 32 | + binutils-aarch64-linux-gnu \ |
| 33 | + gcc-aarch64-linux-gnu \ |
| 34 | + dwarves \ |
| 35 | + python3 |
| 36 | + |
| 37 | +ARG KERN_VERSION |
| 38 | + |
| 39 | +# Download Linux sources |
| 40 | +WORKDIR /px/src |
| 41 | +RUN KERN_MAJ="$(echo "${KERN_VERSION}" | cut -d'.' -f1)"; \ |
| 42 | + wget -nv http://mirrors.edge.kernel.org/pub/linux/kernel/v${KERN_MAJ}.x/linux-${KERN_VERSION}.tar.gz |
| 43 | +RUN tar zxf linux-${KERN_VERSION}.tar.gz |
| 44 | + |
| 45 | +WORKDIR /configs |
| 46 | +ADD x86_64_config /configs/x86_64 |
| 47 | +ADD arm64_config /configs/arm64 |
| 48 | + |
| 49 | +ARG ARCH |
| 50 | +ARG CROSS_COMPILE |
| 51 | + |
| 52 | +# Build Linux kernel |
| 53 | +WORKDIR /px/src/linux-${KERN_VERSION} |
| 54 | +RUN cp /configs/${ARCH} .config |
| 55 | +RUN make ARCH=${ARCH} olddefconfig |
| 56 | +RUN make ARCH=${ARCH} clean |
| 57 | +RUN make ARCH=${ARCH} -j $(nproc) bindeb-pkg LOCALVERSION=-pl |
| 58 | + |
| 59 | +# Extract headers into a tarball |
| 60 | +WORKDIR /px |
| 61 | +RUN DEB_ARCH=$(echo ${ARCH} | sed 's/x86_64/amd64/g'); dpkg -x src/linux-headers-${KERN_VERSION}-pl_${KERN_VERSION}-pl-1_${DEB_ARCH}.deb . |
| 62 | + |
| 63 | +# Remove broken symlinks |
| 64 | +RUN find usr/src/linux-headers-${KERN_VERSION}-pl -xtype l -exec rm {} + |
| 65 | + |
| 66 | +# Remove uneeded files to reduce size |
| 67 | +# Keep only: |
| 68 | +# - usr/src/linux-headers-x.x.x-pl/include |
| 69 | +# - usr/src/linux-headers-x.x.x-pl/arch/${ARCH} |
| 70 | +# This reduces the size by a little over 2x. |
| 71 | +RUN rm -rf usr/share |
| 72 | +RUN find usr/src/linux-headers-${KERN_VERSION}-pl -maxdepth 1 -mindepth 1 ! -name include ! -name arch -type d \ |
| 73 | + -exec rm -rf {} + |
| 74 | +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 {} + |
| 75 | +RUN tar zcf linux-headers-${ARCH}-${KERN_VERSION}.tar.gz usr |
| 76 | + |
| 77 | +VOLUME /output |
| 78 | +CMD ["sh", "-c", "cp linux-headers-*.tar.gz /output/"] |
0 commit comments