From 6e10ea45d13c0e8224d85ab859633c026c2785d5 Mon Sep 17 00:00:00 2001 From: Roger Cundiff Date: Thu, 16 Apr 2020 16:14:54 -0500 Subject: [PATCH 1/5] Inital release scripts --- pushKAppNavToDockerHub.sh | 14 ++++---- release.sh | 57 +++++++++++++++++++++++++++++++ tag.sh | 70 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 6 deletions(-) create mode 100755 release.sh create mode 100755 tag.sh diff --git a/pushKAppNavToDockerHub.sh b/pushKAppNavToDockerHub.sh index 7dcfe81..1f91280 100755 --- a/pushKAppNavToDockerHub.sh +++ b/pushKAppNavToDockerHub.sh @@ -36,7 +36,7 @@ if [ x$1 == x'--?' ] || [ x$1 == x'-?' ]; then fi if [ x$image == x ]; then - . ./projectList.sh + . ./projectList.sh imagelist=$IMAGES else imagelist=$image @@ -48,13 +48,15 @@ docker login docker.io . ./version.sh tag=$VERSION -echo Proceed with tagging kappnav images as $tag and pushing to docker.io/kappnav? -select response in "Yes" "No"; do +if [ x$2 != x"--noprompt" ]; then + echo Proceed with tagging kappnav images as $tag and pushing to docker.io/kappnav? + select response in "Yes" "No"; do case $response in - Yes ) break;; - No ) exit 1;; + Yes ) break;; + No ) exit 1;; esac -done + done +fi for image in $imagelist; do echo docker tag kappnav-$image docker.io/kappnav/$image:$tag diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..bdc51f5 --- /dev/null +++ b/release.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +#***************************************************************** +#* +#* Copyright 2020 IBM Corporation +#* +#* 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, +#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#* See the License for the specific language governing permissions and +#* limitations under the License. +#* +#***************************************************************** +# Create a new release of kAppNav + +# make sure we're running in the build directory +if [ $(echo $PWD | awk '{ n=split($0,d,"/"); print d[n] }') != 'build' ]; then + echo 'Error: $kappnav/build dir must be current dir.' + echo '' + arg="--?" +fi + +# make sure prereqs are satisfied +. ./version.sh +echo "Before running this command you must have done the following." +echo " 1) Checkout the branch on which to create the release for each repository," +echo " or the commit if not HEAD" +echo " 2) Build and test with setupKAppNavTestEnv.sh" +echo " 3) Ensure version.sh contains the correct version number" +echo " 4) If any repository is at a commit other than HEAD you must create" +echo " the release tag. For example:" +echo " git tag -a v0.8.0 \"Version 0.8.0\" 7ee0895" +echo +echo "Are you ready to create kAppNav version $VERSION?" +select response in "Yes" "No"; do + case $response in + Yes ) break;; + No ) exit 1;; + esac +done + +# because we use version numbers as image tags the operator project needs to be +# updated for each release +./updateOperatorForNewRelease.sh + +# create the release tag in each repository +TAG=$VERSION +TAG_MSG="Version "$VERSION +./tag.sh $TAG \"$TAG_MSG\" + +# publish kAppNav images to Docker Hub +./pushKAppNavToDockerHub.sh --noprompt diff --git a/tag.sh b/tag.sh new file mode 100755 index 0000000..672c863 --- /dev/null +++ b/tag.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +#***************************************************************** +#* +#* Copyright 2020 IBM Corporation +#* +#* 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, +#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#* See the License for the specific language governing permissions and +#* limitations under the License. +#* +#***************************************************************** +# does git tag on all projects with releases + +tagName=$1 +tagMessage=$2 + +# make sure running in build directory +if [ $(echo $PWD | awk '{ n=split($0,d,"/"); print d[n] }') != 'build' ]; then + echo 'Error: $kappnav/build dir must be current dir.' + echo + arg="--?" +fi + +# check arguments and print help message if needed +if [ x$tagName == x'--?' ] || [ x$tagName == x'-?' ] || [ x$tagName == 'x' ] || [ ${#tagMessage} == 0 ]; then + echo Create an annotated tag in all kAppNav projects. + echo + echo syntax: + echo + echo "tag.sh \"\"" + echo + echo "An example of the pattern to follow: ./tag.sh v0.8.0 \"Version 0.8.0\"" + exit 0 +fi + +# check if any repositories need special handlinng +echo "If any repositories need to tag a commit other than HEAD you must manually" +echo "do so before running this command. For example:" +echo " git tag -a v0.8.0 \"Version 0.8.0\" 7ee0895" +echo +echo "Do you need to quit and create a tag manually?" +select response in "Yes" "No"; do + case $response in + Yes ) exit 1;; + No ) break;; + esac +done + +# create tags and push to origin +. ./projectList.sh +for p in $ALL_PROJECTS; do + if [ -d ../$p ]; then + cd ../$p + echo Tagging $p repository + git tag -a $tagName -m \"$tagMessage\" + if [ $? -eq 0 ]; then + git push origin $tagName + fi + fi +done + +# go back to original directory +cd ../build From d55c386bcbfa7a82a05856e1e8e806347ae104de Mon Sep 17 00:00:00 2001 From: Roger Cundiff Date: Fri, 17 Apr 2020 15:14:04 -0500 Subject: [PATCH 2/5] Initial drop of updateOperatorForNewRelease.sh --- updateOperatorForNewRelease.sh | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 updateOperatorForNewRelease.sh diff --git a/updateOperatorForNewRelease.sh b/updateOperatorForNewRelease.sh new file mode 100755 index 0000000..95b98b0 --- /dev/null +++ b/updateOperatorForNewRelease.sh @@ -0,0 +1,36 @@ +#!/bin/bash +#***************************************************************** +#* +#* Copyright 2020 IBM Corporation +#* +#* 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, +#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#* See the License for the specific language governing permissions and +#* limitations under the License. +#* +#***************************************************************** +# Update operator to create a new releases dir and make the new release the lastest release +cd ../operator +git checkout master +git pull +git checkout -b updateOperatorForNewRelease +. ./version.sh +newdir="releases/$VERSION" +mkdir $newdir +cp kappnav.yaml kappnav-delete.yaml kappnav-delete-CR.yaml $newdir +cp -r $newdir releases/lastest +git add . +git commit -m "Update release names in operator yaml files" +git push origin updateOperatorForNewRelease +echo "Create a pull request for branch updateOperatorForNewRelease and merge it" +echo "to master." +read -p "Press enter/return after you have merged to master..." wait + +# back to where we started +cd - From af619015688469a61c42cefd44e35a9eb12e639a Mon Sep 17 00:00:00 2001 From: Roger Cundiff Date: Sat, 18 Apr 2020 00:16:56 -0500 Subject: [PATCH 3/5] Initial drop of buildLatest.sh --- buildLatest.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 buildLatest.sh diff --git a/buildLatest.sh b/buildLatest.sh new file mode 100755 index 0000000..bfd0ec5 --- /dev/null +++ b/buildLatest.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +#***************************************************************** +#* +#* Copyright 2020 IBM Corporation +#* +#* 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, +#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#* See the License for the specific language governing permissions and +#* limitations under the License. +#* +#***************************************************************** +# Perform a build, install, and test of the latest commit in each repository +arg=$1 + +# make sure we're running in the build directory +if [ $(echo $PWD | awk '{ n=split($0,d,"/"); print d[n] }') != 'build' ]; then + echo 'Error: $kappnav/build dir must be current dir.' + echo '' + arg="--?" +fi + +if [ x$arg == x'--?' ] || [ x$arg == x'-?' ]; then + echo "Build the latest kAppNav, install it and run the tests." + echo "" + echo "" + echo "syntax:" + echo "" + echo "buildLatest.sh" + echo "" + echo "This script uses the following environment variables." + echo " $CLUSTER_URL - the URL to your OpenShift cluster" + echo " $CLUSTER_USER - the user name for logging into your cluster; default is" + echo " kubeadmin" + echo " $CLUSTER_PWD - the password for logging into your cluster" + echo " $DOCKER_ORG - the Docker org to publish to and pull from" + echo "" + echo " The script will prompt for values for any missing environments variables" + echo " that don't have a default" + exit 1 +fi + +# clean up our docker registry so we have enough space +echo "pruning Docker registry of dangling images" +# docker image prune + +# make sure all of the repositories are up-to-date +. ./projectList.sh +for p in $BUILD_PROJECTS; do + echo "build $p" + # cd ../$p ; git checkout master; git pull; cd - +done + +# build, publish images, install, and test +if [ x$CLUSTER_URL != x ]; then + url=$CLUSTER_URL +else + read -p "Enter your cluster url: " url +fi +if [ x$CLUSTER_USER != x ]; then + user=$CLUSTER_USER +else + user=kubeadmin +fi +if [ x$CLUSTER_PWD != x ]; then + pwd=$CLUSTER_PWD +else + read -p "Enter your cluster password: " url +fi +if [ x$DOCKER_ORG != x ]; then + org=$DOCKER_ORG +else + read -p "Enter the Docker org to use: " org +fi + + +echo ./setupKAppNavTestEnv.sh $url $user $pwd ocp $org -p From cfb779d3b9edda8b6d223589d3a731c2c5d0464b Mon Sep 17 00:00:00 2001 From: Roger Cundiff Date: Mon, 20 Apr 2020 11:02:44 -0500 Subject: [PATCH 4/5] Build only updated repos --- buildLatest.sh | 79 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 20 deletions(-) diff --git a/buildLatest.sh b/buildLatest.sh index bfd0ec5..dcd045a 100755 --- a/buildLatest.sh +++ b/buildLatest.sh @@ -1,5 +1,4 @@ #!/bin/bash - #***************************************************************** #* #* Copyright 2020 IBM Corporation @@ -17,6 +16,17 @@ #* #***************************************************************** # Perform a build, install, and test of the latest commit in each repository + +# function for converting repo name to image name +getImageName() { + dirName=$1 + if [ $dirName == 'inventory' ]; then + imageName=kappnav-inv + else + imageName=kappnav-$dirName + fi +} + arg=$1 # make sure we're running in the build directory @@ -26,38 +36,63 @@ if [ $(echo $PWD | awk '{ n=split($0,d,"/"); print d[n] }') != 'build' ]; then arg="--?" fi +# print help if we need to if [ x$arg == x'--?' ] || [ x$arg == x'-?' ]; then - echo "Build the latest kAppNav, install it and run the tests." - echo "" - echo "" - echo "syntax:" - echo "" - echo "buildLatest.sh" + echo "" + echo "Build the latest kAppNav, install it and run the tests. Note that the" + echo "repositories will be left in the master branch." + echo "" + echo "" + echo "syntax:" + echo "" + echo "buildLatest.sh" echo "" echo "This script uses the following environment variables." - echo " $CLUSTER_URL - the URL to your OpenShift cluster" - echo " $CLUSTER_USER - the user name for logging into your cluster; default is" - echo " kubeadmin" - echo " $CLUSTER_PWD - the password for logging into your cluster" - echo " $DOCKER_ORG - the Docker org to publish to and pull from" + echo " \$CLUSTER_URL - the URL to your OpenShift cluster" + echo " \$CLUSTER_USER - the user name for logging into your cluster; default is" + echo " is kubeadmin" + echo " \$CLUSTER_PWD - the password for logging into your cluster" + echo " \$CLUSTER_PLATFORM - the platform type of your cluster; default is ocp" + echo " \$DOCKER_ORG - the Docker org to publish to and pull from" echo "" echo " The script will prompt for values for any missing environments variables" echo " that don't have a default" - exit 1 + exit 1 fi # clean up our docker registry so we have enough space +# automatically answer 'y' to the prune prompt echo "pruning Docker registry of dangling images" -# docker image prune +echo "y\n" | docker image prune -# make sure all of the repositories are up-to-date +# make sure all of the repositories are up to date +# then rebuild any images that are out of date +builtSomething="false" . ./projectList.sh for p in $BUILD_PROJECTS; do - echo "build $p" - # cd ../$p ; git checkout master; git pull; cd - + echo "" + echo "***** build $p" + cd ../$p ; git checkout master; git pull + commit=$(git rev-parse HEAD) + getImageName $p + docker image inspect $imageName | grep $commit + if [ $? -eq 0 ]; then + echo "$imageName is already current." + else + echo "building $imageName" + ./build.sh + builtSomething="true" + fi + cd - done -# build, publish images, install, and test +# if nothing was built then there's nothing else to do +if [ $builtSomething == "false" ]; then + echo "All repositories are up to date. No need to install and test." + exit +fi + +# publish images, install, and test if [ x$CLUSTER_URL != x ]; then url=$CLUSTER_URL else @@ -73,11 +108,15 @@ if [ x$CLUSTER_PWD != x ]; then else read -p "Enter your cluster password: " url fi +if [ x$CLUSTER_PLATFORM != x ]; then + platform=$CLUSTER_PLATFORM +else + platform=ocp +fi if [ x$DOCKER_ORG != x ]; then org=$DOCKER_ORG else read -p "Enter the Docker org to use: " org fi - -echo ./setupKAppNavTestEnv.sh $url $user $pwd ocp $org -p +./setupKAppNavTestEnv.sh $url $user $pwd $platform $org -p From 341fd182c05e3f5803d180fc3140a168fc61e67a Mon Sep 17 00:00:00 2001 From: Roger Cundiff Date: Mon, 20 Apr 2020 11:05:35 -0500 Subject: [PATCH 5/5] add more comments --- tag.sh | 2 -- updateOperatorForNewRelease.sh | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tag.sh b/tag.sh index 672c863..dd44034 100755 --- a/tag.sh +++ b/tag.sh @@ -1,5 +1,4 @@ #!/bin/bash - #***************************************************************** #* #* Copyright 2020 IBM Corporation @@ -17,7 +16,6 @@ #* #***************************************************************** # does git tag on all projects with releases - tagName=$1 tagMessage=$2 diff --git a/updateOperatorForNewRelease.sh b/updateOperatorForNewRelease.sh index 95b98b0..9b42432 100755 --- a/updateOperatorForNewRelease.sh +++ b/updateOperatorForNewRelease.sh @@ -16,15 +16,21 @@ #* #***************************************************************** # Update operator to create a new releases dir and make the new release the lastest release + +# create the branch for the update cd ../operator git checkout master git pull git checkout -b updateOperatorForNewRelease + +# create a dir for the new release and update the contents of the latest dir . ./version.sh newdir="releases/$VERSION" mkdir $newdir cp kappnav.yaml kappnav-delete.yaml kappnav-delete-CR.yaml $newdir cp -r $newdir releases/lastest + +# update operator origin git add . git commit -m "Update release names in operator yaml files" git push origin updateOperatorForNewRelease