snap: reimplement image part

in order to make launchpad happy again, next changes are required:
* Install podman and cni plugings
* Use podman to build the rootfs or initrd image
* Depending on the architecture, build rootfs or initrd image

fixes #678

Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2019-10-30 21:23:54 +00:00
parent 43a5d147f1
commit 27c7773693

View File

@ -80,7 +80,7 @@ parts:
- -* - -*
runtime: runtime:
after: [go] after: [go, image]
plugin: nil plugin: nil
build-attributes: [no-patchelf] build-attributes: [no-patchelf]
override-build: | override-build: |
@ -115,8 +115,13 @@ parts:
SKIP_GO_VERSION_CHECK=1 \ SKIP_GO_VERSION_CHECK=1 \
QEMUCMD=qemu-system-$arch QEMUCMD=qemu-system-$arch
# Set rootfs image by default if [ -e ${SNAPCRAFT_STAGE}/kata-containers.img ]; then
sed -i -e '/^initrd =/d' ${SNAPCRAFT_PART_INSTALL}/usr/share/defaults/${SNAPCRAFT_PROJECT_NAME}/configuration.toml # Use rootfs image by default
sed -i -e '/^initrd =/d' ${SNAPCRAFT_PART_INSTALL}/usr/share/defaults/${SNAPCRAFT_PROJECT_NAME}/configuration.toml
else
# Use initrd by default
sed -i -e '/^image =/d' ${SNAPCRAFT_PART_INSTALL}/usr/share/defaults/${SNAPCRAFT_PROJECT_NAME}/configuration.toml
fi
proxy: proxy:
after: [go] after: [go]
@ -170,11 +175,16 @@ parts:
after: [go] after: [go]
plugin: nil plugin: nil
build-packages: build-packages:
- docker.io
- cpio - cpio
- git
- iptables
- software-properties-common
- uidmap
override-build: | override-build: |
kata_version=$(cat ${SNAPCRAFT_STAGE}/kata_version)
yq=$(realpath ../../yq/build/yq) yq=$(realpath ../../yq/build/yq)
pkg_name=osbuilder pkg_name=osbuilder
cni_plugings_repo="github.com/containernetworking/plugins"
# set GOPATH # set GOPATH
export GOPATH=$(realpath go) export GOPATH=$(realpath go)
@ -184,35 +194,58 @@ parts:
# go was built in parts/go/build # go was built in parts/go/build
export GOROOT=$(realpath ../../go/build) export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}" export PATH="${GOROOT}/bin:${PATH}"
if [ -n "$http_proxy" ]; then
echo "Setting proxy $http_proxy" # install podman
sudo -E systemctl set-environment http_proxy=$http_proxy || true sudo add-apt-repository -y ppa:projectatomic/ppa
sudo -E systemctl set-environment https_proxy=$https_proxy || true sudo apt-get update
fi sudo apt-get -y install podman
# Build and install cni plugings
echo "Retrieve CNI plugins repository"
go get -d ${cni_plugings_repo} || true
cd $GOPATH/src/${cni_plugings_repo}
echo "Build CNI plugins"
./build_linux.sh
echo "Install CNI binaries"
cni_bin_path="/opt/cni"
sudo mkdir -p ${cni_bin_path}
sudo cp -a bin ${cni_bin_path}
# Copy yq binary. It's used in the container # Copy yq binary. It's used in the container
mkdir -p "${GOPATH}/bin/" mkdir -p "${GOPATH}/bin/"
cp -a "${yq}" "${GOPATH}/bin/" cp -a "${yq}" "${GOPATH}/bin/"
echo "Unmasking docker service"
sudo -E systemctl unmask docker.service || true
sudo -E systemctl unmask docker.socket || true
echo "Adding $USER into docker group"
sudo -E gpasswd -a $USER docker
echo "Starting docker"
sudo -E systemctl start docker || true
# download source # download source
git clone -b ${SNAPCRAFT_PROJECT_VERSION} https://github.com/kata-containers/${pkg_name} ${pkg_gopath} git clone -b ${kata_version} https://github.com/kata-containers/${pkg_name} ${pkg_gopath}
cd ${pkg_gopath} cd ${pkg_gopath}
sudo -E PATH=$PATH make AGENT_VERSION=${SNAPCRAFT_PROJECT_VERSION} DISTRO=clearlinux AGENT_INIT=yes USE_DOCKER=1 image # build image
export AGENT_VERSION=${kata_version}
export AGENT_INIT=yes
export USE_PODMAN=1
export DEBUG=1
case "$(uname -m)" in
aarch64|ppc64le|s390x)
sudo -E PATH=$PATH DISTRO=alpine make initrd
;;
x86_64)
# In some build systems it's impossible to build a rootfs image, try with the initrd image
sudo -E PATH=$PATH DISTRO=clearlinux make image || sudo -E PATH=$PATH DISTRO=alpine make initrd
;;
*) echo "unsupported architecture: $(uname -m)"; exit 1;;
esac
# Install image
kata_image_dir=${SNAPCRAFT_PART_INSTALL}/usr/share/kata-containers kata_image_dir=${SNAPCRAFT_PART_INSTALL}/usr/share/kata-containers
mkdir -p ${kata_image_dir} mkdir -p ${kata_image_dir}
cp kata-containers.img ${kata_image_dir} cp kata-containers*.img ${kata_image_dir}
if [ -e kata-containers.img ]; then
touch ${SNAPCRAFT_STAGE}/kata-containers.img
else
touch ${SNAPCRAFT_STAGE}/kata-containers-initrd.img
fi
ksm-throttler: ksm-throttler:
after: [go] after: [go]