diff --git a/rootfs-builder/rootfs.sh b/rootfs-builder/rootfs.sh index 7b41594b..85172a52 100755 --- a/rootfs-builder/rootfs.sh +++ b/rootfs-builder/rootfs.sh @@ -116,6 +116,7 @@ ENV PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin sed \ -e "s|@GO_VERSION@|${GO_VERSION}|g" \ -e "s|@OS_VERSION@|${OS_VERSION}|g" \ + -e "s|@OS_NAME@|${OS_NAME}|g" \ -e "s|@INSTALL_GO@|${install_go//$'\n'/\\n}|g" \ ${dockerfile_template} > Dockerfile popd @@ -193,16 +194,17 @@ if [ -n "${USE_DOCKER}" ] ; then --env https_proxy="${https_proxy}" \ --env http_proxy="${http_proxy}" \ --env AGENT_VERSION="${AGENT_VERSION}" \ - --env ROOTFS_DIR="/rootfs" \ + --env ROOTFS_DIR="${ROOTFS_DIR}" \ --env GO_AGENT_PKG="${GO_AGENT_PKG}" \ --env AGENT_BIN="${AGENT_BIN}" \ --env AGENT_INIT="${AGENT_INIT}" \ --env GOPATH="${GOPATH}" \ --env KERNEL_MODULES_DIR="${KERNEL_MODULES_DIR}" \ -v "${script_dir}":"/osbuilder" \ - -v "${ROOTFS_DIR}":"/rootfs" \ + -v "${ROOTFS_DIR}":"${ROOTFS_DIR}" \ -v "${kernel_mod_dir}":"${kernel_mod_dir}" \ -v "${GOPATH}":"${GOPATH}" \ + --privileged \ ${image_name} \ bash /osbuilder/rootfs.sh "${distro}" diff --git a/rootfs-builder/ubuntu/Dockerfile.in b/rootfs-builder/ubuntu/Dockerfile.in new file mode 100644 index 00000000..c7c306a3 --- /dev/null +++ b/rootfs-builder/ubuntu/Dockerfile.in @@ -0,0 +1,6 @@ +From ubuntu:@OS_NAME@ + +RUN apt-get update && apt-get install -y git systemd debootstrap build-essential + +# This will install the proper golang to build Kata components +@INSTALL_GO@ \ No newline at end of file diff --git a/rootfs-builder/ubuntu/config.sh b/rootfs-builder/ubuntu/config.sh new file mode 100644 index 00000000..bfacb026 --- /dev/null +++ b/rootfs-builder/ubuntu/config.sh @@ -0,0 +1,19 @@ +# +# Copyright (c) 2018 Yash Jain +# +# SPDX-License-Identifier: Apache-2.0 + + +# architecture to build the rootfs for +ARCH=${ARCH:-"amd64"} + +# url to download rootfs from +ARCHIVE_URL=${ARCHIVE_URL:-"http://archive.ubuntu.com/ubuntu/"} + +# this should be ubuntu's codename eg Xenial for 16.04 +OS_NAME=${OS_NAME:-"xenial"} + +# packages to be installed by default +PACKAGES="systemd iptables" + +DEBOOTSTRAP=${PACKAGE_MANAGER:-"debootstrap"} \ No newline at end of file diff --git a/rootfs-builder/ubuntu/rootfs_lib.sh b/rootfs-builder/ubuntu/rootfs_lib.sh new file mode 100755 index 00000000..7e1d777e --- /dev/null +++ b/rootfs-builder/ubuntu/rootfs_lib.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# +# Copyright (c) 2018 Yash Jain +# +# SPDX-License-Identifier: Apache-2.0 + +set -e + +check_program(){ + type "$1" >/dev/null 2>&1 +} + + + +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:-""} + + + check_root + mkdir -p "${ROOTFS_DIR}" + + if [ -n "${PKG_MANAGER}" ]; then + info "debootstrap path provided by user: ${PKG_MANAGER}" + elif check_program $DEBOOTSTRAP ; then + PKG_MANAGER=$DEBOOTSTRAP + else + die "$DEBOOTSTRAP is not installed" + fi + + # trim whitespace + PACKAGES=$(echo $PACKAGES |xargs ) + EXTRA_PKGS=$(echo $EXTRA_PKGS |xargs) + + # add comma as debootstrap needs , separated package names. + # Don't change $PACKAGES in config.sh to include ',' + # This is done to maintain consistency + PACKAGES=$(echo $PACKAGES | sed -e 's/ /,/g' ) + EXTRA_PKGS=$(echo $EXTRA_PKGS | sed -e 's/ /,/g' ) + + # extra packages are added to packages and finally passed to debootstrap + if [ "${EXTRA_PKGS}" = "" ]; then + echo "no extra packages" + else + PACKAGES="${PACKAGES},${EXTRA_PKGS}" + fi + + ${PKG_MANAGER} --variant=minbase \ + --arch="${ARCH}" \ + --include="$PACKAGES" \ + "${OS_NAME}" \ + "${ROOTFS_DIR}"\ + "${ARCHIVE_URL}" +} + + +check_root() +{ + if [ "$(id -u)" != "0" ]; then + echo "Root is needed" + exit 1 + fi +}