Created
June 19, 2020 19:13
-
-
Save adelin-b/8aca8e2fd0ee234c9191a7a368c87693 to your computer and use it in GitHub Desktop.
rsync deploy
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 | |
# DEPLOY_USER=ubuntu | |
# DEPLOY_SERVER= | |
# DEPLOY_SSH=$DEPLOY_USER@$DEPLOY_SERVER:$DEPLOY_DIR | |
SSH_SERVER_NAME=ssh_config_name | |
DEPLOY_DIR=/home/admin/deploy/ | |
DEPLOY_SSH=$SSH_SERVER_NAME:$DEPLOY_DIR | |
EXLUDE_FILE=.rsync_exclude | |
set -e | |
fast="" | |
usage() | |
{ | |
echo "" | |
echo "Usage: $0 -f " | |
echo -e "\t-f Fast deploy without checking for new packages" | |
exit 1 # Exit script after printing help | |
} | |
while getopts "f" opt | |
do | |
case "$opt" in | |
f ) fast="true" ;; | |
? ) usage ;; # Print usage in case parameter is non-existent | |
esac | |
done | |
echo "Running dry-run of rsync to server" | |
rsync --dry-run -az --force --delete --progress --exclude-from=$EXLUDE_FILE -e "ssh -p22" ./ $DEPLOY_SSH | |
echo "Thoses files are going to be rsynced and deployed" | |
read -p "Are you sure? " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo "Running actual deploy" | |
echo "Rsync files" | |
rsync -az --force --delete --progress --exclude-from=$EXLUDE_FILE -e "ssh -p22" ./ $DEPLOY_SSH | |
if [ -z "$fast" ] ; then | |
echo "Updating packages." | |
ssh $SSH_SERVER_NAME "cd ${DEPLOY_DIR}; yarn ; yarn build; yarn start:service:api" | |
fi | |
echo "Deployment done." | |
echo | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment