Created
September 21, 2017 20:16
-
-
Save shreyb/13f50e0529c6c1c75c3ea6c8b96a1cac to your computer and use it in GitHub Desktop.
Script to rebuild all GRACC reporting images where dockerfiles live
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script is to rebuild all the images (assuming no version bump) with a new RPM. This is useful, for example, if there's a minor bug found in testing. We can rebuild all the Docker images and push them automatically | |
# The script also commits the changed rpm to the git repo master branch | |
# Constants | |
DOCKERDIR=${HOME}/Project/email_reports-docker | |
RPMDIR=${HOME}/RPMDocker/rpm_out | |
BASEDIR=${DOCKERDIR}/base | |
FIFEBASEDIR=${DOCKERDIR}/fife | |
FIFEREPORTDIRS="efficiencyreport jobsuccessratereport minervareport" | |
OSGDIR=${DOCKERDIR}/osg-reports | |
OSGBASEDIR=${OSGDIR}/osg | |
OSGREPORTDIRS="osgflockingreport osgmissingprojectsreport osgpersitereport osgprobereport osgreport osgtopoppusagereport" | |
failedreport=() | |
# Functions | |
function usage { | |
echo " rebuild_all_images.sh [-a]" | |
echo " -a Rebuild OSG report images as well as FIFE images" | |
exit 0 | |
} | |
function gitcommit { | |
# Git commit new tarball | |
git add ${BASEDIR}/${baserpmname} | |
git commit -m 'New tarball in base image' | |
echo "Commited new tarball to git" | |
} | |
function errorexit { | |
# Aborts program if return code is not 0 | |
if [[ $1 -ne 0 ]]; | |
then | |
echo "Some error! Look at the stdout above" | |
exit 1 | |
fi; | |
} | |
function catcherror { | |
# Continues if return code is not 0 | |
if [[ $1 -ne 0 ]]; | |
then | |
echo "Some error! Will continue" | |
failedreport+=($2) | |
continue | |
fi; | |
} | |
# Main | |
# Setup | |
if [[ $# -gt 1 ]]; | |
then | |
usage | |
fi | |
case $1 in | |
"-a") | |
OSGPUSH=1 | |
;; | |
"") | |
OSGPUSH=0 | |
;; | |
*) | |
usage | |
;; | |
esac | |
# Find RPM and copy it into place | |
baserpm=`ls -1t ${RPMDIR}/*.rpm | head -n 1` | |
errorexit $? | |
baserpmname=`basename $baserpm` | |
cp $baserpm ${BASEDIR}/ | |
# Switch to base dir and rebuild/push base | |
cd $BASEDIR && latestbaseimage=`docker images shreyb/gracc-reporting:base* --format "{{.Repository}}:{{.Tag}}\t{{.CreatedAt}}" | sort -k 2 -r | awk '{print $1}' | head -n 1` | |
errorexit $? | |
echo "" | |
echo "The latest base image is $latestbaseimage" | |
docker build . -t $latestbaseimage && docker push $latestbaseimage | |
errorexit $? | |
echo "Rebuilt and pushed latest base image to DockerHub" | |
# Rebuild/push FIFE image | |
cd $FIFEBASEDIR && fifeimage=`docker images shreyb/gracc-reporting:fife* --format "{{.Repository}}:{{.Tag}}\t{{.CreatedAt}}" | sort -k 2 -r | awk '{print $1}' | head -n 1` | |
errorexit $? | |
echo "" | |
echo "The latest fife image is $fifeimage" | |
docker build . -t $fifeimage && docker push $fifeimage | |
errorexit $? | |
# Rebuild/push FIFE Report Images | |
echo "" | |
echo "" | |
echo "FIFE reports" | |
for dir in $FIFEREPORTDIRS; | |
do | |
cd ${DOCKERDIR}/${dir} && imagesearch=`echo "${dir%*report}-report*"` | |
catcherror $? $dir | |
repimage=`docker images shreyb/gracc-reporting:${imagesearch} --format "{{.Repository}}:{{.Tag}}\t{{.CreatedAt}}" | sort -k 2 -r | awk '{print $1}' | head -n 1` | |
if [[ -z "${repimage// }" ]] | |
then | |
echo "No such matching image" | |
catcherror 1 $dir | |
fi; | |
echo "" | |
echo "The latest $dir image is $repimage" | |
docker build . -t $repimage && docker push $repimage | |
catcherror $? $dir | |
done; | |
echo "" | |
echo "FIFE Reports Finished" | |
if [[ $OSGPUSH -ne 1 ]]; | |
then | |
gitcommit | |
errorexit $? | |
echo "Failed Reports: ${failedreport[@]}" | |
echo "All done" | |
exit 0 | |
fi; | |
# Rebuild/push OSG Base Image | |
cd $OSGBASEDIR && osgbaseimage=`docker images shreyb/gracc-reporting:osg_* --format "{{.Repository}}:{{.Tag}}\t{{.CreatedAt}}" | sort -k 2 -r | awk '{print $1}' | head -n 1` | |
errorexit $? | |
echo "" | |
echo "The latest osg image is $osgbaseimage" | |
docker build . -t $osgbaseimage && docker push $osgbaseimage | |
errorexit $? | |
# Rebuild/push OSG Report Images | |
echo "" | |
echo "" | |
echo "OSG reports" | |
for dir in $OSGREPORTDIRS; | |
do | |
cd ${OSGDIR}/${dir} && imagesearch=`echo "${dir%*report}-report*"` | |
catcherror $? $dir | |
repimage=`docker images shreyb/gracc-reporting:${imagesearch} --format "{{.Repository}}:{{.Tag}}\t{{.CreatedAt}}" | sort -k 2 -r | awk '{print $1}' | head -n 1` | |
if [[ -z "${repimage// }" ]] | |
then | |
echo "No such matching image" | |
catcherror 1 $dir | |
fi; | |
echo "" | |
echo "The latest $dir image is $repimage" | |
docker build . -t $repimage && docker push $repimage | |
catcherror $? $dir | |
done; | |
echo "OSG Reports finished" | |
gitcommit | |
errorexit $? | |
echo "Failed Reports: ${failedreport[@]}" | |
echo "All done" | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment