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

Skip to content

Commit 3430c8a

Browse files
committed
Move push-ci-build.sh functionality to release repo.
1 parent f7a4bfb commit 3430c8a

5 files changed

Lines changed: 270 additions & 55 deletions

File tree

README-CI.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Continuous Integration How-to
2+
3+
## Before
4+
5+
* Currently called from hack/jenkins/build.sh
6+
7+
```
8+
$ build/push-ci-build.sh
9+
```
10+
11+
## After
12+
13+
```
14+
$ git clone https://github.com/kubernetes/release
15+
$ RELEASE_INFRA=$PWD/release
16+
$ cd /kubernetes/root/dir && make quick-release
17+
$ $RELEASE_INFRA/push-ci-build.sh --nomock [--federation]
18+
```

anago

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -918,17 +918,21 @@ for label in ${!RELEASE_VERSION[@]}; do
918918
common::stepheader "PUSH ${RELEASE_VERSION[$label]} IMAGES"
919919
##############################################################################
920920
common::runstep release::gcs::copy_release_artifacts \
921-
${RELEASE_VERSION[$label]} \
922-
$BUILD_OUTPUT-${RELEASE_VERSION[$label]} $RELEASE_BUCKET \
921+
release/${RELEASE_VERSION[$label]} \
922+
$BUILD_OUTPUT-${RELEASE_VERSION[$label]} \
923+
$RELEASE_BUCKET \
923924
|| common::exit 1 "Exiting..."
924925

925926
common::runstep release::docker::release \
926-
$KUBE_DOCKER_REGISTRY ${RELEASE_VERSION[$label]} \
927+
$KUBE_DOCKER_REGISTRY \
928+
${RELEASE_VERSION[$label]} \
927929
|| common::exit 1 "Exiting..."
928930

