snap: don't use make snap to build the snap

In some build systems like launchpad is not possible to run neither
custom commands or hooks, hence build a snap image with `make snap` is
not feasible, to deal with this limitation, the final snapcraft.yaml
is part of the repository and all packages versions are read from versions.yaml
in the runtime repository.

fixes #305

Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2019-01-10 12:37:31 -06:00
parent a60cd133bd
commit 7f7e258d14
3 changed files with 137 additions and 77 deletions

1
.gitignore vendored
View File

@ -14,6 +14,5 @@ snap-build/*.log
snap-build/id_rsa* snap-build/id_rsa*
snap-build/seed/user-data snap-build/seed/user-data
snap/.snapcraft/ snap/.snapcraft/
snap/snapcraft.yaml
stage/ stage/
typescript typescript

View File

@ -16,6 +16,7 @@ VERSION_FILE_URL := https://raw.githubusercontent.com/kata-containers/runtime/ma
export MK_DIR export MK_DIR
export YQ export YQ
export SNAPCRAFT_FILE
export VERSION_FILE export VERSION_FILE
export VERSIONS_YAML_FILE export VERSIONS_YAML_FILE
@ -44,26 +45,14 @@ $(VERSION_FILE):
$(VERSIONS_YAML_FILE): $(VERSIONS_YAML_FILE):
@curl -sO $(VERSIONS_YAML_FILE_URL) @curl -sO $(VERSIONS_YAML_FILE_URL)
$(SNAPCRAFT_FILE): %: %.in Makefile $(YQ) $(VERSIONS_YAML_FILE) $(VERSION_FILE) snap: $(YQ) $(VERSION_FILE)
$(SED) \ @if [ "$$(cat $(VERSION_FILE))" != "$$($(YQ) r $(SNAPCRAFT_FILE) version)" ]; then \
-e "s|@KATA_RUNTIME_VERSION@|$$(cat $${VERSION_FILE})|g" \ >&2 echo "Warning: $(SNAPCRAFT_FILE) version is different to upstream $(VERSION_FILE) file"; \
-e "s|@KATA_PROXY_VERSION@|$$(cat $${VERSION_FILE})|g" \ fi
-e "s|@KATA_SHIM_VERSION@|$$(cat $${VERSION_FILE})|g" \
-e "s|@KSM_THROTTLER_VERSION@|$$(cat $${VERSION_FILE})|g" \
-e "s|@QEMU_LITE_BRANCH@|$$($${YQ} r $${VERSIONS_YAML_FILE} assets.hypervisor.qemu-lite.branch)|g" \
-e "s|@KERNEL_URL@|$$($${YQ} r $${VERSIONS_YAML_FILE} assets.kernel.url)|g" \
-e "s|@KERNEL_VERSION@|$$($${YQ} r $${VERSIONS_YAML_FILE} assets.kernel.version | tr -d v)|g" \
-e "s|@GO_VERSION@|$$($${YQ} r $${VERSIONS_YAML_FILE} languages.golang.meta.newest-version)|g" \
$< > $@
snap: $(SNAPCRAFT_FILE)
snapcraft -d snapcraft -d
snap-xbuild: snap-xbuild:
cd $(MK_DIR)/snap-build; ./xbuild.sh -a all cd $(MK_DIR)/snap-build; ./xbuild.sh -a all
clean: .PHONY: test test-release-tools test-static-build test-packaging-tools snap snap-xbuild \
rm -f $(SNAPCRAFT_FILE)
.PHONY: test test-release-tools test-static-build test-packaging-tools snap clean \
$(VERSION_FILE) $(VERSIONS_YAML_FILE) $(VERSION_FILE) $(VERSIONS_YAML_FILE)

View File

@ -1,5 +1,5 @@
name: kata-containers name: kata-containers
version: @KATA_RUNTIME_VERSION@ version: "1.5.0-rc2"
summary: Build lightweight VMs that seamlessly plug into the containers ecosystem summary: Build lightweight VMs that seamlessly plug into the containers ecosystem
description: | description: |
Kata Containers is an open source project and community working to build a Kata Containers is an open source project and community working to build a
@ -11,20 +11,43 @@ confinement: classic
parts: parts:
go: go:
source-tag: go@GO_VERSION@ override-build: |
versions_url=https://raw.githubusercontent.com/kata-containers/runtime/${SNAPCRAFT_PROJECT_VERSION}/versions.yaml
version="$(curl -sSL ${versions_url} | yq r - languages.golang.version)"
curl -LO https://dl.google.com/go/go${version}.src.tar.gz
tar -xf go${version}.src.tar.gz --strip-components=1
cd src && env GOROOT_BOOTSTRAP=$(go env GOROOT | tr -d '\n') ./make.bash
build-packages:
- golang-go
- g++
- curl
build-snaps:
- yq
plugin: nil
prime:
- -*
runtime: runtime:
source: http://github.com/kata-containers/runtime
source-type: git
source-tag: @KATA_RUNTIME_VERSION@
after: [go] after: [go]
plugin: go plugin: nil
go-importpath: github.com/kata-containers/runtime
build-attributes: [no-patchelf] build-attributes: [no-patchelf]
override-build: | override-build: |
# Don't use installed GOROOT pkg_name=runtime
unset GOROOT
export GOPATH=$(realpath ../go) # set GOPATH
cd ${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/runtime export GOPATH=$(realpath go)
# go was built in parts/go/build
export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}"
pkg_gopath=${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/${pkg_name}
mkdir -p ${pkg_gopath}
# download source
curl -LO https://github.com/kata-containers/${pkg_name}/archive/${SNAPCRAFT_PROJECT_VERSION}.tar.gz
tar -xf ${SNAPCRAFT_PROJECT_VERSION}.tar.gz --strip-components=1 -C ${pkg_gopath}
cd ${pkg_gopath}
# build and install
make \ make \
PREFIX=/snap/${SNAPCRAFT_PROJECT_NAME}/current/usr \ PREFIX=/snap/${SNAPCRAFT_PROJECT_NAME}/current/usr \
SKIP_GO_VERSION_CHECK=1 SKIP_GO_VERSION_CHECK=1
@ -32,39 +55,56 @@ parts:
PREFIX=/usr \ PREFIX=/usr \
DESTDIR=${SNAPCRAFT_PART_INSTALL} \ DESTDIR=${SNAPCRAFT_PART_INSTALL} \
SKIP_GO_VERSION_CHECK=1 SKIP_GO_VERSION_CHECK=1
# A snap is read-only squashfs, unfourtunately it's not possible to use the rootfs image with DAX
# since rw access is required therefore initrd image must be used instead.
sed -i -e '/^image =/d' ${SNAPCRAFT_PART_INSTALL}/usr/share/defaults/${SNAPCRAFT_PROJECT_NAME}/configuration.toml sed -i -e '/^image =/d' ${SNAPCRAFT_PART_INSTALL}/usr/share/defaults/${SNAPCRAFT_PROJECT_NAME}/configuration.toml
proxy: proxy:
source: http://github.com/kata-containers/proxy
source-type: git
source-tag: @KATA_PROXY_VERSION@
after: [go] after: [go]
plugin: go plugin: nil
go-importpath: github.com/kata-containers/proxy
build-attributes: [no-patchelf] build-attributes: [no-patchelf]
override-build: | override-build: |
# Don't use installed GOROOT pkg_name=proxy
unset GOROOT
export GOPATH=$(realpath ../go) # set GOPATH
cd ${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/proxy export GOPATH=$(realpath go)
# go was built in parts/go/build
export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}"
pkg_gopath=${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/${pkg_name}
mkdir -p ${pkg_gopath}
# download source
curl -LO https://github.com/kata-containers/${pkg_name}/archive/${SNAPCRAFT_PROJECT_VERSION}.tar.gz
tar -xf ${SNAPCRAFT_PROJECT_VERSION}.tar.gz --strip-components=1 -C ${pkg_gopath}
cd ${pkg_gopath}
# build and install
make make
make install DESTDIR=${SNAPCRAFT_PART_INSTALL} make install DESTDIR=${SNAPCRAFT_PART_INSTALL}
shim: shim:
source: http://github.com/kata-containers/shim
source-type: git
source-tag: @KATA_SHIM_VERSION@
after: [go] after: [go]
plugin: go plugin: nil
go-importpath: github.com/kata-containers/shim
build-attributes: [no-patchelf] build-attributes: [no-patchelf]
build-packages:
- libelf-dev
override-build: | override-build: |
# Don't use installed GOROOT pkg_name=shim
unset GOROOT
export GOPATH=$(realpath ../go) # set GOPATH
cd ${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/shim export GOPATH=$(realpath go)
# go was built in parts/go/build
export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}"
pkg_gopath=${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/${pkg_name}
mkdir -p ${pkg_gopath}
# download source
curl -LO https://github.com/kata-containers/${pkg_name}/archive/${SNAPCRAFT_PROJECT_VERSION}.tar.gz
tar -xf ${SNAPCRAFT_PROJECT_VERSION}.tar.gz --strip-components=1 -C ${pkg_gopath}
cd ${pkg_gopath}
# build and install
make make
make install LIBEXECDIR=${SNAPCRAFT_PART_INSTALL}/usr/libexec make install LIBEXECDIR=${SNAPCRAFT_PART_INSTALL}/usr/libexec
@ -77,8 +117,11 @@ parts:
- docker.io - docker.io
- cpio - cpio
override-build: | override-build: |
# Don't use installed GOROOT set -x
unset GOROOT # go was built in parts/go/build
export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}"
env
if [ -n "$http_proxy" ]; then if [ -n "$http_proxy" ]; then
echo "Setting proxy $http_proxy" echo "Setting proxy $http_proxy"
systemctl set-environment http_proxy=$http_proxy || true systemctl set-environment http_proxy=$http_proxy || true
@ -88,9 +131,7 @@ parts:
echo "Starting docker" echo "Starting docker"
systemctl start docker || true systemctl start docker || true
export GOPATH=$(realpath ../go) # use the same go version for all packages
mkdir -p $GOPATH
sed -i 's|^GO_VERSION=.*|GO_VERSION='$(go version | cut -d' ' -f3 | tr -d go)'|g' rootfs-builder/versions.txt sed -i 's|^GO_VERSION=.*|GO_VERSION='$(go version | cut -d' ' -f3 | tr -d go)'|g' rootfs-builder/versions.txt
sudo -E PATH=$PATH make DISTRO=alpine AGENT_INIT=yes USE_DOCKER=1 initrd sudo -E PATH=$PATH make DISTRO=alpine AGENT_INIT=yes USE_DOCKER=1 initrd
@ -100,40 +141,60 @@ parts:
cp kata-containers-initrd.img ${kata_image_dir} cp kata-containers-initrd.img ${kata_image_dir}
ksm-throttler: ksm-throttler:
source: http://github.com/kata-containers/ksm-throttler
source-type: git
source-tag: @KSM_THROTTLER_VERSION@
after: [go] after: [go]
plugin: go plugin: nil
go-importpath: github.com/kata-containers/ksm-throttler
build-attributes: [no-patchelf] build-attributes: [no-patchelf]
override-build: | override-build: |
# Don't use installed GOROOT pkg_name=ksm-throttler
unset GOROOT
export GOPATH=$(realpath ../go) # set GOPATH
cd ${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/ksm-throttler export GOPATH=$(realpath go)
# go was built in parts/go/build
export GOROOT=$(realpath ../../go/build)
export PATH="${GOROOT}/bin:${PATH}"
pkg_gopath=${GOPATH}/src/github.com/${SNAPCRAFT_PROJECT_NAME}/${pkg_name}
mkdir -p ${pkg_gopath}
# download source
curl -LO https://github.com/kata-containers/${pkg_name}/archive/${SNAPCRAFT_PROJECT_VERSION}.tar.gz
tar -xf ${SNAPCRAFT_PROJECT_VERSION}.tar.gz --strip-components=1 -C ${pkg_gopath}
cd ${pkg_gopath}
# build and install
make TARGET=kata-ksm-throttler make TARGET=kata-ksm-throttler
make install \ make install \
DESTDIR=${SNAPCRAFT_PART_INSTALL} \ DESTDIR=${SNAPCRAFT_PART_INSTALL} \
TARGET=kata-ksm-throttler TARGET=kata-ksm-throttler
kernel: kernel:
source: @KERNEL_URL@/linux-@KERNEL_VERSION@.tar.xz override-pull: |
source-type: tar versions_url=https://raw.githubusercontent.com/kata-containers/runtime/${SNAPCRAFT_PROJECT_VERSION}/versions.yaml
version="$(curl -sSL ${versions_url} | yq r - assets.kernel.version | tr -d v)"
url="$(curl -sSL ${versions_url} | yq r - assets.kernel.url)"
curl -LO ${url}/linux-${version}.tar.xz
tar -xf linux-${version}.tar.xz --strip-components=1
after: [kernel-dump] after: [kernel-dump]
plugin: kernel plugin: kernel
build-packages:
- libelf-dev
- curl
build-snaps:
- yq
override-build: | override-build: |
versions_url=https://raw.githubusercontent.com/kata-containers/runtime/${SNAPCRAFT_PROJECT_VERSION}/versions.yaml
version="$(curl -sSL ${versions_url} | yq r - assets.kernel.version | tr -d v)"
x_version="$(echo $version | sed -e 's|.[[:digit:]]*$||').x"
case "$(arch)" in case "$(arch)" in
"x86_64") "x86_64")
config=x86_64_kata_kvm_4.14.x config="x86_64_kata_kvm_${x_version}"
;; ;;
"ppc64le") "ppc64le")
config=powerpc_kata_kvm_4.14.x config="powerpc_kata_kvm_${x_version}"
;; ;;
"aarch64") "aarch64")
config=arm64_kata_kvm_4.14.x config="arm64_kata_kvm_${x_version}"
;; ;;
*) *)
@ -152,15 +213,14 @@ parts:
--forward \ --forward \
--strip 1 \ --strip 1 \
--input "$patch" --input "$patch"
echo
done done
# Copy config file # Copy config file
cp ${SNAPCRAFT_STAGE}/kernel/configs/${config} .config cp ${SNAPCRAFT_STAGE}/kernel/configs/${config} .config
make -s oldconfig EXTRAVERSION=".container" > /dev/null make -s oldconfig EXTRAVERSION=".container" > /dev/null
make -j $(nproc) EXTRAVERSION=".container" make -j $(($(nproc)-1)) EXTRAVERSION=".container"
kernel_suffix=@KERNEL_VERSION@.container kernel_suffix=${version}.container
kata_kernel_dir=${SNAPCRAFT_PART_INSTALL}/usr/share/kata-containers kata_kernel_dir=${SNAPCRAFT_PART_INSTALL}/usr/share/kata-containers
mkdir -p ${kata_kernel_dir} mkdir -p ${kata_kernel_dir}
@ -183,8 +243,12 @@ parts:
- -* - -*
qemu: qemu:
source: https://github.com/kata-containers/qemu/archive/@QEMU_LITE_BRANCH@.tar.gz override-pull: |
source-type: tar versions_url=https://raw.githubusercontent.com/kata-containers/runtime/${SNAPCRAFT_PROJECT_VERSION}/versions.yaml
branch="$(curl -sSL ${versions_url} | yq r - assets.hypervisor.qemu-lite.branch)"
url="$(curl -sSL ${versions_url} | yq r - assets.hypervisor.qemu-lite.url)"
curl -LO ${url}/archive/${branch}.tar.gz
tar -xf ${branch}.tar.gz --strip-components=1
plugin: make plugin: make
after: [qemu-scripts-dump, qemu-patches-dump] after: [qemu-scripts-dump, qemu-patches-dump]
build-packages: build-packages:
@ -199,6 +263,9 @@ parts:
- libcap-dev - libcap-dev
- libattr1-dev - libattr1-dev
- libfdt-dev - libfdt-dev
- curl
build-snaps:
- yq
override-build: | override-build: |
chmod +x ${SNAPCRAFT_STAGE}/qemu/scripts/configure-hypervisor.sh chmod +x ${SNAPCRAFT_STAGE}/qemu/scripts/configure-hypervisor.sh
# static build # static build
@ -223,13 +290,18 @@ parts:
--forward \ --forward \
--strip 1 \ --strip 1 \
--input "$patch" --input "$patch"
echo
done done
make -j $(nproc)
# build and install
make -j $(($(nproc)-1))
make install DESTDIR=${SNAPCRAFT_PART_INSTALL} make install DESTDIR=${SNAPCRAFT_PART_INSTALL}
prime: prime:
- -snap/* - -snap/
- -usr/var/* - -usr/var/
- -usr/libexec/
- -usr/bin/qemu-ga
- -usr/bin/qemu-pr-helper
- -usr/bin/virtfs-proxy-helper
- usr/* - usr/*
- lib/* - lib/*
organize: organize: