Last active
December 12, 2017 17:42
-
-
Save tystr/5769483 to your computer and use it in GitHub Desktop.
Simple bash script to first build then rsync a brunch application to multiple servers
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/bash | |
# This script assumes that you have the deployer ssh key in your home directory | |
# The ./public directory is deployed into the $DEPLOY_TO directory on the remote servers | |
RSYNC=/usr/bin/rsync | |
BRUNCH=/usr/local/bin/brunch | |
PRODUCTION_HOSTNAMES=("host1" "host2") | |
DEPLOY_TO=/var/www/application/current | |
DEPLOYER_SSH_KEY=$HOME/.ssh/id_rsa-deployer | |
LOGFILE=deploy.log | |
echo -n "Warning: This will deploy directly to the production servers. Are you sure? (y/N): " | |
read -t 10 confirm | |
if [ "$confirm" != "y" ]; then | |
echo -e "\nAborting...\n" | |
exit 0 | |
else | |
echo -e "\nDeploying...\n" | |
fi | |
echo "" > $LOGFILE | |
echo -n "Building the brunch application..." | |
echo "Building the brunch application..." >> $LOGFILE | |
$BRUNCH build >> $LOGFILE | |
if [ $? -eq 0 ]; then | |
echo "done." | |
else | |
echo -e "\nAn error occurred when building the application." | |
exit 1 | |
fi | |
echo "Rsyncing to production servers" | |
for HOSTNAME in "${PRODUCTION_HOSTNAMES[@]}" | |
do | |
echo -n "Syncing to $HOSTNAME..." | |
echo -e "\n\nSyncing to $HOSTNAME..." >> $LOGFILE | |
$RSYNC -avz --rsh="ssh -i $DEPLOYER_SSH_KEY" ./public deployer@$HOSTNAME:$DEPLOY_TO >> $LOGFILE | |
if [ $? -eq 0 ]; then | |
echo "done." | |
else | |
echo -e "\nAn error occured when deploying to $HOSTNAME. Check deploy.log for details" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment