Skip to content

Instantly share code, notes, and snippets.

@pcanterini
Created May 19, 2015 15:11
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 pcanterini/05668823f01d350d9c52 to your computer and use it in GitHub Desktop.
Save pcanterini/05668823f01d350d9c52 to your computer and use it in GitHub Desktop.
Ubuntu nodejs git hook
# ubuntu server setup
adduser deploy sudo
# on your machine
# ssh-copy-id deploy@IPADDRESS
# ssh deploy@IPADDRESS -i yoursakeyfile
# edit /etc/ssh/ssh_config set PasswordAuthentication to 'no'
# run service ssh restart to restart ssh
# back on the server
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
# install nodejs
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get install -y nodejs
# create git repo
mkdir project.git
cd project.git
git init --bare
# Create/edit post receive hook and don't forget to chmod +x post-receive
### start ###
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
GIT_WORK_TREE=/home/deploy/publishing-templates git checkout -f $branch
done
cd /home/deploy/publishing-templates/app
#git pull hub master
npm install
gulp all
### end ###
# dont forget to create deploy folder in same folder where .git bare repo is
# Install nginx
sudo apt-get install nginx
# Edit nginx config file
sudo vi /etc/nginx/sites-available/default
# Restart nginx
sudo service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment