snap: use adopt-info to set grade and version

adopt-info is a snapcraft feature that allows us to specify the snap grade and
version at runtime. Depending on the environment the master or the latest
stable branch can be used to build the Kata Containers snap, for the kata
CI and launchpad snap-master branch, the master branch are used, otherwise
the latest stable branch.

Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2019-10-30 21:15:08 +00:00
parent 6f95e3e1f3
commit 43a5d147f1

View File

@ -1,16 +1,39 @@
name: kata-containers name: kata-containers
version: "master"
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
standard implementation of lightweight Virtual Machines (VMs) that feel and standard implementation of lightweight Virtual Machines (VMs) that feel and
perform like containers, but provide the workload isolation and security perform like containers, but provide the workload isolation and security
advantages of VMs advantages of VMs
grade: stable
confinement: classic confinement: classic
adopt-info: metadata
parts: parts:
metadata:
plugin: nil
prime:
- -*
build-packages:
- git
- git-extras
override-pull: |
branch="master"
# kata CI or launchpad snap-master
if [ "${CI}" = "true" ] || echo "${SNAPCRAFT_IMAGE_INFO}" | egrep -o "build_url.*" | grep -q "${branch}"; then
snapcraftctl set-grade "devel"
else
# Get the latest stable version
runtime_url="https://github.com/kata-containers/runtime"
branch=$(git ls-remote --tags ${runtime_url} | egrep -o "refs.*" | egrep -v "\-alpha|\-rc|{}" | cut -d/ -f3 | sort -r | head -1)
snapcraftctl set-grade "stable"
fi
snapcraftctl set-version "${branch}"
echo "${branch}" | tee ${SNAPCRAFT_STAGE}/kata_version
yq: yq:
after: [metadata]
plugin: nil plugin: nil
prime: prime:
- -* - -*
@ -41,8 +64,9 @@ parts:
go: go:
after: [yq] after: [yq]
override-build: | override-build: |
kata_version=$(cat ${SNAPCRAFT_STAGE}/kata_version)
yq=$(realpath ../../yq/build/yq) yq=$(realpath ../../yq/build/yq)
versions_url=https://raw.githubusercontent.com/kata-containers/runtime/${SNAPCRAFT_PROJECT_VERSION}/versions.yaml versions_url=https://raw.githubusercontent.com/kata-containers/runtime/${kata_version}/versions.yaml
version="$(curl -sSL ${versions_url} | ${yq} r - languages.golang.version)" version="$(curl -sSL ${versions_url} | ${yq} r - languages.golang.version)"
curl -LO https://dl.google.com/go/go${version}.src.tar.gz curl -LO https://dl.google.com/go/go${version}.src.tar.gz
tar -xf go${version}.src.tar.gz --strip-components=1 tar -xf go${version}.src.tar.gz --strip-components=1
@ -60,6 +84,7 @@ parts:
plugin: nil plugin: nil
build-attributes: [no-patchelf] build-attributes: [no-patchelf]
override-build: | override-build: |
kata_version=$(cat ${SNAPCRAFT_STAGE}/kata_version)
pkg_name=runtime pkg_name=runtime
# set GOPATH # set GOPATH
@ -71,7 +96,7 @@ parts:
mkdir -p ${pkg_gopath} mkdir -p ${pkg_gopath}
# 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}
# build and install # build and install
@ -98,6 +123,7 @@ parts:
plugin: nil plugin: nil
build-attributes: [no-patchelf] build-attributes: [no-patchelf]
override-build: | override-build: |
kata_version=$(cat ${SNAPCRAFT_STAGE}/kata_version)
pkg_name=proxy pkg_name=proxy
# set GOPATH # set GOPATH
@ -109,7 +135,7 @@ parts:
mkdir -p ${pkg_gopath} mkdir -p ${pkg_gopath}
# 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}
# build and install # build and install
@ -121,6 +147,7 @@ parts:
plugin: nil plugin: nil
build-attributes: [no-patchelf] build-attributes: [no-patchelf]
override-build: | override-build: |
kata_version=$(cat ${SNAPCRAFT_STAGE}/kata_version)
pkg_name=shim pkg_name=shim
# set GOPATH # set GOPATH
@ -132,7 +159,7 @@ parts:
mkdir -p ${pkg_gopath} mkdir -p ${pkg_gopath}
# 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}
# build and install # build and install
@ -192,6 +219,7 @@ parts:
plugin: nil plugin: nil
build-attributes: [no-patchelf] build-attributes: [no-patchelf]
override-build: | override-build: |
kata_version=$(cat ${SNAPCRAFT_STAGE}/kata_version)
pkg_name=ksm-throttler pkg_name=ksm-throttler
# set GOPATH # set GOPATH
@ -203,7 +231,7 @@ parts:
mkdir -p ${pkg_gopath} mkdir -p ${pkg_gopath}
# 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}
# build and install # build and install
@ -280,11 +308,12 @@ parts:
- libcapstone-dev - libcapstone-dev
- bc - bc
override-build: | override-build: |
kata_version=$(cat ${SNAPCRAFT_STAGE}/kata_version)
yq=$(realpath ../../yq/build/yq) yq=$(realpath ../../yq/build/yq)
pkg_name="qemu" pkg_name="qemu"
configs_dir="${SNAPCRAFT_STAGE}/qemu/default-configs" configs_dir="${SNAPCRAFT_STAGE}/qemu/default-configs"
versions_url=https://raw.githubusercontent.com/kata-containers/runtime/${SNAPCRAFT_PROJECT_VERSION}/versions.yaml versions_url=https://raw.githubusercontent.com/kata-containers/runtime/${kata_version}/versions.yaml
# arch-specific definition # arch-specific definition
case "$(uname -m)" in case "$(uname -m)" in
"aarch64") "aarch64")