From 567a603dd482de8bb9c0a7ef10498f8d5d84c119 Mon Sep 17 00:00:00 2001 From: Yecheng Fu Date: Thu, 26 Mar 2020 16:14:25 +0800 Subject: [PATCH] remove dependencies on k8s-node (#2036) * remove dependencies on k8s-node * fix --- ci/pingcap_tidb_operator_build_kind.groovy | 38 +++++------ ci/upload-binaries-charts.sh | 78 ++++++++++++++++++++++ 2 files changed, 97 insertions(+), 19 deletions(-) create mode 100755 ci/upload-binaries-charts.sh diff --git a/ci/pingcap_tidb_operator_build_kind.groovy b/ci/pingcap_tidb_operator_build_kind.groovy index 29ba809a8b..fff7b5eac6 100644 --- a/ci/pingcap_tidb_operator_build_kind.groovy +++ b/ci/pingcap_tidb_operator_build_kind.groovy @@ -252,26 +252,26 @@ def call(BUILD_BRANCH, CREDENTIALS_ID, CODECOV_CREDENTIALS_ID) { builds.failFast = false parallel builds - // we requires ~/bin/config.cfg, filemgr-linux64 utilities on k8s-kind node - // TODO make it possible to run on any node if ( !(BUILD_BRANCH ==~ /[a-z0-9]{40}/) ) { - node('k8s-kind') { - dir("${PROJECT_DIR}") { - deleteDir() - unstash 'tidb-operator' - stage('upload tidb-operator, tidb-backup-manager binary and charts'){ - //upload binary and charts - sh """ - cp ~/bin/config.cfg ./ - tar -zcvf tidb-operator.tar.gz images/tidb-operator images/tidb-backup-manager charts - filemgr-linux64 --action mput --bucket pingcap-dev --nobar --key builds/pingcap/operator/${GITHASH}/centos7/tidb-operator.tar.gz --file tidb-operator.tar.gz - """ - //update refs - writeFile file: 'sha1', text: "${GITHASH}" - sh """ - filemgr-linux64 --action mput --bucket pingcap-dev --nobar --key refs/pingcap/operator/${BUILD_BRANCH}/centos7/sha1 --file sha1 - rm -f sha1 tidb-operator.tar.gz config.cfg - """ + node('build_go1130_memvolume') { + container("golang") { + def WORKSPACE = pwd() + dir("${PROJECT_DIR}") { + unstash 'tidb-operator' + stage('upload tidb-operator binaries and charts'){ + withCredentials([ + string(credentialsId: 'UCLOUD_PUBLIC_KEY', variable: 'UCLOUD_PUBLIC_KEY'), + string(credentialsId: 'UCLOUD_PRIVATE_KEY', variable: 'UCLOUD_PRIVATE_KEY'), + ]) { + sh """ + export UCLOUD_UFILE_PROXY_HOST=mainland-hk.ufileos.com + export UCLOUD_UFILE_BUCKET=pingcap-dev + export BUILD_BRANCH=${BUILD_BRANCH} + export GITHASH=${GITHASH} + ./ci/upload-binaries-charts.sh + """ + } + } } } } diff --git a/ci/upload-binaries-charts.sh b/ci/upload-binaries-charts.sh new file mode 100755 index 0000000000..e9c429365f --- /dev/null +++ b/ci/upload-binaries-charts.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +# Copyright 2020 PingCAP, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd) +cd $ROOT + +source "${ROOT}/hack/lib.sh" + +UCLOUD_PUBLIC_KEY=${UCLOUD_PUBLIC_KEY:-} +UCLOUD_PRIVATE_KEY=${UCLOUD_PRIVATE_KEY:-} +UCLOUD_UFILE_PROXY_HOST=${UCLOUD_UFILE_PROXY_HOST:-} +UCLOUD_UFILE_API_HOST=${UCLOUD_UFILE_API_HOST:-api.spark.ucloud.cn} +UCLOUD_UFILE_BUCKET=${UCLOUD_UFILE_BUCKET:-} +GITHASH=${GITHASH:-} +BUILD_BRANCH=${BUILD_BRANCH:-} + +FILEMGR_URL="http://tools.ufile.ucloud.com.cn/filemgr-linux64.tar.gz" + +if [ -z "$UCLOUD_PUBLIC_KEY" -o -z "$UCLOUD_PRIVATE_KEY" -o -z "$UCLOUD_UFILE_PROXY_HOST" ]; then + echo "error: UCLOUD_PUBLIC_KEY/UCLOUD_PUBLIC_KEY/UCLOUD_UFILE_PROXY_HOST are required" + exit 1 +fi + +if [ -z "$UCLOUD_UFILE_BUCKET" ]; then + echo "error: UCLOUD_UFILE_BUCKET is required" + exit 1 +fi + +if [ -z "$GITHASH" -o -z "$BUILD_BRANCH" ]; then + echo "error: GITHASH/BUILD_BRANCH are required" + exit 1 +fi + +function upload() { + local dir=$(mktemp -d) + trap "test -d $dir && rm -rf $dir" RETURN + + echo "info: create a temporary directory: $dir" + + cat < $dir/config.cfg +{ + "public_key" : "${UCLOUD_PUBLIC_KEY}", + "private_key" : "${UCLOUD_PRIVATE_KEY}", + "proxy_host" : "${UCLOUD_UFILE_PROXY_HOST}", + "api_host" : "${UCLOUD_UFILE_API_HOST}" +} +EOF + + echo "info: downloading filemgr from $FILEMGR_URL" + curl --retry 10 -L -s "$FILEMGR_URL" | tar --strip-components 2 -C $dir -xzvf - ./linux64/filemgr-linux64 + + echo "info: uploading charts and binaries" + tar -zcvf $dir/tidb-operator.tar.gz images/tidb-operator images/tidb-backup-manager charts + $dir/filemgr-linux64 --config $dir/config.cfg --action mput --bucket ${UCLOUD_UFILE_BUCKET} --nobar --key builds/pingcap/operator/${GITHASH}/centos7/tidb-operator.tar.gz --file $dir/tidb-operator.tar.gz + + echo "info: update ref of branch '$BUILD_BRANCH'" + echo -n $GITHASH > $dir/sha1 + $dir/filemgr-linux64 --config $dir/config.cfg --action mput --bucket ${UCLOUD_UFILE_BUCKET} --nobar --key refs/pingcap/operator/${BUILD_BRANCH}/centos7/sha1 --file $dir/sha1 +} + +# retry a few times until it succeeds, this can avoid temporary network flakes +hack::wait_for_success 120 5 "upload"