Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b61da6f

Browse files
committed
Move push-ci-build.sh functionality to release repo.
1 parent 9fa578a commit b61da6f

5 files changed

Lines changed: 270 additions & 54 deletions

File tree

README-CI.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Continuous Integration How-to
2+
3+
Called from hack/jenkins/build.sh

anago

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -952,17 +952,21 @@ for label in ${!RELEASE_VERSION[@]}; do
952952
common::stepheader "PUSH ${RELEASE_VERSION[$label]} IMAGES"
953953
##############################################################################
954954
common::runstep release::gcs::copy_release_artifacts \
955-
${RELEASE_VERSION[$label]} \
956-
$BUILD_OUTPUT-${RELEASE_VERSION[$label]} $RELEASE_BUCKET \
955+
release/${RELEASE_VERSION[$label]} \
956+
$BUILD_OUTPUT-${RELEASE_VERSION[$label]} \
957+
$RELEASE_BUCKET \
957958
|| common::exit 1 "Exiting..."
958959

959960
common::runstep release::docker::release \
960-
$KUBE_DOCKER_REGISTRY ${RELEASE_VERSION[$label]} \
961+
$KUBE_DOCKER_REGISTRY \
962+
${RELEASE_VERSION[$label]} \
961963
|| common::exit 1 "Exiting..."
962964

963-
common::runstep release::gcs::publish_official \
965+
common::runstep release::gcs::publish_version \
966+
release \
964967
${RELEASE_VERSION[$label]} \
965-
$BUILD_OUTPUT-${RELEASE_VERSION[$label]} $RELEASE_BUCKET \
968+
$BUILD_OUTPUT-${RELEASE_VERSION[$label]} \
969+
$RELEASE_BUCKET \
966970
|| common::exit 1 "Exiting..."
967971
done
968972

