Search code examples
githubsshcontinuous-integrationforeverautodeploy

How to automatically deploy node repo on github in linux server?


I have a linux server as my a production environment, and my node repo is on github . When I push my code, if I want to deploy it , I need to .

>local
git push
ssh user@host

>remote
cd repo
git pull

I am using node forever to auto update my code , but it is still a very troublesome .

Is there any solution , like travis-ci or heroku , can Automatically deploy my code on github ?


Solution

  • Travis-ci is for continuous integration (as its name) While Heroku is just a cloud platform. They are not for deployment.

    My solution is to set up a git hook on your server, push to it to trigger the hook, and do whatever you want in that script.

    for example, you can:

    1. cd ~/repo && mkdir myproj && cd myproj
    2. git init --bare
    3. edit ~/repo/myproj/hooks/post-update

      #!/bin/sh
      unset GIT_DIR;
      cd <your project-root>
      export NODE_ENV="product"
      git pull
      npm install
      pm2 restart <your app name>
      
    4. chmod +x ~/repo/myproj/hooks/post-update

    now you can add your repo on server as one of your remotes

    There's some services available to monitor your deployment, such as http://dploy.io/ and https://www.codeship.io/

    Feel free to use them when your business grows up.