Skip to content

Instantly share code, notes, and snippets.

@reillo
Created August 4, 2016 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reillo/a123b7199900969675bf74975d2eef74 to your computer and use it in GitHub Desktop.
Save reillo/a123b7199900969675bf74975d2eef74 to your computer and use it in GitHub Desktop.
Deploy git to live or dev server
#!/usr/bin/env bash
## author: reillo <atilloregner@gmail.com>
## add to .gitignore deployment_log
## description: purpose of this is to update the development or live server with using git and packages.
## > bash ./deploy.sh Deploy project to develop without composer update
## > bash ./deploy.sh -l Deploy project to live!.
## > bash ./deploy.sh -u package/name Deploy to develop and update package name
## > bash ./deploy.sh -l -u package/name Deploy to live and update package name
## configuration
devDomain=dev.sample.com
devBranch=develop
devTargetPath=/usr/share/nginx/mage_dev
devRemoteUser=dev
devPort=22
liveDomain=sample.com
liveBranch=master
liveTargetPath=/usr/share/nginx/mage
liveRemoteUser=trex
livePort=22
## other
composerUpdate=
## git merging information
repo=origin
merging="merge" ### "merge" or "reset --hard"
## deployer information
vhostname=$(hostname)
vuser=$USER
# flags,
domain=${devDomain}
branch=${devBranch}
targetPath=${devTargetPath}
remoteUser=${devRemoteUser}
port=${devPort}
## -l - deploy to live
## -u [package/name] - execute composer update
while getopts :lu: option; do
case ${option} in
l) domain=${liveDomain}; branch=${liveBranch}; targetPath=${liveTargetPath}; remoteUser=${liveRemoteUser}; port=${livePort};;
u) composerUpdate="composer update "$OPTARG;;
esac
done
## Debugging
#echo $domain;
#echo $branch;
#echo $targetPath;
#echo $remoteUser;
#exit
## push current git master to repo
git push ${repo} ${branch}
ssh ${remoteUser}@${domain} -p ${port} /bin/bash << EOF
cd ${targetPath} || exit
## fecth repo
umask 022
unset GIT_DIR
git fetch ${repo} ${branch}
git stash save "stash-backup-\$(date +"%Y-%m-%d")"
git ${merging} ${repo}/${branch}
## clear flush (optional)
#${composerUpdate}
#modman deploy app_magentotheme --force
#modman deploy app_rewrite --force
#n98-magerun.phar cache:flush
## log last deploy
touch deployment_log
logContent="${vuser}@${vhostname} : Last Deployed \$(date +"%Y-%m-%d")"
echo \${logContent} >> "deployment_log"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment