Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Build kernel from a specific git tag #725

Merged
merged 2 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions images/kernel/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
FROM luxas/kernel-builder:gcc-7 AS builder
FROM weaveworks/ignite-kernel-builder:dev AS builder

# Install crosscompilers for non-amd64 arches
RUN apt-get update && \
apt-get install -y --no-install-recommends \
binutils-multiarch \
gcc-7-aarch64-linux-gnu && \
ln -s /usr/bin/aarch64-linux-gnu-gcc-7 /usr/bin/aarch64-linux-gnu-gcc

# Fetch the latest tags from the linux kernel repo
RUN git fetch --tags
# Set up environment variables
ENV CCACHE_DIR=/ccache \
SRC_DIR=/usr/src \
DIST_DIR=/dist \
LINUX_DIR=/usr/src/linux \
LINUX_REPO_URL=git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

ARG KERNEL_VERSION
ARG KERNEL_EXTRA
Expand All @@ -17,9 +14,13 @@ ARG ARCH
ARG GOARCH
ARG ARCH_MAKE_PARAMS

# Checkout the desired kernel version and make sure the environment is clean
RUN git checkout v${KERNEL_VERSION} && \
make clean && make mrproper
# Clone the desired kernel version and make sure the environment is clean
RUN mkdir -p ${SRC_DIR} ${CCACHE_DIR} ${DIST_DIR} && \
git clone --depth 1 --branch v${KERNEL_VERSION} ${LINUX_REPO_URL} ${LINUX_DIR} && \
cd ${LINUX_DIR} && make clean && make mrproper

# Change workdir to run all the build commands from LINUX_DIR.
WORKDIR ${LINUX_DIR}

COPY generated/config-${GOARCH}-${KERNEL_VERSION}${KERNEL_EXTRA} .config

Expand Down
9 changes: 7 additions & 2 deletions images/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CTR := $(DOCKER) run -i --rm \

REGISTRY?=weaveworks
IMAGE_NAME?=${REGISTRY}/ignite-kernel
KERNEL_BUILDER_NAME=${REGISTRY}/ignite-kernel-builder
# Check https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/refs/ for updates
KERNEL_VERSIONS ?= 4.14.182 4.19.125 5.4.43 # If you update this, please keep the .github/workflows/release-kernel-images.yml matrix up to date
GOARCH?=amd64
Expand All @@ -44,17 +45,21 @@ endif

all: build

kernel-builder:
$(DOCKER) build -t ${KERNEL_BUILDER_NAME}:dev \
-f builder/Dockerfile .

upgrade: $(addprefix upgrade-,$(KERNEL_VERSIONS))
./patch-config.sh
for file in generated/*; do \
./upgrade-config.sh $$file $$file; done

upgrade-%:
upgrade-%: kernel-builder
for file in upstream/*; do \
./upgrade-config.sh $$file versioned/$$(basename $$file)-$*; done

build: $(addprefix build-,$(KERNEL_VERSIONS))
build-%:
build-%: kernel-builder
$(DOCKER) build -t $(IMAGE_NAME):$*-${GOARCH} \
--build-arg KERNEL_VERSION=$* \
--build-arg ARCH=${KERNEL_ARCH} \
Expand Down
27 changes: 27 additions & 0 deletions images/kernel/builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ubuntu:18.04 AS builder

ARG GCC_VERSION="gcc-7"

# Install dependencies
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
bc \
bison \
build-essential \
ccache \
flex \
${GCC_VERSION} \
git \
kmod \
libelf-dev \
libncurses-dev \
libssl-dev \
wget \
ca-certificates && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/${GCC_VERSION} 10

# Install crosscompilers for non-amd64 arches
RUN apt-get install -y --no-install-recommends \
binutils-multiarch \
${GCC_VERSION}-aarch64-linux-gnu && \
ln -s /usr/bin/aarch64-linux-gnu-${GCC_VERSION} /usr/bin/aarch64-linux-gnu-gcc
9 changes: 5 additions & 4 deletions images/kernel/upgrade-config.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

KERNEL_BUILDER_IMAGE=luxas/kernel-builder:gcc-7
KERNEL_BUILDER_IMAGE=weaveworks/ignite-kernel-builder:dev
LINUX_REPO_URL=git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

DOCKER_TTY="${DOCKER_TTY:+"-t"}"

Expand All @@ -23,12 +24,12 @@ if [[ ${FROM} != ${TO} ]]; then
cp ${FROM} ${TO}
fi

docker pull ${KERNEL_BUILDER_IMAGE}
docker run -i ${DOCKER_TTY} \
docker run --rm -i ${DOCKER_TTY} \
${ARCH_PARAMETER} \
-v $(pwd)/${TO}:/tmp/.config \
${KERNEL_BUILDER_IMAGE} /bin/bash -c "\
git checkout v${VERSION} && \
git clone --depth 1 --branch v${VERSION} ${LINUX_REPO_URL} linux && \
cd linux &&
make clean && make mrproper && cp /tmp/.config . && \
make EXTRAVERSION="" LOCALVERSION= olddefconfig && \
cp .config /tmp/.config"