Skip to content

Commit

Permalink
Merge pull request #3 from eschrock/master
Browse files Browse the repository at this point in the history
Pull linuxkit kernel via docker
  • Loading branch information
Eric Schrock authored Aug 1, 2019
2 parents e5433d4 + 1ce6536 commit 47582ea
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ARG ZFS_VERSION=

RUN apt-get update

# Tools to fetch and build source
RUN apt-get install -y \
git \
curl xz-utils \
Expand All @@ -18,6 +19,27 @@ RUN apt-get install -y \
zlib1g-dev uuid-dev libattr1-dev libblkid-dev libselinux-dev libudev-dev \
libacl1-dev libaio-dev libdevmapper-dev libssl-dev libelf-dev

# Python is not strictly required for ZFS, but eliminates a number of warnings
RUN apt-get install -y \
python3 python3-distutils

# Linuxkit binaries (such as fixdep) require musl
RUN apt-get install -y musl

# Linuxkit requires the ability to copy data from docker images
RUN apt-get -y install apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"
RUN apt-get update
RUN apt-get -y install docker-ce

RUN mkdir /src
RUN mkdir /build

Expand Down
36 changes: 25 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,37 @@ function get_zfs_source() {
}

# Get linuxkit-specific source
function get_linuxkit_src() {
local version=$1
curl --retry 5 -o /src/linuxkit-$version.tar.gz -L https://github.com/linuxkit/linux/archive/v${version}.tar.gz
function get_linuxkit_kernel() {
local kernel_version=$1
local kernel_release=$2
local container_id=$(docker run -d linuxkit/kernel:$kernel_version /bin/true 2>/dev/null || /bin/true)
if [ -z $container_id ]; then
echo "failed to launch linuxkit/kernel:$kernel_version container"
exit 1
fi
cd /
docker cp $container_id:kernel-dev.tar .
docker cp $container_id:kernel.tar .
tar xf kernel-dev.tar
tar xf kernel.tar

cd /src
tar xf linuxkit-$version.tar.gz
mv linux-$version linux
rm linuxkit-$version.tar.gz
docker cp $container_id:linux.tar.xz .
tar xf linux.tar.xz

docker rm $container_id

KERNEL_SRC=/src/linux
KERNEL_OBJ=/lib/modules/$kernel_release/build
}

#
# Get ubuntu-specific modules. With Ubuntu, we can get the pre-built modules and
# headers for a given kernel release, so that we don't need to actually build from source.
#
function get_ubuntu_kernel() {
local kernel_release=$1
local kernel_version=$2
local kernel_version=$1
local kernel_release=$2

apt-get install -y linux-modules-$kernel_release linux-headers-$kernel_release linux-source-$kernel_version
cd /usr/src && tar -xjf linux-source-$kernel_version.tar.bz2
Expand Down Expand Up @@ -66,13 +81,12 @@ function get_kernel() {

case $kernel_variant in
linuxkit)
get_linuxkit_src $kernel_version
build_kernel
get_linuxkit_kernel $kernel_version $KERNEL_RELEASE
;;
*)
case $KERNEL_UNAME in
*Ubuntu*)
get_ubuntu_kernel $KERNEL_RELEASE $kernel_version
get_ubuntu_kernel $kernel_version $KERNEL_RELEASE
;;
*)
get_vanilla_src $kernel_version
Expand Down

0 comments on commit 47582ea

Please sign in to comment.