Skip to content

Commit

Permalink
kernel: build: Add container build
Browse files Browse the repository at this point in the history
Add script to build kernel in a container.

Signed-off-by: Carlos Venegas <jos.c.venegas.munoz@intel.com>
  • Loading branch information
jcvenegas committed Jul 28, 2021
1 parent b789a93 commit d46ae32
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
Expand Up @@ -37,15 +37,8 @@ RUN if [ ${IMG_USER} != "root" ]; then groupadd --gid=${GID} ${IMG_USER};fi
RUN if [ ${IMG_USER} != "root" ]; then adduser ${IMG_USER} --uid=${UID} --gid=${GID};fi
RUN sh -c "echo '${IMG_USER} ALL=NOPASSWD: ALL' >> /etc/sudoers"

# kernel deps
RUN apt install -y flex
RUN apt install -y bison
RUN apt install -y libelf-dev
RUN apt install -y bc
RUN apt install -y iptables
RUN apt install -y build-essential
RUN apt install -y git

RUN apt install -y make

# kata deps
RUN apt install -y golang
Expand Down
10 changes: 3 additions & 7 deletions tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh
Expand Up @@ -21,7 +21,7 @@ readonly versions_yaml="${repo_root_dir}/versions.yaml"

readonly clh_builder="${repo_root_dir}/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh"
readonly firecracker_builder="${repo_root_dir}/tools/packaging/static-build/firecracker/build-static-firecracker.sh"
readonly kernel_builder="${repo_root_dir}/tools/packaging/kernel/build-kernel.sh"
readonly kernel_builder="${repo_root_dir}/tools/packaging/static-build/kernel/build.sh"
readonly qemu_builder="${repo_root_dir}/tools/packaging/static-build/qemu/build-static-qemu.sh"
readonly rootfs_builder="${repo_root_dir}/tools/packaging/guest-image/build_image.sh"

Expand Down Expand Up @@ -87,12 +87,8 @@ install_initrd() {

#Install kernel asset
install_kernel() {
info "build kernel"
export kernel_version=="$(yq r $versions_yaml assets.version)"
"${kernel_builder}" setup
"${kernel_builder}" build
info "install kernel"
DESTDIR="${destdir}" PREFIX="${prefix}" "${kernel_builder}" install
export kernel_version="$(yq r $versions_yaml assets.kernel.version)"
DESTDIR="${destdir}" PREFIX="${prefix}" "${kernel_builder}" "${kernel_version}"
}

#Install experimental kernel asset
Expand Down
3 changes: 2 additions & 1 deletion tools/packaging/kernel/build-kernel.sh
Expand Up @@ -28,7 +28,6 @@ download_kernel=false
# The repository where kernel configuration lives
readonly kernel_config_repo="github.com/${project_name}/kata-containers/tools/packaging"
readonly patches_repo="github.com/${project_name}/kata-containers/tools/packaging"
readonly patches_repo_dir="${GOPATH}/src/${patches_repo}"
# Default path to search patches to apply to kernel
readonly default_patches_dir="${script_dir}/patches"
# Default path to search config for kata
Expand Down Expand Up @@ -497,6 +496,8 @@ main() {
kernel_version=$(get_from_kata_deps "assets.kernel.version")
fi
fi
#Remove extra 'v'
kernel_version="${kernel_version#v}"

if [ -z "${kernel_path}" ]; then
config_version=$(get_config_version)
Expand Down
18 changes: 18 additions & 0 deletions tools/packaging/static-build/kernel/Dockerfile
@@ -0,0 +1,18 @@
# Copyright (c) 2021 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

FROM ubuntu
ENV DEBIAN_FRONTEND=noninteractive

# kernel deps
RUN apt update
RUN apt install -y \
bc \
bison \
build-essential \
curl \
flex \
git \
iptables \
libelf-dev \
38 changes: 38 additions & 0 deletions tools/packaging/static-build/kernel/build.sh
@@ -0,0 +1,38 @@
#!/bin/bash
#
# Copyright (c) 2021 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

set -o errexit
set -o nounset
set -o pipefail

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly repo_root_dir="$(cd "${script_dir}/../../../.." && pwd)"
readonly kernel_builder="${repo_root_dir}/tools/packaging/kernel/build-kernel.sh"


kernel_version=${1}
DESTDIR=${DESTDIR:-${PWD}}
PREFIX=${PREFIX:-/opt/kata}
container_image="kata-kernel-builder"

sudo docker build -t "${container_image}" "${script_dir}"

echo "build ${kernel_version}"
sudo docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
-w "${PWD}" \
"${container_image}" \
bash -c "${kernel_builder} -v ${kernel_version} setup"

sudo docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
-w "${PWD}" \
"${container_image}" \
bash -c "${kernel_builder} -v ${kernel_version} build"

sudo docker run --rm -i -v "${repo_root_dir}:${repo_root_dir}" \
-w "${PWD}" \
--env DESTDIR="${DESTDIR}" --env PREFIX="${PREFIX}" \
"${container_image}" \
bash -c "${kernel_builder} -v ${kernel_version} install"

0 comments on commit d46ae32

Please sign in to comment.