diff --git a/rootfs-builder/alpine/Dockerfile.in b/rootfs-builder/alpine/Dockerfile.in new file mode 100644 index 000000000..538f84b61 --- /dev/null +++ b/rootfs-builder/alpine/Dockerfile.in @@ -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 diff --git a/rootfs-builder/alpine/config.sh b/rootfs-builder/alpine/config.sh new file mode 100644 index 000000000..9fe4a2b8c --- /dev/null +++ b/rootfs-builder/alpine/config.sh @@ -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" diff --git a/rootfs-builder/alpine/rootfs_lib.sh b/rootfs-builder/alpine/rootfs_lib.sh new file mode 100644 index 000000000..4143bce2e --- /dev/null +++ b/rootfs-builder/alpine/rootfs_lib.sh @@ -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 +} diff --git a/rootfs-builder/rootfs.sh b/rootfs-builder/rootfs.sh index 248635c55..9d68283ec 100755 --- a/rootfs-builder/rootfs.sh +++ b/rootfs-builder/rootfs.sh @@ -104,6 +104,7 @@ ENV PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin pushd ${dir} [ -f "${dockerfile_template}" ] || die "${dockerfile_template}: file not found" sed \ + -e "s|@GO_VERSION@|${GO_VERSION}|g" \ -e "s|@OS_VERSION@|${OS_VERSION}|g" \ -e "s|@INSTALL_GO@|${install_go//$'\n'/\\n}|g" \ ${dockerfile_template} > Dockerfile @@ -209,6 +210,7 @@ OK "Pull Agent source code" info "Build agent" pushd "${GOPATH}/src/${GO_AGENT_PKG}" +make clean make INIT=${AGENT_INIT} make install DESTDIR="${ROOTFS_DIR}" INIT=${AGENT_INIT} popd