packaging: merge packaging repository

git-subtree-dir: tools/packaging
git-subtree-mainline: f818b46a41
git-subtree-split: 1f22d72d5d

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
Peng Tao
2020-06-23 22:49:04 -07:00
645 changed files with 292694 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
#
MK_DIR :=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
.PHONY: bump-kata-version
NEW_VERSION :=
TARGET_BRANCH ?= "master"
# Run update-repository-version.sh
# $1 : repository to bump
define BUMP_REPO
@echo "Create PR for $1 version $(NEW_VERSION)"
@$(MK_DIR)/update-repository-version.sh -p $(NEW_VERSION) $(TARGET_BRANCH)
endef
bump-kata-version: $(REPOS)
ifeq ($(and $(NEW_VERSION),$(TARGET_BRANCH)),)
$(error Either NEW_VERSION or TARGET_BRANCH variable is empty, provide both)
else
$(call BUMP_REPO)
endif

View File

@@ -0,0 +1,67 @@
# Release information
* [Introduction](#introduction)
* [Create a Kata Containers release](#create-a-kata-containers-release)
* [Release tools](#release-tools)
- [`update-repository-version.sh`](#update-repository-versionsh)
- [Update Kata projects to a new version](#update-kata-projects-to-a-new-version)
- [`tag_repos.sh`](#tag_repossh)
## Introduction
This directory contains information of the process and
tools used for creating Kata Containers releases.
## Create a Kata Containers release
See [the release documentation](https://github.com/kata-containers/documentation/blob/master/Release-Process.md).
## Release tools
### `update-repository-version.sh`
This script creates a GitHub pull request (a.k.a PR) to change the version in
all the Kata repositories.
For more information on using the script, run the following:
```bash
$ ./update-repository-version.sh -h
```
### Update Kata projects to a new version
Kata Containers is divided into multiple projects. With each release, all
project versions are updated to keep the version consistent.
To update all versions for all projects, use the following:
```bash
$ make bump-kata-version NEW_VERSION=<new-version>
```
The makefile target `bump-kata-version` creates a GitHub pull request in the
Kata repositories. These pull requests are tested by the Kata CI to ensure the
entire project is working prior to the release. Next, the PR is approved and
merged by Kata Containers members.
### `tag_repos.sh`
After all the Kata repositories are updated with a new version, they need to be
tagged.
The `tag_repos.sh` script is used to create tags for the Kata Containers
repositories. This script ensures that all the repositories are in the same
version (by checking the `VERSION` file).
The script creates an **annotated tag** for the new release version for the
following repositories:
- agent
- proxy
- runtime
- shim
- throttler
The script also tags the tests and osbuilder repositories to make it clear which
versions of these supporting repositories are used for the release.

View File

@@ -0,0 +1,311 @@
#!/bin/bash
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
[ -z "${DEBUG}" ] || set -x
set -o errexit
set -o nounset
set -o pipefail
readonly script_name="$(basename "${BASH_SOURCE[0]}")"
readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly project="kata-containers"
readonly prefix="/opt/kata"
readonly project_to_attach="github.com/${project}/runtime"
readonly tmp_dir=$(mktemp -d -t static-build-tmp.XXXXXXXXXX)
readonly GOPATH="${tmp_dir}/go"
# flag to decide if push tarball to github
push=false
export GOPATH
workdir="${WORKDIR:-$PWD}"
# This flag help us to test and run this script with changes
# that are local
test_local="false"
destdir="${workdir}/kata-static"
mkdir -p "${destdir}"
exit_handler() {
[ -d "${tmp_dir}" ] || sudo rm -rf "${tmp_dir}"
}
trap exit_handler EXIT
projects=(
proxy
runtime
shim
)
die() {
msg="$*"
echo "ERROR: ${msg}" >&2
exit 1
}
info() {
echo "INFO: $*"
}
usage() {
return_code=${1:-0}
cat <<EOT
This script is used as part of the ${project} release process.
It is used to create a tarball with static binaries.
Usage:
${script_name} <options> [version]
Args:
version: The kata version that will be use to create the tarball
options:
-h : Show this help
-l : Run this script to test changes locally
-p : push tarball to ${project_to_attach}
-w <dir>: directory where tarball will be created
EOT
exit "${return_code}"
}
#Verify that hub is installed and in case that is not
# install it to avoid issues when we try to push
verify_hub() {
check_command=$(whereis hub | cut -d':' -f2)
# Install hub if is not installed
if [ -z ${check_command} ]; then
hub_repo="github.com/github/hub"
hub_url="https://${hub_repo}"
go get -d ${hub_repo} || true
pushd ${GOPATH}/src/${hub_repo}
make
make install prefix=/usr/local
popd
fi
}
#Install guest image/initrd asset
install_image() {
kata_version=${1:-$kata_version}
image_destdir="${destdir}/${prefix}/share/kata-containers/"
info "Create image"
image_tarball=$(find . -name 'kata-containers-'"${kata_version}"'-*.tar.gz')
[ -f "${image_tarball}" ] || "${script_dir}/../obs-packaging/kata-containers-image/build_image.sh" -v "${kata_version}"
image_tarball=$(find . -name 'kata-containers-'"${kata_version}"'-*.tar.gz')
[ -f "${image_tarball}" ] || die "image not found"
info "Install image in destdir ${image_tarball}"
mkdir -p "${image_destdir}"
tar xf "${image_tarball}" -C "${image_destdir}"
pushd "${destdir}/${prefix}/share/kata-containers/" >>/dev/null
info "Create image default symlinks"
image=$(find . -name 'kata-containers-image*.img')
initrd=$(find . -name 'kata-containers-initrd*.initrd')
ln -sf "${image}" kata-containers.img
ln -sf "${initrd}" kata-containers-initrd.img
popd >>/dev/null
pushd ${destdir}
tar -czvf ../kata-static-image.tar.gz *
popd
}
#Install kernel asset
install_kernel() {
kata_version=${1:-$kata_version}
pushd "${script_dir}/../"
info "build kernel"
kata_version="${kata_version}" ./kernel/build-kernel.sh setup
kata_version="${kata_version}" ./kernel/build-kernel.sh build
info "install kernel"
kata_version="${kata_version}" DESTDIR="${destdir}" PREFIX="${prefix}" ./kernel/build-kernel.sh install
popd
pushd ${destdir}
tar -czvf ../kata-static-kernel.tar.gz *
popd
}
#Install experimental kernel asset
install_experimental_kernel() {
kata_version=${1:-$kata_version}
pushd "${script_dir}/../"
info "build experimental kernel"
kata_version="${kata_version}" ./kernel/build-kernel.sh -e setup
kata_version="${kata_version}" ./kernel/build-kernel.sh -e build
info "install experimental kernel"
kata_version="${kata_version}" DESTDIR="${destdir}" PREFIX="${prefix}" ./kernel/build-kernel.sh -e install
popd
pushd ${destdir}
tar -czvf ../kata-static-experimental-kernel.tar.gz *
popd
}
# Install static qemu asset
install_qemu() {
kata_version=${1:-$kata_version}
info "build static qemu"
kata_version="${kata_version}" "${script_dir}/../static-build/qemu/build-static-qemu.sh"
}
# Install static qemu-virtiofsd asset
install_qemu_virtiofsd() {
kata_version=${1:-$kata_version}
info "build static qemu-virtiofs"
kata_version="${kata_version}" "${script_dir}/../static-build/qemu-virtiofs/build-static-qemu-virtiofs.sh"
}
# Install static firecracker asset
install_firecracker() {
kata_version=${1:-$kata_version}
info "build static firecracker"
[ -f "firecracker/firecracker-static" ] || kata_version="${kata_version}" "${script_dir}/../static-build/firecracker/build-static-firecracker.sh"
info "Install static firecracker"
mkdir -p "${destdir}/opt/kata/bin/"
sudo install -D --owner root --group root --mode 0744 firecracker/firecracker-static "${destdir}/opt/kata/bin/firecracker"
sudo install -D --owner root --group root --mode 0744 firecracker/jailer-static "${destdir}/opt/kata/bin/jailer"
pushd ${destdir}
tar -czvf ../kata-static-firecracker.tar.gz *
popd
}
# Install static cloud-hypervisor asset
install_clh() {
kata_version=${1:-$kata_version}
info "build static cloud-hypervisor"
kata_version="${kata_version}" "${script_dir}/../static-build/cloud-hypervisor/build-static-clh.sh"
info "Install static cloud-hypervisor"
mkdir -p "${destdir}/opt/kata/bin/"
sudo install -D --owner root --group root --mode 0744 cloud-hypervisor/cloud-hypervisor "${destdir}/opt/kata/bin/cloud-hypervisor"
pushd "${destdir}"
# create tarball for github release action
tar -czvf ../kata-static-clh.tar.gz *
popd
}
install_docker_config_script() {
local docker_config_script_name="kata-configure-docker.sh"
local docker_config_script="${script_dir}/../static-build/scripts/${docker_config_script_name}"
local script_dest_dir="${destdir}/opt/kata/share/scripts"
mkdir -p "$script_dest_dir"
sudo install --owner root --group root --mode 0755 \
"$docker_config_script" "$script_dest_dir"
}
#Install all components that are not assets
install_kata_components() {
kata_version=${1:-$kata_version}
for p in "${projects[@]}"; do
echo "Download ${p}"
go get "github.com/${project}/$p" || true
pushd "${GOPATH}/src/github.com/${project}/$p" >>/dev/null
echo "Checkout to version ${kata_version}"
git checkout "${kata_version}"
echo "Build"
make \
PREFIX="${prefix}" \
QEMUCMD="qemu-system-x86_64"
echo "Install"
make PREFIX="${prefix}" \
DESTDIR="${destdir}" \
install
popd >>/dev/null
done
sed -i -e '/^initrd =/d' "${destdir}/${prefix}/share/defaults/${project}/configuration-qemu.toml"
sed -i -e '/^initrd =/d' "${destdir}/${prefix}/share/defaults/${project}/configuration-fc.toml"
pushd "${destdir}/${prefix}/share/defaults/${project}"
ln -sf "configuration-qemu.toml" configuration.toml
popd
pushd "${destdir}/${prefix}/bin"
cat <<EOT | sudo tee kata-fc
#!/bin/bash
${prefix}/bin/kata-runtime --kata-config "${prefix}/share/defaults/${project}/configuration-fc.toml" \$@
EOT
sudo chmod +x kata-fc
cat <<EOT | sudo tee kata-qemu
#!/bin/bash
${prefix}/bin/kata-runtime --kata-config "${prefix}/share/defaults/${project}/configuration-qemu.toml" \$@
EOT
sudo chmod +x kata-qemu
cat <<EOT | sudo tee kata-clh
#!/bin/bash
${prefix}/bin/kata-runtime --kata-config "${prefix}/share/defaults/${project}/configuration-clh.toml" \$@
EOT
sudo chmod +x kata-clh
cat <<EOT | sudo tee kata-qemu-virtiofs
#!/bin/bash
${prefix}/bin/kata-runtime --kata-config "${prefix}/share/defaults/${project}/configuration-qemu-virtiofs.toml" \$@
EOT
sudo chmod +x kata-qemu-virtiofs
popd
pushd ${destdir}
tar -czvf ../kata-static-kata-components.tar.gz *
popd
}
untar_qemu_binaries() {
info "Install static qemu"
tar xf kata-static-qemu.tar.gz -C "${destdir}"
info "Install static qemu-virtiofs"
tar xf kata-static-qemu-virtiofsd.tar.gz -C "${destdir}"
}
main() {
while getopts "hlpw:" opt; do
case $opt in
h) usage 0 ;;
l) test_local="true" ;;
p) push="true" ;;
w) workdir="${OPTARG}" ;;
esac
done
shift $((OPTIND - 1))
kata_version=${1:-}
[ -n "${kata_version}" ] || usage 1
info "Requested version: ${kata_version}"
if [[ "$test_local" == "true" ]]; then
verify_hub
fi
destdir="${workdir}/kata-static-${kata_version}-$(uname -m)"
info "DESTDIR ${destdir}"
mkdir -p "${destdir}"
install_image
install_kata_components
install_experimental_kernel
install_kernel
install_clh
install_qemu
install_qemu_virtiofsd
install_firecracker
install_docker_config_script
untar_qemu_binaries
tarball_name="${destdir}.tar.xz"
pushd "${destdir}" >>/dev/null
tar cfJ "${tarball_name}" "./opt"
popd >>/dev/null
if [ "${push}" == "true" ]; then
hub -C "${GOPATH}/src/github.com/${project}/runtime" release edit -a "${tarball_name}" "${kata_version}"
else
echo "Wont push the tarball to github use -p option to do it."
fi
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main $@
fi

View File

@@ -0,0 +1,76 @@
#!/bin/bash
#Copyright (c) 2018 Intel Corporation
#
#SPDX-License-Identifier: Apache-2.0
#
[ -z "${DEBUG}" ] || set -x
set -o errexit
set -o nounset
set -o pipefail
workdir="${PWD}"
readonly script_name="$(basename "${BASH_SOURCE[0]}")"
readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly project="kata-containers"
GOPATH=${GOPATH:-${HOME}/go}
source "${script_dir}/../scripts/lib.sh"
source "${script_dir}/../obs-packaging/scripts/pkglib.sh"
die() {
msg="$*"
echo "ERROR: ${FUNCNAME[1]} ${msg}" >&2
exit 1
}
usage() {
return_code=${1:-0}
cat <<EOT
Usage:
${script_name} [options] <version>
version: Kata version to create the image.
Create image for a kata version.
options:
-h : show this help
-p : push image to github
EOT
exit "${return_code}"
}
main() {
push="false"
while getopts "d:hp" opt; do
case $opt in
h) usage 0 ;;
p) push="true" ;;
esac
done
shift $((OPTIND - 1))
kata_version=${1:-}
[ -n "${kata_version}" ] || usage "1"
ref="refs/tags/${kata_version}^{}"
agent_sha=$(get_kata_hash "agent" "${ref}")
agent_sha=${agent_sha:0:${short_commit_length}}
image_tarball=$(find -name 'kata-containers-*.tar.gz' | grep "${kata_version}" | grep "${agent_sha}") ||
"${script_dir}/../obs-packaging/kata-containers-image/build_image.sh" -v "${kata_version}"
image_tarball=$(find -name 'kata-containers-*.tar.gz' | grep "${kata_version}" | grep "${agent_sha}" ) || die "file not found ${image_tarball}"
if [ ${push} == "true" ]; then
hub -C "${GOPATH}/src/github.com/${project}/agent" release edit -a "${image_tarball}" "${kata_version}"
else
echo "Wont push image to github use -p option to do it."
fi
}
main $@

View File

@@ -0,0 +1,167 @@
#!/bin/bash
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
[ -z "${DEBUG}" ] || set -x
set -o errexit
set -o nounset
set -o pipefail
script_dir=$(dirname "$0")
readonly script_name="$(basename "${BASH_SOURCE[0]}")"
readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly project="kata-containers"
readonly tmp_dir=$(mktemp -d -t release-notes-tmp.XXXXXXXXXX)
# shellcheck source=../scripts/lib.sh
source "${script_dir}/../scripts/lib.sh"
exit_handler() {
[ -d "${tmp_dir}" ] || rm -rf "${tmp_dir}"
}
trap exit_handler EXIT
usage() {
return_code=${1:-}
cat <<EOT
Usage ${script_name} <previous-release> <new_release>
Args:
previous-release: will be used as start point to get release notes
new-release: new release version that will have the
Example:
./${script_name} 1.2.0 1.2.1 > notes.md
EOT
exit "${return_code}"
}
repos=(
"agent"
"proxy"
"runtime"
"shim"
)
get_release_info() {
docker_version=$(get_from_kata_deps "externals.docker.version" "${new_release}")
crio_version=$(get_from_kata_deps "externals.crio.version")
cri_containerd_version=$(get_from_kata_deps "externals.cri-containerd.version" "${new_release}")
kubernetes_version=$(get_from_kata_deps "externals.kubernetes.version" "${new_release}")
oci_spec_version=$(get_from_kata_deps "specs.oci.version" "${new_release}")
#Image information
image_info=$(get_from_kata_deps "assets.image" "${new_release}")
# Initrd information
initrd_info=$(get_from_kata_deps "assets.initrd" "${new_release}")
kernel_version=$(get_from_kata_deps "assets.kernel.version" "${new_release}")
kernel_url=$(get_from_kata_deps "assets.kernel.url" "${new_release}")
kata_kernel_config_version="${new_release}-kernel-config"
kata_kernel_config_version="${new_release}-kernel-config"
runtime_version=${new_release}
}
changes() {
echo "**FIXME - message this section by hand to produce a summary please**"
echo "### Shortlog"
for cr in $(git log --merges "${previous_release}".."${new_release}" | grep 'Merge:' | awk '{print $2".."$3}'); do
git log --oneline "$cr"
done
}
print_release_notes() {
cat <<EOT
# Release ${runtime_version}
EOT
for repo in "${repos[@]}"; do
git clone -q "https://github.com/${project}/${repo}.git" "${tmp_dir}/${repo}"
pushd "${tmp_dir}/${repo}" >>/dev/null
cat <<EOT
## ${repo} Changes
$(changes)
EOT
popd >>/dev/null
rm -rf "${tmp_dir}/${repo}"
done
cat <<EOT
## Compatibility with Docker
Kata Containers ${runtime_version} is compatible with Docker ${docker_version}
## Compatibility with CRI-O
Kata Containers ${runtime_version} is compatible with CRI-O ${crio_version}
## Compatibility with cri-containerd
Kata Containers ${runtime_version} is compatible with cri-contaienrd ${cri_containerd_version}
## OCI Runtime Specification
Kata Containers ${runtime_version} support the OCI Runtime Specification [${oci_spec_version}][ocispec]
## Compatibility with Kubernetes
Kata Containers ${runtime_version} is compatible with Kubernetes ${kubernetes_version}
## Kata Linux Containers image
Agent version: ${new_release}
### Default Image Guest OS:
${image_info}
### Default Initrd Guest OS:
${initrd_info}
## Kata Linux Containers Kernel
Kata Containers ${runtime_version} suggest to use the Linux kernel [${kernel_version}][kernel]
See the kernel suggested [Guest Kernel patches][kernel-patches]
See the kernel suggested [Guest Kernel config][kernel-config]
## Installation
Follow the Kata [installation instructions][installation].
## Issues & limitations
More information [Limitations][limitations]
[kernel]: ${kernel_url}/linux-${kernel_version#v}.tar.xz
[kernel-patches]: https://github.com/kata-containers/packaging/tree/${kata_kernel_config_version}/kernel/patches
[kernel-config]: https://github.com/kata-containers/packaging/tree/${kata_kernel_config_version}/kernel/configs
[agent]: https://github.com/kata-containers/agent/releases/tag/${runtime_version}
[image]: https://github.com/kata-containers/osbuilder/releases/tag/${runtime_version}
[ocispec]: https://github.com/opencontainers/runtime-spec/releases/tag/${oci_spec_version}
[limitations]: https://github.com/kata-containers/documentation/blob/master/Limitations.md
[installation]: https://github.com/kata-containers/documentation/tree/master/install
EOT
}
main() {
previous_release=${1:-}
new_release=${2:-}
if [ -z "${previous_release}" ]; then
echo "previous-release not provided"
usage 1
fi
if [ -z "${new_release}" ]; then
echo "new-release not provided"
usage 1
fi
get_release_info
print_release_notes
}
main "$@"

View File

@@ -0,0 +1,243 @@
#!/bin/bash
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -o errexit
set -o nounset
set -o pipefail
tmp_dir=$(mktemp -d -t tag-repos-tmp.XXXXXXXXXX)
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
script_name="$(basename "${BASH_SOURCE[0]}")"
OWNER=${OWNER:-"kata-containers"}
PROJECT="Kata Containers"
PUSH="${PUSH:-"false"}"
branch="master"
readonly URL_RAW_FILE="https://raw.githubusercontent.com/${OWNER}"
#The runtime version is used as reference of latest release
# This is set to the right value later.
kata_version=""
# Set if a new stable branch is created
stable_branch=""
source "${script_dir}/../scripts/lib.sh"
function usage() {
cat <<EOT
Usage: ${script_name} [options] <args>
This script creates a new release for ${PROJECT}.
It tags and create release for:
EOT
for r in "${repos[@]}"; do
echo " - ${r}"
done
cat <<EOT
Args:
status : Get Current ${PROJECT} tags status
pre-release <target-version>: Takes a version to check all the components match with it (but not the runtime)
tag : Create tags for ${PROJECT}
Options:
-b <branch>: branch were will check the version.
-h : Show this help
-p : push tags
EOT
}
finish() {
rm -rf "$tmp_dir"
}
trap finish EXIT
die() {
echo >&2 "ERROR: $*"
exit 1
}
info() {
echo "INFO: $*"
}
repos=(
"agent"
"documentation"
"ksm-throttler"
"osbuilder"
"packaging"
"proxy"
"runtime"
"shim"
"tests"
"kata-containers"
)
# The pre-release option at the check_versions function receives
# the runtime VERSION in order to check all the components match with it,
# this has the purpose that all the components have the same version before
# merging the runtime version
check_versions() {
version_to_check=${1:-}
if [ -z "${version_to_check}" ];then
info "Query the version from latest runtime in branch ${branch}"
else
kata_version="${version_to_check}"
fi
info "Tagging ${PROJECT} with version ${kata_version}"
info "Check all repos has version ${kata_version} in VERSION file"
for repo in "${repos[@]}"; do
if [ ! -z "${version_to_check}" ] && [ "${repo}" == "runtime" ]; then
info "Not checking runtime because we want the rest of repos are in ${version_to_check}"
continue
fi
repo_version=$(curl -Ls "${URL_RAW_FILE}/${repo}/${branch}/VERSION" | grep -v -P "^#")
info "${repo} is in $repo_version"
[ "${repo_version}" == "${kata_version}" ] || die "${repo} is not in version ${kata_version}"
done
}
do_tag(){
local tag=${1:-}
[ -n "${tag}" ] || die "No tag not provided"
if git rev-parse -q --verify "refs/tags/${tag}"; then
info "$repo already has tag"
else
info "Creating tag ${tag} for ${repo}"
git tag -a "${tag}" -s -m "${PROJECT} release ${tag}"
fi
}
tag_repos() {
info "Creating tag ${kata_version} in all repos"
for repo in "${repos[@]}"; do
git clone --quiet "https://github.com/${OWNER}/${repo}.git"
pushd "${repo}" >>/dev/null
git remote set-url --push origin "git@github.com:${OWNER}/${repo}.git"
git fetch origin
git checkout "${branch}"
version_from_file=$(cat ./VERSION)
info "Check VERSION file has ${kata_version}"
if [ "${version_from_file}" != "${kata_version}" ];then
die "mismatch: VERSION file (${version_from_file}) and runtime version ${kata_version}"
else
echo "OK"
fi
git fetch origin --tags
tag="$kata_version"
if [[ "packaging" == "${repo}" ]];then
do_tag "${tag}-kernel-config"
fi
do_tag "${tag}"
if [ "${branch}" == "master" ]; then
if echo "${tag}" | grep -oP '.*-rc0$'; then
info "This is a rc0 for master - creating stable branch"
stable_branch=$(echo ${tag} | awk 'BEGIN{FS=OFS="."}{print $1 "." $2}')
stable_branch="stable-${stable_branch}"
info "creating branch ${stable_branch} for ${repo}"
git checkout -b "${stable_branch}" "${branch}"
fi
fi
popd >>/dev/null
done
}
push_tags() {
info "Pushing tags to repos"
build_hub
for repo in "${repos[@]}"; do
pushd "${repo}" >>/dev/null
tag="$kata_version"
if [[ "packaging" == "${repo}" ]];then
ktag="${tag}-kernel-config"
info "Push tag ${ktag} for ${repo}"
git push origin "${ktag}"
fi
info "Push tag ${tag} for ${repo}"
git push origin "${tag}"
create_github_release "${PWD}" "${tag}"
if [ "${stable_branch}" != "" ]; then
info "Pushing stable ${stable_branch} branch for ${repo}"
git push origin ${stable_branch}
fi
popd >>/dev/null
done
}
create_github_release() {
repo_dir=${1:-}
tag=${2:-}
[ -d "${repo_dir}" ] || die "No repository directory"
[ -n "${tag}" ] || die "No tag specified"
if ! "${hub_bin}" release show "${tag}"; then
info "Creating Github release"
if [[ "$tag" =~ "-rc" ]]; then
rc_args="-p"
fi
rc_args=${rc_args:-}
"${hub_bin}" -C "${repo_dir}" release create ${rc_args} -m "${PROJECT} ${tag}" "${tag}"
else
info "Github release already created"
fi
}
main () {
while getopts "b:hp" opt; do
case $opt in
b) branch="${OPTARG}" ;;
h) usage && exit 0 ;;
p) PUSH="true" ;;
esac
done
shift $((OPTIND - 1))
subcmd=${1:-""}
shift || true
kata_version=$(curl -Ls "${URL_RAW_FILE}/runtime/${branch}/VERSION" | grep -v -P "^#")
[ -z "${subcmd}" ] && usage && exit 0
pushd "${tmp_dir}" >>/dev/null
case "${subcmd}" in
status)
check_versions
;;
pre-release)
local target_version=${1:-}
[ -n "${target_version}" ] || die "No version provided"
check_versions "${target_version}"
;;
tag)
check_versions
tag_repos
if [ "${PUSH}" == "true" ]; then
push_tags
else
info "tags not pushed, use -p option to push the tags"
fi
;;
*)
usage && die "Invalid argument ${subcmd}"
;;
esac
popd >>/dev/null
}
main "$@"