lib/gitlib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ BRANCH_REGEX="master|release-([0-9]{1,})\.([0-9]{1,})(\.([0-9]{1,}))*$"
3636
# release - 1=Major, 2=Minor, 3=Patch, 4=-(alpha|beta), 5=rev
3737
# dotzero - 1=Major, 2=Minor
3838
# build - 1=build number, 2=sha1
39-
declare -A VER_REGEX=([release]="v([0-9]{1,})\.([0-9]{1,})\.([0-9]{1,})(-alpha|-beta)*\.*([0-9]{1,})*"
40-
[dotzero]="v([0-9]{1,})\.([0-9]{1,})\.0$"
39+
declare -A VER_REGEX=([release]="v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-alpha|-beta)*\.*(0|[1-9][0-9]*)?"
40+
[dotzero]="v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.0$"
4141
[build]="([0-9]{1,})\+([0-9a-f]{5,40})"
4242
)
4343

lib/releaselib.sh

Lines changed: 78 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -443,24 +443,25 @@ release::gcs::stage_and_hash() {
443443

444444
###############################################################################
445445
# Copy the release artifacts to staging and push them up to GS
446-
# TODO: There is a version of this in kubernetes/build/common.sh that is also
447-
# used by the build/push-*-build.sh scripts. Refactor.
448-
# @param version - release version
446+
# @param target_version - something like release/<version>
449447
# @param build_output - build output directory
450448
# @param bucket - GS bucket
449+
# @optparam bucket_mirror - (optional) mirror GS bucket
451450
# @return 1 on failure
452451
release::gcs::copy_release_artifacts() {
453-
local version=$1
452+
local target_version=$1
454453
local build_output=$2
455454
local bucket=$3
455+
local bucket_mirror=$4
456456
local platform
457457
local platforms
458458
local release_stage=$build_output/release-stage
459459
local release_tars=$build_output/release-tars
460460
local gcs_stage=$build_output/gcs-stage
461461
local src
462462
local dst
463-
local gcs_destination=gs://$bucket/release/$version/
463+
local gcs_destination=gs://$bucket/$target_version
464+
local gcs_mirror=gs://$bucket_mirror/$target_version
464465
local gce_path=$release_stage/full/kubernetes/cluster/gce
465466
local gci_path
466467

@@ -510,45 +511,60 @@ release::gcs::copy_release_artifacts() {
510511
common::sha $path 1 > "$path.sha1" || return 1
511512
done
512513

514+
# Copy the main set from staging to destination
513515
logecho -n "- Copying release artifacts to $gcs_destination: "
514516
logrun -s $GSUTIL -qm cp -r $gcs_stage/* $gcs_destination || return 1
515517

516-
# TODO(jbeda): Generate an HTML page with links for this release so it is easy
517-
# to see it. For extra credit, generate a dynamic page that builds up the
518-
# release list using the GCS JSON API. Use Angular and Bootstrap for extra
519-
# extra credit.
520-
521518
logecho -n "- Marking all uploaded objects public: "
522519
logrun -s $LOGRUN_MOCK $GSUTIL -q -m acl ch -R -g all:R \
523-
"$gcs_destination" || return 1
520+
"$gcs_destination" || return 1
524521

525522
logecho -n "- Listing final contents to log file: "
526523
logrun -s $GSUTIL ls -lhr "$gcs_destination" || return 1
524+
525+
# Push to mirror if set
526+
if [[ -n "$bucket_mirror" && "$bucket" != "$bucket_mirror" ]]; then
527+
logecho -n "- Mirroring build to $gcs_mirror: "
528+
logrun -s $GSUTIL -q -m rsync -d -r "$gcs_destination" "$gcs_mirror" \
529+
|| return 1
530+
logecho -n "- Marking all uploaded mirror objects public: "
531+
logrun -s $LOGRUN_MOCK $GSUTIL -q -m acl ch -R -g all:R \
532+
"$gcs_mirror" || return 1
533+
fi
527534
}
528535

529536

530537
###############################################################################
531-
# Publish a new official version, (latest or stable,) but only if the release
532-
# files actually exist on GCS and the release we're dealing with is newer than
533-
# the contents in GCS.
534-
# @param version - release version
538+
# Publish a new version, (latest or stable,) but only if the
539+
# files actually exist on GCS and the artifacts we're dealing with are newer
540+
# than the contents in GCS.
541+
# @param build_type - One of 'release' or 'ci'
542+
# @param version - The version
535543
# @param build_output - build output directory
536544
# @param bucket - GS bucket
545+
# @optparam bucket_mirror - GS mirror bucket
537546
# @return 1 on failure
538-
release::gcs::publish_official () {
539-
local version=$1
540-
local build_output=$2
541-
local bucket=$3
542-
local release_dir="gs://$bucket/release/$version"
547+
release::gcs::publish_version () {
548+
local build_type=$1
549+
local version=$2
550+
local build_output=$3
551+
local bucket=$4
552+
local bucket_mirror=$5
553+
local release_dir="gs://$bucket/$build_type/$version"
543554
local version_major
544555
local version_minor
545556
local publish_file
546-
local publish_files
557+
local -a publish_files
558+
local -a publish_buckets=($bucket)
547559
local type="latest"
548-
[[ "$version" =~ alpha|beta ]] || type="stable"
549560

550-
logecho
551-
logecho "Publish official pointer text files to $bucket..."
561+
# Ensure no duplicate
562+
[[ "$bucket" != "$bucket_mirror" ]] && publish_buckets+=($bucket_mirror)
563+
564+
# For release/ targets, type could be 'stable'
565+
if [[ "$build_type" == release ]]; then
566+
[[ "$version" =~ alpha|beta ]] || type="stable"
567+
fi
552568

553569
if ! $GSUTIL ls $release_dir >/dev/null 2>&1 ; then
554570
logecho "Release files don't exist at $release_dir"
@@ -565,13 +581,18 @@ release::gcs::publish_official () {
565581
$type-$version_major.$version_minor
566582
)
567583

568-
for publish_file in ${publish_files[@]}; do
569-
# If there's a version that's above the one we're trying to release, don't
570-
# do anything, and just try the next one.
571-
release::gcs::verify_release_gt release/$publish_file.txt \
572-
$bucket $version || continue
573-
release::gcs::publish release/$publish_file.txt $build_output \
574-
$bucket $version || return 1
584+
for b in ${publish_buckets[*]}; do
585+
logecho
586+
logecho "Publish official pointer text files to $b..."
587+
588+
for publish_file in ${publish_files[@]}; do
589+
# If there's a version that's above the one we're trying to release, don't
590+
# do anything, and just try the next one.
591+
release::gcs::verify_latest_update $build_type/$publish_file.txt \
592+
$b $version || continue
593+
release::gcs::publish $build_type/$publish_file.txt $build_output \
594+
$b $version || return 1
595+
done
575596
done
576597
}
577598

@@ -584,16 +605,16 @@ release::gcs::publish_official () {
584605
# @param version - release version
585606
# @return 1 if new version is not greater than the GCS version
586607
#
587-
release::gcs::verify_release_gt() {
608+
release::gcs::verify_latest_update () {
588609
local -r publish_file=$1
589610
local -r bucket=$2
590611
local -r version=$3
591612
local -r publish_file_dst="gs://$bucket/$publish_file"
592613
local gcs_version
593-
local greater=true
614+
local greater=1
594615

595616
logecho -n "Test $version > $publish_file (published): "
596-
if ! [[ $version =~ ${VER_REGEX[release]} ]]; then
617+
if ! [[ $version =~ ${VER_REGEX[release]}(.${VER_REGEX[build]})* ]]; then
597618
logecho -r "$FAILED"
598619
logecho "* Invalid version format! $version"
599620
return 1
@@ -604,9 +625,10 @@ release::gcs::verify_release_gt() {
604625
local -r version_patch="${BASH_REMATCH[3]}"
605626
local -r version_prerelease="${BASH_REMATCH[4]}"
606627
local -r version_prerelease_rev="${BASH_REMATCH[5]}"
628+
local -r version_commits="${BASH_REMATCH[7]}"
607629

608630
if gcs_version="$($GSUTIL cat $publish_file_dst 2>/dev/null)"; then
609-
if ! [[ $gcs_version =~ ${VER_REGEX[release]} ]]; then
631+
if ! [[ $gcs_version =~ ${VER_REGEX[release]}(.${VER_REGEX[build]})* ]]; then
610632
logecho -r "$FAILED"
611633
logecho "* file contains invalid release version," \
612634
"can't compare: '$gcs_version'"
@@ -618,17 +640,18 @@ release::gcs::verify_release_gt() {
618640
local -r gcs_version_patch="${BASH_REMATCH[3]}"
619641
local -r gcs_version_prerelease="${BASH_REMATCH[4]}"
620642
local -r gcs_version_prerelease_rev="${BASH_REMATCH[5]}"
643+
local -r gcs_version_commits="${BASH_REMATCH[7]}"
621644

622645
if [[ "$version_major" -lt "$gcs_version_major" ]]; then
623-
greater=false
646+
greater=0
624647
elif [[ "$version_major" -gt "$gcs_version_major" ]]; then
625648
: # fall out
626649
elif [[ "$version_minor" -lt "$gcs_version_minor" ]]; then
627-
greater=false
650+
greater=0
628651
elif [[ "$version_minor" -gt "$gcs_version_minor" ]]; then
629652
: # fall out
630653
elif [[ "$version_patch" -lt "$gcs_version_patch" ]]; then
631-
greater=false
654+
greater=0
632655
elif [[ "$version_patch" -gt "$gcs_version_patch" ]]; then
633656
: # fall out
634657
# Use lexicographic (instead of integer) comparison because
@@ -638,19 +661,28 @@ release::gcs::verify_release_gt() {
638661
# We have to do this because lexicographically "beta" > "alpha" > "", but
639662
# we want official > beta > alpha.
640663
elif [[ -n "$version_prerelease" && -z "$gcs_version_prerelease" ]]; then
641-
greater=false
664+
greater=0
642665
elif [[ -z "$version_prerelease" && -n "$gcs_version_prerelease" ]]; then
643666
: # fall out
644667
elif [[ "$version_prerelease" < "$gcs_version_prerelease" ]]; then
645-
greater=false
668+
greater=0
646669
elif [[ "$version_prerelease" > "$gcs_version_prerelease" ]]; then
647670
: # fall out
648671
# Finally resort to -le here, since we want strictly-greater-than.
649-
elif [[ "$version_prerelease_rev" -le "$gcs_version_prerelease_rev" ]]; then
650-
greater=false
672+
elif [[ $publish_file =~ ^release && \
673+
"$version_prerelease_rev" -le "$gcs_version_prerelease_rev" ]] ||\
674+
[[ $publish_file =~ ^ci && \
675+
"$version_prerelease_rev" -lt "$gcs_version_prerelease_rev" ]]; then
676+
greater=0
677+
elif [[ "$version_prerelease_rev" -gt "$gcs_version_prerelease_rev" ]]; then
678+
: # fall out
679+
# If either version_commits is empty, it will be considered less-than, as
680+
# expected, (e.g. 1.2.3-beta < 1.2.3-beta.1).
681+
elif [[ "$version_commits" -lt "$gcs_version_commits" ]]; then
682+
greater=0
651683
fi
652684

653-
if $greater; then
685+
if ((greater)); then
654686
logecho -r "$OK"
655687
logecho "* $version > $gcs_version (published), updating"
656688
else
@@ -668,16 +700,15 @@ release::gcs::verify_release_gt() {
668700

669701

670702
###############################################################################
671-
# Publish a release to GCS: upload a version file, if KUBE_GCS_MAKE_PUBLIC,
703+
# Publish a release to GCS: upload a version file, if --nomock,
672704
# make it public, and verify the result.
673-
# TODO: There is a version of this in kubernetes/build/common.sh that is also
674-
# used by kube::release::gcs::publish_ci(). Possible refactor.
675705
# @param publish_file - the GCS location to look in
676706
# @param build_output - build output directory
677707
# @param bucket - GS bucket
678708
# @param version - release version
709+
# @optparam bucket_mirror - (optional) mirror GS bucket
679710
# @return 1 on failure
680-
release::gcs::publish() {
711+
release::gcs::publish () {
681712
local publish_file=$1
682713
local build_output=$2
683714
local bucket=$3

0 commit comments

Comments
 (0)