Skip to content

Instantly share code, notes, and snippets.

@vinayakg
Created July 19, 2020 09:00
Show Gist options
  • Save vinayakg/b20ac4b67e3ba3f196ed86c1fc18d470 to your computer and use it in GitHub Desktop.
Save vinayakg/b20ac4b67e3ba3f196ed86c1fc18d470 to your computer and use it in GitHub Desktop.
Script for deployment - with git export implemented
#!/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