Codementor Events

Script to build angular website.

Published Feb 25, 2020

This is the Script i used in deploying an angulat website.
The deployment will create a QA instance.
In this script, note that the prodution urls to the python apis are being replaced with the QA versions of the API.

Also note that, we are using docker to containorize the Website.
If the build is successful, we are stopping any currently running docker container and then running the new docker container.

if [$# -gt 0]
then
#echo "$# Arguments passed.. : " $*
branchtobuild=$1
else
#echo "NO Arguments have been passed.. "
branchtobuild="master"
fi
WRKDIR=/home/rajaram_class_gmail_com/jenkinswrkdir
cd $WRKDIR
name=$(date '+%Y%m%d_%H%M%S');echo $name
Check if the needed directories exist
[-d stage01] || echo "stage01"
[-d stage02] || echo "stage02"
cd $WRKDIR/stage01
git init
git pull https://<userid>:<password>@bitbucket.org/<bitbucketid>/repo01.git repo01pdc
git clone -b $branchtobuild --single-branch https://<userid>:<password>@bitbucket.org/<bitbucketid>/repo01.git
cp -R repo01/repo01Web/* $WRKDIR/stage02
cd $WRKDIR/stage02
cp $WRKDIR/Dockerfile .
#
Change the code so that the call will go to the new qa server..
#
# sed 's/repo01.net\/services/repo01qa.hopto.org/g' $WRKDIR/stage01/repo01/repo01Web/src/app/components/api/config.ts > $WRKDIR/stage02/src/app/components/api/config.ts
ls $WRKDIR/stage02/src/app/service/rest.service.ts
sed 's/repo01.net\/services/repo01qa.hopto.org/g' $WRKDIR/stage01/repo01/repo01Web/src/app/service/rest.service.ts > $WRKDIR/stage02/src/app/service/rest.service.ts
yes | rm -r $WRKDIR/stage01/repo01
docker build -t repo01qadocimg_$name . -f Dockerfile
retcode=$?
if [$retcode -eq 0]
then
#
# stop any running containers..
#
for cont in docker container ls --format " {{.Names}}"
do
  if [$cont == "repo01qa-"]; then
    #echo $cont
    docker stop $cont
  fi
done
# Now run the docker image we just now built.
docker run --name repo01qa-$name -d -p 80:80 repo01qadocimg_$name
# why did we remove e9bca15b1bd0? its sonarqube container.
docker ps -q |grep -v e9bca15b1bd0 > /home/rajaram_class_gmail_com/jenkinswrkdir/gooddockerimage.txt
else
echo "Sorry Build failed.. please check the error logs 😦 "
fi
Discover and read more posts from Rajaram K
get started
post commentsBe the first to share your opinion
Show more replies