Skip to content

Commit

Permalink
snap: reimplement image part
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Julio Montes committed Oct 31, 2019
1 parent 43a5d14 commit 27c7773
Showing 1 changed file with 55 additions and 22 deletions.
77 changes: 55 additions & 22 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ parts:
- -*

runtime:
after: [go]
after: [go, image]
plugin: nil
build-attributes: [no-patchelf]
override-build: |
Expand Down Expand Up @@ -115,8 +115,13 @@ parts:
SKIP_GO_VERSION_CHECK=1 \
QEMUCMD=qemu-system-$arch
# Set rootfs image by default
sed -i -e '/^initrd =/d' ${SNAPCRAFT_PART_INSTALL}/usr/share/defaults/${SNAPCRAFT_PROJECT_NAME}/configuration.toml
if [ -e ${SNAPCRAFT_STAGE}/kata-containers.img ]; then
# 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:
after: [go]
Expand Down Expand Up @@ -170,11 +175,16 @@ parts:
after: [go]
plugin: nil
build-packages:
- docker.io
- cpio
- git
- iptables
- software-properties-common
- uidmap
override-build: |
kata_version=$(cat ${SNAPCRAFT_STAGE}/kata_version)
yq=$(realpath ../../yq/build/yq)
pkg_name=osbuilder
cni_plugings_repo="github.com/containernetworking/plugins"
# set GOPATH
export GOPATH=$(realpath go)
Expand All @@ -184,35 +194,58 @@ parts:
# go was built in parts/go/build
export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}"
if [ -n "$http_proxy" ]; then
echo "Setting proxy $http_proxy"
sudo -E systemctl set-environment http_proxy=$http_proxy || true
sudo -E systemctl set-environment https_proxy=$https_proxy || true
fi
# Copy yq binary. It's used in the container
mkdir -p "${GOPATH}/bin/"
cp -a "${yq}" "${GOPATH}/bin/"
# install podman
sudo add-apt-repository -y ppa:projectatomic/ppa
sudo apt-get update
sudo apt-get -y install podman
echo "Unmasking docker service"
sudo -E systemctl unmask docker.service || true
sudo -E systemctl unmask docker.socket || true
# Build and install cni plugings
echo "Retrieve CNI plugins repository"
go get -d ${cni_plugings_repo} || true
cd $GOPATH/src/${cni_plugings_repo}
echo "Adding $USER into docker group"
sudo -E gpasswd -a $USER docker
echo "Build CNI plugins"
./build_linux.sh
echo "Starting docker"
sudo -E systemctl start docker || true
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
mkdir -p "${GOPATH}/bin/"
cp -a "${yq}" "${GOPATH}/bin/"
# 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}
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
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:
after: [go]
Expand Down

0 comments on commit 27c7773

Please sign in to comment.