Skip to content

Instantly share code, notes, and snippets.

@reillo
Created October 7, 2017 06:01
Show Gist options
  • Save reillo/ec9c76a90d9127a29755cf6a21d58f55 to your computer and use it in GitHub Desktop.
Save reillo/ec9c76a90d9127a29755cf6a21d58f55 to your computer and use it in GitHub Desktop.
deploy.sh (Magento)
#!/usr/bin/env bash
## author: reillo <[email protected]>
## add to .gitignore deployment_log
## description: purpose of this is to update the development or live server with belmont packages.
## > bash ./deploy.sh Deploy project to develop without composer update
## > bash ./deploy.sh -l Deploy project to live!.
## configuration
devDomain=mage.lmweb.com.au
devBranch=master
devTargetPath=/home/magelm17/public_html
devRemoteUser=magelm17
devPort=9384
liveDomain=54.153.232.117
liveBranch=master
liveTargetPath=/home/magelane/public_html
liveRemoteUser=magelane
livePort=22
## 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 :l option; do
case ${option} in
l) domain=${liveDomain}; branch=${liveBranch}; targetPath=${liveTargetPath}; port=${livePort}; remoteUser=${liveRemoteUser};;
esac
done
# push current git master to repo
git push ${repo} ${branch}
ssh -p ${port} ${remoteUser}@${domain} /bin/bash << EOF
cd ${targetPath} || exit
## fecth repo
umask 022
unset GIT_DIR
git fetch ${repo} ${branch}
git ${merging} ${repo}/${branch}
## clear flush (optional)
#n98-magerun.phar config:set magelane_magelane/browser_cache $(date +"%s")
n98-magerun.phar cache:flush
n98-magerun.phar media:cache:jscss:clear
## 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