View File

@@ -0,0 +1,26 @@
#!/bin/bash
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -o errexit
set -o nounset
set -o pipefail
echo "Check tag_repos.sh show help"
./release/tag_repos.sh | grep Usage
echo "Check tag_repos.sh -h option"
./release/tag_repos.sh -h | grep Usage
echo "Check tag_repos.sh status"
./release/tag_repos.sh status | grep runtime
echo "Check tag_repos.sh pre-release"
./release/tag_repos.sh pre-release $(curl -sL https://raw.githubusercontent.com/kata-containers/runtime/master/VERSION) | grep "Not checking runtime"
echo "Check tag_repos.sh pre-release with invalid information"
./release/tag_repos.sh pre-release 1000000 | grep "ERROR" || true

View File

@@ -0,0 +1,202 @@
#!/bin/bash
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -o errexit
set -o nounset
set -o pipefail
readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly script_name="$(basename "${BASH_SOURCE[0]}")"
readonly tmp_dir=$(mktemp -t -d pr-bump.XXXX)
readonly organization="kata-containers"
PUSH="false"
GOPATH=${GOPATH:-${HOME}/go}
source "${script_dir}/../scripts/lib.sh"
cleanup() {
[ -d "${tmp_dir}" ] && rm -rf "${tmp_dir}"
}
trap cleanup EXIT
handle_error() {
local exit_code="${?}"
local line_number="${1:-}"
echo "Failed at $line_number: ${BASH_COMMAND}"
exit "${exit_code}"
}
trap 'handle_error $LINENO' ERR
get_changes() {
local current_version=$1
[ -n "${current_version}" ] || die "current version not provided"
if [ "${current_version}" == "new" ];then
echo "Starting to version this repository"
return
fi
# If for some reason there is not a tag this could fail
# better fail and write the error in the PR
if ! changes=$(git log --oneline "${current_version}..HEAD"); then
echo "failed to get logs"
fi
if [ "${changes}" == "" ]; then
echo "Version bump no changes"
return
fi
# list all PRs merged from $current_version to HEAD
git log --merges "${current_version}..HEAD" | awk '/Merge pull/{getline; getline;print }' | while read pr; do
echo "- ${pr}"
done
echo ""
# list all commits added in this new version.
git log --oneline "${current_version}..HEAD" --no-merges
}
generate_commit() {
local new_version=$1
local current_version=$2
[ -n "$new_version" ] || die "no new version"
[ -n "$current_version" ] || die "no current version"
printf "release: Kata Containers %s\n\n" "${new_version}"
get_changes "$current_version"
}
bump_repo() {
local repo="${1:-}"
local new_version="${2:-}"
local target_branch="${3:-}"
[ -n "${repo}" ] || die "repository not provided"
[ -n "${new_version}" ] || die "no new version"
[ -n "${target_branch}" ] || die "no target branch"
local remote_github="https://github.com/${organization}/${repo}.git"
info "Update $repo to version $new_version"
info "remote: ${remote_github}"
git clone --quiet "${remote_github}"
pushd "${repo}" >>/dev/null
branch="${new_version}-branch-bump"
git fetch origin "${target_branch}"
git checkout "origin/${target_branch}" -b "${branch}"
# All repos we build should have a VERSION file
if [ ! -f "VERSION" ]; then
current_version="new"
echo "${new_version}" >VERSION
else
current_version="$(grep -v '#' ./VERSION)"
info "Updating VERSION file"
echo "${new_version}" >VERSION
if git diff --exit-code; then
info "${repo} already in version ${new_version}"
cat VERSION
return 0
fi
fi
info "Creating PR message"
notes_file=notes.md
cat <<EOT >"${notes_file}"
# Kata Containers ${new_version}
$(get_changes "$current_version")
EOT
cat "${notes_file}"
if (echo "${current_version}" | grep "alpha") && (echo "${new_version}" | grep -v "alpha");then
info "update move from alpha, check if new version is rc0"
if echo "$new_version" | grep -v "rc0"; then
die "bump should be from alpha to rc0"
fi
info "OK"
fi
git add VERSION
info "Creating commit with new changes"
commit_msg="$(generate_commit $new_version $current_version)"
git commit -s -m "${commit_msg}"
if [[ ${PUSH} == "true" ]]; then
build_hub
info "Forking remote"
${hub_bin} fork --remote-name=fork
info "Push to fork"
${hub_bin} push fork -f "${branch}"
info "Create PR"
out=""
out=$("${hub_bin}" pull-request -b "${target_branch}" -F "${notes_file}" 2>&1) || echo "$out" | grep "A pull request already exists"
fi
popd >>/dev/null
}
usage() {
exit_code="$1"
cat <<EOT
Usage:
${script_name} [options] <args>
Args:
<new-version> : New version to bump the repository
<target-branch> : The base branch to create to PR
Example:
${script_name} 1.10
Options
-h : Show this help
-p : create a PR
EOT
exit "$exit_code"
}
repos=(
"agent"
"documentation"
"kata-containers"
"ksm-throttler"
"osbuilder"
"packaging"
"proxy"
"runtime"
"shim"
"tests"
)
main(){
while getopts "hp" opt; do
case $opt in
h) usage 0 ;;
p) PUSH="true" ;;
esac
done
shift $((OPTIND - 1))
new_version=${1:-}
target_branch=${2:-}
[ -n "${new_version}" ] || { echo "ERROR: no new version" && usage 1; }
[ -n "${target_branch}" ] || die "no target branch"
for repo in "${repos[@]}"
do
pushd "$tmp_dir" >>/dev/null
bump_repo "${repo}" "${new_version}" "${target_branch}"
popd >>/dev/null
done
}
main $@

