Skip to content

Setup Push to Deploy

Weimin Ouyang edited this page May 3, 2016 · 12 revisions

Since version 2.4, git has supported push to deploy. Push to deploy requires some configuration on server side git repository. Steps to take (in Ubuntu) are listed below:

  1. Install the newest git.

    sudo add-apt-repository ppa:git-core/ppa
    sudo apt-get update
    sudo apt-get install git
  2. Install Node.js + npm.

    curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
    sudo apt-get install -y nodejs
  3. Install pm2 globally. PM2 is a production process manager for Node.js applications with a built-in load balancer.

    npm install -g pm2
  4. Clone git repo to your home directory.

  5. Add a hook named post-update in WeStudy/.git/hooks, and make it executable.

    #!/bin/sh 
    
    git read-tree -u -m HEAD
    npm install --production
    pm2 restart ~/WeStudy/bin/www
  6. Overwrite WeStudy/.git/config with the following:

    [core]
    	repositoryformatversion = 0
    	filemode = true
    	bare = false
    	logallrefupdates = true
    [receive]
    	denyCurrentBranch = updateInstead
    
  7. Install dependencies

    npm install
  8. Start a node instance in ~/WeStudy/.

    pm2 start ./bin/www
    
    ## or to start on port 443
    sudo apt-get install authbind
    sudo touch /etc/authbind/byport/443
    sudo chown %user% /etc/authbind/byport/443
    sudo chmod 755 /etc/authbind/byport/443
    PORT=443 authbind --deep pm2 start ./bin/www -n live

Optional: Add this alias pm2='authbind --deep pm2' to bash_profile.

  1. Go to your development environment, and switch to a branch you want to push.

    git push -f <remote name> <branch name>:master
  2. Set up ssh control master. Add the following to ~/.ssh/config.

    Host *
    ControlMaster auto
    ControlPath ~/.ssh/controlmasters/%r@%h:%p
    

    Create the contolmaster folder mkdir ~/.ssh/controlmasters

Clone this wiki locally