rootfs: add alpine rootfs support

Fixes: #52
Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
Peng Tao 2018-02-01 01:18:23 +08:00
parent de6e4dc93f
commit c8403836c0
4 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,3 @@
From golang:@GO_VERSION@-alpine3.7
RUN apk update && apk add git make bash gcc musl-dev linux-headers apk-tools-static

View File

@ -0,0 +1,23 @@
# This is a configuration file add extra variables to
# be used by build_rootfs() from rootfs_lib.sh the variables will be
# loaded just before call the function.
# Here there are a couple of variables you may need.
# Remove them or add more
# alpine version
OS_VERSION=${OS_VERSION:-v3.7}
# Essential base packages
BASE_PACKAGES="alpine-base"
# Alpine mirror to use
# See a list of mirrors at http://nl.alpinelinux.org/alpine/MIRRORS.txt
MIRROR=http://dl-5.alpinelinux.org/alpine
# Default Architecture
ARCH=${ARCH:-x86_64}
# Mandatory Packages that must be installed
# - iptables: Need by Kata agent
PACKAGES="iptables"

View File

@ -0,0 +1,52 @@
#!/bin/bash
#
# Copyright (c) 2018 HyperHQ Inc.
#
# SPDX-License-Identifier: Apache-2.0
check_root()
{
if [ "$(id -u)" != "0" ]; then
echo "Root is needed"
exit 1
fi
}
# - Arguments
# rootfs_dir=$1
#
# - Optional environment variables
#
# EXTRA_PKGS: Variable to add extra PKGS provided by the user
#
# BIN_AGENT: Name of the Kata-Agent binary
#
# Any other configuration variable for a specific distro must be added
# and documented on its own config.sh
#
# - Expected result
#
# rootfs_dir populated with rootfs pkgs
# It must provide a binary in /sbin/init
build_rootfs() {
# Mandatory
local ROOTFS_DIR=$1
# In case of support EXTRA packages, use it to allow
# users add more packages to the base rootfs
local EXTRA_PKGS=${EXTRA_PKGS:-}
# Populate ROOTFS_DIR
check_root
mkdir -p "${ROOTFS_DIR}"
/sbin/apk.static \
-X ${MIRROR}/${OS_VERSION}/main \
-U \
--allow-untrusted \
--root ${ROOTFS_DIR}\
--initdb add ${BASE_PACKAGES} ${EXTRA_PKGS} ${PACKAGES}
mkdir -p ${ROOTFS_DIR}{/root,/etc/apk,/proc}
echo "${MIRROR}/${OS_VERSION}/main" > ${ROOTFS_DIR}/etc/apk/repositories
}

View File

@ -104,6 +104,7 @@ ENV PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin
pushd ${dir} pushd ${dir}
[ -f "${dockerfile_template}" ] || die "${dockerfile_template}: file not found" [ -f "${dockerfile_template}" ] || die "${dockerfile_template}: file not found"
sed \ sed \
-e "s|@GO_VERSION@|${GO_VERSION}|g" \
-e "s|@OS_VERSION@|${OS_VERSION}|g" \ -e "s|@OS_VERSION@|${OS_VERSION}|g" \
-e "s|@INSTALL_GO@|${install_go//$'\n'/\\n}|g" \ -e "s|@INSTALL_GO@|${install_go//$'\n'/\\n}|g" \
${dockerfile_template} > Dockerfile ${dockerfile_template} > Dockerfile
@ -209,6 +210,7 @@ OK "Pull Agent source code"
info "Build agent" info "Build agent"
pushd "${GOPATH}/src/${GO_AGENT_PKG}" pushd "${GOPATH}/src/${GO_AGENT_PKG}"
make clean
make INIT=${AGENT_INIT} make INIT=${AGENT_INIT}
make install DESTDIR="${ROOTFS_DIR}" INIT=${AGENT_INIT} make install DESTDIR="${ROOTFS_DIR}" INIT=${AGENT_INIT}
popd popd