Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #25 from kappnav/releaseScripts
Browse files Browse the repository at this point in the history
Release scripts
  • Loading branch information
rlcundiff authored Apr 20, 2020
2 parents 7674b13 + 341fd18 commit d0f0eff
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 6 deletions.
122 changes: 122 additions & 0 deletions buildLatest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/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

# 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
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

# print help if we need to
if [ x$arg == x'--?' ] || [ x$arg == x'-?' ]; then
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 " 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
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"
echo "y\n" | docker image prune

# 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 ""
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

# 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
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$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

./setupKAppNavTestEnv.sh $url $user $pwd $platform $org -p
14 changes: 8 additions & 6 deletions pushKAppNavToDockerHub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
57 changes: 57 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/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 <tagName> \"<tagMessage>\""
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
42 changes: 42 additions & 0 deletions updateOperatorForNewRelease.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/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

# 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
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 -

0 comments on commit d0f0eff

Please sign in to comment.