diff --git a/Jenkinsfiles/release_pieline/Jenkinsfile b/Jenkinsfiles/release_pieline/Jenkinsfile new file mode 100644 index 0000000000..7032efb219 --- /dev/null +++ b/Jenkinsfiles/release_pieline/Jenkinsfile @@ -0,0 +1,42 @@ +// Copyright (c) 2019 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// +pipeline { + agent none + parameters { + string( + name: 'BRANCH', + defaultValue:"master", + description: "Kata Containers Branch" + ) + string( + name: 'NEW_VERSION', + defaultValue:"", + description: "Kata Containers version" + ) + } + environment { + PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + BRANCH="${params.BRANCH}" + NEW_VERSION="${params.NEW_VERSION}" + } + stages { + stage('Bump repos') { + agent { label 'ubuntu-lts-latest-azure' } + steps { + sh ''' + git clone https://github.com/kata-containers/packaging.git + cd packaging + ''' + withCredentials([string(credentialsId: 'katabuilder-git-bump', variable: 'GITHUB_TOKEN')]) { + sh ''' + cd packaging + ./Jenkinsfiles/release_pieline/git_credential_cache.sh + ./Jenkinsfiles/release_pieline/bump.sh "${NEW_VERSION}" "${BRANCH}" + ''' + } + } + } + } +} diff --git a/Jenkinsfiles/release_pieline/bump.sh b/Jenkinsfiles/release_pieline/bump.sh new file mode 100755 index 0000000000..3db1e92b52 --- /dev/null +++ b/Jenkinsfiles/release_pieline/bump.sh @@ -0,0 +1,114 @@ +#!/bin/bash +# Copyright (c) 2019 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# + +export CI="true" + +set -o errexit +set -o nounset +set -o pipefail +set -o errtrace + +readonly script_name="$(basename "${BASH_SOURCE[0]}")" + +function handle_error() { + local exit_code="${?}" + local line_number="${1:-}" + echo "Failed at $line_number: ${BASH_COMMAND}" + exit "${exit_code}" +} +trap 'handle_error $LINENO' ERR + +die() { + echo >&2 "ERROR: $*" + exit 1 +} + +install_go() { + echo "Installing go" + export GOROOT="/usr/local/go" + # shellcheck disable=SC2016 + echo 'export PATH=$PATH:'"${GOROOT}/bin" | sudo tee -a /etc/profile + export PATH="$PATH:${GOROOT}/bin" + + export GOPATH="${WORKSPACE}/go" + mkdir -p "${GOPATH}" + + tests_repo="github.com/kata-containers/tests" + tests_repo_dir="${GOPATH}/src/${tests_repo}" + # shellcheck disable=SC2046 + mkdir -p $(dirname "${tests_repo_dir}") + [ -d "${tests_repo_dir}" ] || git clone "https://${tests_repo}.git" "${tests_repo_dir}" + "${GOPATH}/src/${tests_repo}/.ci/install_go.sh" -p -f + go version +} + +install_docker() { + echo "Installing docker" + sudo -E apt-get -y install apt-transport-https ca-certificates software-properties-common + curl -sL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + arch=$(dpkg --print-architecture) + sudo -E add-apt-repository "deb [arch=${arch}] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + sudo -E apt-get update + sudo -E apt-get -y install docker-ce +} + +setup_git() { + echo "configuring git" + git config --global user.email "katabuilder@katacontainers.io" + git config --global user.name "katabuilder" + export HUB_PROTOCOL=https +} + +bump_kata() { + new_version=${1:-} + branch=${2:-} + [ -n "${new_version}" ] + [ -n "${branch}" ] + readonly packaging_repo="github.com/kata-containers/packaging" + readonly packaging_repo_dir="${GOPATH}/src/${packaging_repo}" + [ -d "${packaging_repo_dir}" ] || git clone "https://${packaging_repo}.git" "${packaging_repo_dir}" + + cd "${packaging_repo_dir}/release" + [ "$branch" == "master" ] && ./update-repository-version.sh -p ksm-throttler "$new_version" "$branch" + ./update-repository-version.sh -p proxy "$new_version" "$branch" + ./update-repository-version.sh -p shim "$new_version" "$branch" + ./update-repository-version.sh -p runtime "$new_version" "$branch" + [ "$branch" == "master" ] && ./update-repository-version.sh -p osbuilder "$new_version" "$branch" + ./update-repository-version.sh -p agent "$new_version" "$branch" +} + +setup() { + setup_git + install_go + install_docker +} + +usage() { + exit_code="$1" + cat < +Args: + : new version to bump kata + : branch target +Example: + ${script_name} 1.10 +EOT + + exit "$exit_code" +} + +main() { + new_version=${1:-} + branch=${2:-} + [ -n "${new_version}" ] || usage 1 + [ -n "${branch}" ] || usage 1 + echo "Start Release ${new_version} for branch ${branch}" + setup + bump_kata "${new_version}" "${branch}" +} + +main $@ diff --git a/Jenkinsfiles/release_pieline/git_credential_cache.sh b/Jenkinsfiles/release_pieline/git_credential_cache.sh new file mode 100755 index 0000000000..16cfd8bc7e --- /dev/null +++ b/Jenkinsfiles/release_pieline/git_credential_cache.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# Copyright (c) 2019 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# +set -o errexit +set -o nounset +set -o pipefail +set -o errtrace + +die() { + echo >&2 "ERROR: $*" + exit 1 +} + +init_git_credential_cache() { + #This is needed to setup github credentials to do push in a job + ( + + set -o errexit + set -o nounset + set -o pipefail + set -o errtrace + set +x + + readonly token_sh=$(mktemp) + readonly agent_clone=$(mktemp -d) + finish() { + rm -rf "${token_sh}" + rm -rf "${agent_clone}" + } + trap finish EXIT + + chmod 700 "${token_sh}" + cat <"${token_sh}" +#!/bin/bash +echo "\$GITHUB_TOKEN" +EOT + export GIT_ASKPASS=${token_sh} + + #cache credential + git config --global credential.helper cache + #setup credential + git clone https://github.com/katabuilder/agent.git "${agent_clone}" + cd "${agent_clone}" || exit 1 + #this set the credential for first time + git push + # not needed anymore + unset GIT_ASKPASS + ) >>/dev/null +} + +main() { + [ -n "$GITHUB_TOKEN" ] || die "GITHUB_TOKEN not set" + init_git_credential_cache +} + +main $@