View File

@@ -0,0 +1,54 @@
#!/bin/bash
#
#Copyright (c) 2018 Intel Corporation
#
#SPDX-License-Identifier: Apache-2.0
#
set -o errexit
set -o nounset
set -o pipefail
readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
out=""
handle_error() {
echo "not ok"
echo "output: ${out}"
}
OK() {
echo "ok"
}
output_should_contain() {
local output="$1"
local text_to_find="$2"
[ -n "$output" ]
[ -n "$text_to_find" ]
echo "${output}" | grep "${text_to_find}"
}
trap handle_error ERR
echo "Missing args show help"
out=$("${script_dir}/update-repository-version.sh" 2>&1) || (($? != 0))
echo "${out}" | grep Usage >>/dev/null
output_should_contain "${out}" "Usage"
OK
echo "Missing version show help"
out=$("${script_dir}/update-repository-version.sh" 2>&1) || (($? != 0))
echo "${out}" | grep Usage >>/dev/null
echo "${out}" | grep "no new version" >>/dev/null
OK
echo "help option"
out=$("${script_dir}/update-repository-version.sh" -h)
output_should_contain "${out}" "Usage"
OK
echo "Local update version update should work"
new_version="50.0.0-rc0"
out=$("${script_dir}/update-repository-version.sh" "${new_version}" "master" 2>&1)
output_should_contain "${out}" "release: Kata Containers ${new_version}"
OK