929-
common::runstep release::gcs::publish_official \
931+
common::runstep release::gcs::publish_version \
932+
release \
930933
${RELEASE_VERSION[$label]} \
931-
$BUILD_OUTPUT-${RELEASE_VERSION[$label]} $RELEASE_BUCKET \
934+
$BUILD_OUTPUT-${RELEASE_VERSION[$label]} \
935+
$RELEASE_BUCKET \
932936
|| common::exit 1 "Exiting..."
933937
done
934938

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: 79 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ release::set_build_version () {
198198
return 1
199199
else
200200
logecho
201-
logecho "Bad build version!"
201+
logecho "Bad build version: $build_version"
202202
return 1
203203
fi
204204

@@ -433,24 +433,25 @@ release::gcs::stage_and_hash() {
433433

434434
###############################################################################
435435
# Copy the release artifacts to staging and push them up to GS
436-
# TODO: There is a version of this in kubernetes/build/common.sh that is also
437-
# used by the build/push-*-build.sh scripts. Refactor.
438-
# @param version - release version
436+
# @param target_version - something like release/<version>
439437
# @param build_output - build output directory
440438
# @param bucket - GS bucket
439+
# @optparam bucket_mirror - (optional) mirror GS bucket
441440
# @return 1 on failure
442441
release::gcs::copy_release_artifacts() {
443-
local version=$1
442+
local target_version=$1
444443
local build_output=$2
445444
local bucket=$3
445+
local bucket_mirror=$4
446446
local platform
447447
local platforms
448448
local release_stage=$build_output/release-stage
449449
local release_tars=$build_output/release-tars
450450
local gcs_stage=$build_output/gcs-stage
451451
local src
452452
local dst
453-
local gcs_destination=gs://$bucket/release/$version/
453+
local gcs_destination=gs://$bucket/$target_version
454+
local gcs_mirror=gs://$bucket_mirror/$target_version
454455
local gce_path=$release_stage/full/kubernetes/cluster/gce
455456
local gci_path
456457

@@ -500,45 +501,60 @@ release::gcs::copy_release_artifacts() {
500501
common::sha1 $path > "$path.sha1" || return 1
501502
done
502503

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

506-
# TODO(jbeda): Generate an HTML page with links for this release so it is easy
507-
# to see it. For extra credit, generate a dynamic page that builds up the
508-
# release list using the GCS JSON API. Use Angular and Bootstrap for extra
509-
# extra credit.
510-
511508
logecho -n "- Marking all uploaded objects public: "
512509
logrun -s $LOGRUN_MOCK $GSUTIL -q -m acl ch -R -g all:R \
513-
"$gcs_destination" || return 1
510+
"$gcs_destination" || return 1
514511

515512
logecho -n "- Listing final contents to log file: "
516513
logrun -s $GSUTIL ls -lhr "$gcs_destination" || return 1
514+
515+
# Push to mirror if set
516+
if [[ -n "$bucket_mirror" && "$bucket" != "$bucket_mirror" ]]; then
517+
logecho -n "- Mirroring build to $gcs_mirror: "
518+
logrun -s $GSUTIL -q -m rsync -d -r "$gcs_destination" "$gcs_mirror" \
519+
|| return 1
520+
logecho -n "- Marking all uploaded mirror objects public: "
521+
logrun -s $LOGRUN_MOCK $GSUTIL -q -m acl ch -R -g all:R \
522+
"$gcs_mirror" || return 1
523+
fi
517524
}
518525

519526

520527
###############################################################################
521-
# Publish a new official version, (latest or stable,) but only if the release
522-
# files actually exist on GCS and the release we're dealing with is newer than
523-
# the contents in GCS.
524-
# @param version - release version
528+
# Publish a new version, (latest or stable,) but only if the
529+
# files actually exist on GCS and the artifacts we're dealing with are newer
530+
# than the contents in GCS.
531+
# @param build_type - One of 'release' or 'ci'
532+
# @param version - The version
525533
# @param build_output - build output directory
526534
# @param bucket - GS bucket
535+
# @optparam bucket_mirror - GS mirror bucket
527536
# @return 1 on failure
528-
release::gcs::publish_official () {
529-
local version=$1
530-
local build_output=$2
531-
local bucket=$3
532-
local release_dir="gs://$bucket/release/$version"
537+
release::gcs::publish_version () {
538+
local build_type=$1
539+
local version=$2
540+
local build_output=$3
541+
local bucket=$4
542+
local bucket_mirror=$5
543+
local release_dir="gs://$bucket/$build_type/$version"
533544
local version_major
534545
local version_minor
535546
local publish_file
536-
local publish_files
547+
local -a publish_files
548+
local -a publish_buckets=($bucket)
537549
local type="latest"
538-
[[ "$version" =~ alpha|beta ]] || type="stable"
539550

540-
logecho
541-
logecho "Publish official pointer text files to $bucket..."
551+
# Ensure no duplicate
552+
[[ "$bucket" != "$bucket_mirror" ]] && publish_buckets+=($bucket_mirror)
553+
554+
# For release/ targets, type could be 'stable'
555+
if [[ "$build_type" == release ]]; then
556+
[[ "$version" =~ alpha|beta ]] || type="stable"
557+
fi
542558

543559
if ! $GSUTIL ls $release_dir >/dev/null 2>&1 ; then
544560
logecho "Release files don't exist at $release_dir"
@@ -555,13 +571,18 @@ release::gcs::publish_official () {
555571
$type-$version_major.$version_minor
556572
)
557573

558-
for publish_file in ${publish_files[@]}; do
559-
# If there's a version that's above the one we're trying to release, don't
560-
# do anything, and just try the next one.
561-
release::gcs::verify_release_gt release/$publish_file.txt \
562-
$bucket $version || continue
563-
release::gcs::publish release/$publish_file.txt $build_output \
564-
$bucket $version || return 1
574+
for b in ${publish_buckets[*]}; do
575+
logecho
576+
logecho "Publish official pointer text files to $b..."
577+
578+
for publish_file in ${publish_files[@]}; do
579+
# If there's a version that's above the one we're trying to release, don't
580+
# do anything, and just try the next one.
581+
release::gcs::verify_latest_update $build_type/$publish_file.txt \
582+
$b $version || continue
583+
release::gcs::publish $build_type/$publish_file.txt $build_output \
584+
$b $version || return 1
585+
done
565586
done
566587
}
567588

@@ -574,16 +595,16 @@ release::gcs::publish_official () {
574595
# @param version - release version
575596
# @return 1 if new version is not greater than the GCS version
576597
#
577-
release::gcs::verify_release_gt() {
598+
release::gcs::verify_latest_update () {
578599
local -r publish_file=$1
579600
local -r bucket=$2
580601
local -r version=$3
581602
local -r publish_file_dst="gs://$bucket/$publish_file"
582603
local gcs_version
583-
local greater=true
604+
local greater=1
584605

585606
logecho -n "Test $version > $publish_file (published): "
586-
if ! [[ $version =~ ${VER_REGEX[release]} ]]; then
607+
if ! [[ $version =~ ${VER_REGEX[release]}(.${VER_REGEX[build]})* ]]; then
587608
logecho -r "$FAILED"
588609
logecho "* Invalid version format! $version"
589610
return 1
@@ -594,9 +615,10 @@ release::gcs::verify_release_gt() {
594615
local -r version_patch="${BASH_REMATCH[3]}"
595616
local -r version_prerelease="${BASH_REMATCH[4]}"
596617
local -r version_prerelease_rev="${BASH_REMATCH[5]}"
618+
local -r version_commits="${BASH_REMATCH[7]}"
597619

598620
if gcs_version="$($GSUTIL cat $publish_file_dst 2>/dev/null)"; then
599-
if ! [[ $gcs_version =~ ${VER_REGEX[release]} ]]; then
621+
if ! [[ $gcs_version =~ ${VER_REGEX[release]}(.${VER_REGEX[build]})* ]]; then
600622
logecho -r "$FAILED"
601623
logecho "* file contains invalid release version," \
602624
"can't compare: '$gcs_version'"
@@ -608,17 +630,18 @@ release::gcs::verify_release_gt() {
608630
local -r gcs_version_patch="${BASH_REMATCH[3]}"
609631
local -r gcs_version_prerelease="${BASH_REMATCH[4]}"
610632
local -r gcs_version_prerelease_rev="${BASH_REMATCH[5]}"
633+
local -r gcs_version_commits="${BASH_REMATCH[7]}"
611634

612635
if [[ "$version_major" -lt "$gcs_version_major" ]]; then
613-
greater=false
636+
greater=0
614637
elif [[ "$version_major" -gt "$gcs_version_major" ]]; then
615638
: # fall out
616639
elif [[ "$version_minor" -lt "$gcs_version_minor" ]]; then
617-
greater=false
640+
greater=0
618641
elif [[ "$version_minor" -gt "$gcs_version_minor" ]]; then
619642
: # fall out
620643
elif [[ "$version_patch" -lt "$gcs_version_patch" ]]; then
621-
greater=false
644+
greater=0
622645
elif [[ "$version_patch" -gt "$gcs_version_patch" ]]; then
623646
: # fall out
624647
# Use lexicographic (instead of integer) comparison because
@@ -628,19 +651,28 @@ release::gcs::verify_release_gt() {
628651
# We have to do this because lexicographically "beta" > "alpha" > "", but
629652
# we want official > beta > alpha.
630653
elif [[ -n "$version_prerelease" && -z "$gcs_version_prerelease" ]]; then
631-
greater=false
654+
greater=0
632655
elif [[ -z "$version_prerelease" && -n "$gcs_version_prerelease" ]]; then
633656
: # fall out
634657
elif [[ "$version_prerelease" < "$gcs_version_prerelease" ]]; then
635-
greater=false
658+
greater=0
636659
elif [[ "$version_prerelease" > "$gcs_version_prerelease" ]]; then
637660
: # fall out
638661
# Finally resort to -le here, since we want strictly-greater-than.
639-
elif [[ "$version_prerelease_rev" -le "$gcs_version_prerelease_rev" ]]; then
640-
greater=false
662+
elif [[ $publish_file =~ ^release && \
663+
"$version_prerelease_rev" -le "$gcs_version_prerelease_rev" ]] ||\
664+
[[ $publish_file =~ ^ci && \
665+
"$version_prerelease_rev" -lt "$gcs_version_prerelease_rev" ]]; then
666+
greater=0
667+
elif [[ "$version_prerelease_rev" -gt "$gcs_version_prerelease_rev" ]]; then
668+
: # fall out
669+
# If either version_commits is empty, it will be considered less-than, as
670+
# expected, (e.g. 1.2.3-beta < 1.2.3-beta.1).
671+
elif [[ "$version_commits" -lt "$gcs_version_commits" ]]; then
672+
greater=0
641673
fi
642674

643-
if $greater; then
675+
if ((greater)); then
644676
logecho -r "$OK"
645677
logecho "* $version > $gcs_version (published), updating"
646678
else
@@ -658,16 +690,15 @@ release::gcs::verify_release_gt() {
658690

659691

660692
###############################################################################
661-
# Publish a release to GCS: upload a version file, if KUBE_GCS_MAKE_PUBLIC,
693+
# Publish a release to GCS: upload a version file, if --nomock,
662694
# make it public, and verify the result.
663-
# TODO: There is a version of this in kubernetes/build/common.sh that is also
664-
# used by kube::release::gcs::publish_ci(). Possible refactor.
665695
# @param publish_file - the GCS location to look in
666696
# @param build_output - build output directory
667697
# @param bucket - GS bucket
668698
# @param version - release version
699+
# @optparam bucket_mirror - (optional) mirror GS bucket
669700
# @return 1 on failure
670-
release::gcs::publish() {
701+
release::gcs::publish () {
671702
local publish_file=$1
672703
local build_output=$2
673704
local bucket=$3

0 commit comments

Comments
 (0)