Skip to content

Instantly share code, notes, and snippets.

@raykao
Last active April 29, 2016 16:30
Show Gist options
  • Save raykao/2b2653cfaa147ecf9170304e3cd7cb50 to your computer and use it in GitHub Desktop.
Save raykao/2b2653cfaa147ecf9170304e3cd7cb50 to your computer and use it in GitHub Desktop.
An example of a git post-receive hook for deploying https://github.com/womenandtech/editor
#!/bin/bash
# load enviroment variables and other necessary itemes (e.g. node via nvm)
source ~/.bash_profile
# Set Directory locations:
#
# WORKING_DIR -> The directory that actually houses the working code
WORKING_DIR="/home/<username>/editor.womenandtech.com"
# GIT_DIR -> The git repo DIR
GIT_DIR="/home/<username>/<all git repositiories dir>/<repository dir>"
git --work-tree=$WORKING_DIR --git-dir=$GIT_DIR checkout -f
# Change Directory to working directory (we'll be running commands from that location)
cd "$WORKING_DIR"
# output all the responses over git (you can see this output when you run "git push production" from your remote computer i.e. your laptop
# Display that we're about to install node modules
echo "---- install node modules ----"
# Runs npm install to install any/all dependencies listed in "package.json"
echo $(npm install)
# Display that we're about to install bower packages
echo "---- install bower modules ----"
# Runs bower install...obviously...
echo $(bower install)
# Build and bundle up our production product...all the good things will be in "$WORKING_DIR/dist" folder...
# this is where your webserver should be serving from. See https://gist.github.com/raykao/d245d10cfd3ca2a3e1650aa63d4f87e7 for an example.
echo $(ember build --environment=production)
@raykao
Copy link
Author

raykao commented Apr 29, 2016

Don't forget you will need to run chmod +x post-receive to make the post-receive hook file executable...otherwise zero things will happen :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment