Skip to content

Instantly share code, notes, and snippets.

@jonathan-kosgei
Forked from lemiorhan/post-receive
Last active September 1, 2016 20:26
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 jonathan-kosgei/0f04adfecab6498b2b9442f1433069e3 to your computer and use it in GitHub Desktop.
Save jonathan-kosgei/0f04adfecab6498b2b9442f1433069e3 to your computer and use it in GitHub Desktop.
Post-receive hook to deploy the code being pushed to production branch to a specific folder
#!/bin/bash
target_branch="production"
working_tree="PATH_TO_DEPLOY"
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ -n "$branch" ] && [ "$target_branch" == "$branch" ]; then
GIT_WORK_TREE=$working_tree git checkout $target_branch -f
NOW=$(date +"%Y%m%d-%H%M")
# Add section to do npm install or composer install or pip install -r requirements
# check env passed to gogs container or sed this file in init script on gogs with the app_type
# or do the logic there and just set the command to be used here in a variable
# also check if the package.json or requirements.txt and/or Gemfile / composer.json/lock ?
# if it exists then install deps to the git work tree, check if it's needed to delete the deps folder each time
# use a scripting language like http://krisjordan.com/essays/setting-up-push-to-deploy-with-git
# don't forget to restart (start | stop) app uwsgi , php ? , npm maybe pm2 bundler etc
# remove this tagging #git tag release_$NOW $target_branch
# Add info to the pretty print below to show app is stopped / started / deps are updated etc etc :-)
# Even maybe app access info ; url, ports etc
echo " /==============================="
echo " | DEPLOYMENT COMPLETED"
echo " | Target branch: $target_branch"
echo " | Target folder: $working_tree"
echo " | Tag name : release_$NOW"
echo " \=============================="
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment