Created
July 19, 2020 09:00
-
-
Save vinayakg/b20ac4b67e3ba3f196ed86c1fc18d470 to your computer and use it in GitHub Desktop.
Script for deployment - with git export implemented
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 | |
if [ -z "$1" ] | |
then | |
echo "Usage deploybuild.sh gitreponame branch" | |
exit 0 | |
fi | |
if [ -z "$2" ] | |
then | |
echo "Usage deploybuild.sh gitreponame branch" | |
exit 0 | |
fi | |
projectname=$1 | |
branch=$2 | |
giturl="https://github.com/edu" | |
builddate=$(date '+%Y%m%d%H%M%S') | |
prodhost="10.10.2.205" | |
echo $(pwd) | |
echo $builddate | |
echo "Projectname: $projectname, branch: $branch" | |
if [ ! -d ~/src ] | |
then | |
mkdir -p ~/src | |
fi | |
cd ~/src | |
# clone the required repo | |
rm -rf ~/src/$projectname | |
git clone $giturl/$projectname | |
cd ~/src/$projectname | |
echo "Created a folder with code in it ~src/$projectname" | |
echo $(pwd) | |
exportpath=~/build/$projectname/$builddate | |
if [ ! -d ~/build/$projectname ] | |
then | |
mkdir -p ~/build/$projectname | |
fi | |
cd ~/src/$projectname | |
# archive the repo now | |
mkdir -p $exportpath | |
echo "export path dir is $exportpath/ and pwd: $(pwd)" | |
cmd=$(git archive $branch | tar -x -C $exportpath/) | |
virtualfoldername=$projectname | |
# Change the mapping from git repos to our project conventions | |
case "$projectname" in | |
"ed-html") virtualfoldername="eduhtml" | |
;; | |
"ed-portal") virtualfoldername="eduvanz" | |
;; | |
esac | |
echo $virtualfoldername | |
ssh -i ~/appserver_rsa_prod ubuntu@$prodhost "mkdir -p ~/build/$projectname" | |
scp -rp -i ~/appserver_rsa_prod $exportpath ubuntu@$prodhost:~/build/$projectname/ | |
ssh -i ~/appserver_rsa_prod ubuntu@$prodhost "sudo ln -s ~/build/$projectname/$builddate /var/www/html/$virtualfoldername" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment