|
#!/bin/bash |
|
|
|
cd "`dirname $0`" |
|
|
|
# The commit/deployment message |
|
MESSAGE='Uh...' |
|
[ -n "${1}" ] && MESSAGE=${1} |
|
|
|
# ----- Part 1 - Prep the source/main repo ----- |
|
|
|
cd ../main_repo_dir |
|
# Here you can also run grunt/gulp, etc to prep for deployment |
|
# Commit, Pull & Push any changes |
|
git add . -A |
|
git commit -am "$MESSAGE" |
|
git pull |
|
git push |
|
|
|
# ----- Part 2 - Update the deployment repo ----- |
|
|
|
# Create an archive with all the changed files - https://git-scm.com/docs/git-diff#git-diff---diff-filterACDMRTUXB82308203 |
|
git archive --format=zip HEAD `git diff --name-only HEAD~1 HEAD --no-renames --diff-filter=AMCBTXU` > ../rangergo-backend-deploy/update.zip |
|
# Create a text file containing all the delted file names |
|
git diff --name-only HEAD~1 HEAD --no-renames --diff-filter=D > ../rangergo-backend-deploy/deleted.log |
|
cd ../deployment_repo_dir |
|
# Delete the files deleted in the original repo - https://stackoverflow.com/a/10150682/937891 |
|
xargs -a deleted.log -d'\n' rm |
|
# Create a temporary directory for extracting and then copying files from the source repo |
|
mkdir easy_git_and_ssh_based_deployer_tmp && cd easy_git_and_ssh_based_deployer_tmp |
|
unzip -o ../update.zip |
|
cd .. |
|
cp -rf ./easy_git_and_ssh_based_deployer_tmp/* ./ # Here you may instead selectively copy dist or deployment specific folders |
|
# Clean up |
|
rm -rf ./easy_git_and_ssh_based_deployer_tmp |
|
rm update.zip |
|
rm deleted.log |
|
|
|
# Commit and push the deployment repo |
|
git add . -A |
|
git commit -am "$MESSAGE" |
|
git pull |
|
git push |
|
|
|
# ----- Part 3 - Deploy to the server ----- |
|
|
|
# Login via SSH and pull the updated repo on the server |
|
ssh user@my_server_to_deploy.io <<'ENDSSH' |
|
#commands to run on remote host |
|
cd /var/www/my_server_dir |
|
git pull |
|
# php artisan migrate --force # Can do stuff like migrating if laravel, etc |
|
ENDSSH |