Giter VIP home page Giter VIP logo

git-hook-listener's Introduction

Git Hook Listener

An application for continuous deployment that listens for git webhooks and downloads push updates automatically.

"Why should I use this"?

Well, I used to update applications on servers by dragging and dropping files via Filezilla, manually. Sometimes I had to check the files to replace from my computer to the server. And I used to do this process a lot of times, specially to show and validate new functionalities in development. It takes a lot of time and effort just to do a simple task: get my newest updates in my machine and update on the server. Nowadays, using a git repository and this project, I just commit my changes and, magically, the files are replicated to the server as well! :)

"Sounds good! What are the prerequisites?"

  • Just a Git repository and NodeJS installed in your server / computer.

Getting started

1) Store your Git repository user credentials in your machine (for Linux)

This is for avoiding prompting your user and password when doing a git pull.

Windows users, please give me a feedback.

  // In CMD, write:
  $ nano ~/.netrc
  
  // And add these lines:
  machine github.com (or bitbucket.org)
  login [YOUR_USER]
  password [YOUR_PASS]
  
  // Save it using: CMD + o
  // And exit using: CMD + x
2) Download this project
  $ cd [path to download]
  $ git clone https://github.com/renancaldas/git-hook-listener.git
  $ cd git-hook-listener && npm install
3) Run for the first time

You should have nodemon installed! If you don't have: npm install -g nodemon

   $ npm start
   // Which runs: NODE_ENV=development DEBUG=git* nodemon git-hook-listener.js

It should appear the message: git-hook-listener.js Server started at port 3000 +0ms

4) Test if application is up and running

Make a GET request to the endpoint running, for example:

    // Open a new CMD, because the current window is running the application
    $ curl http://localhost:3000/test

    // Or try connecting remotelly
    $ curl http://www.your_domain_running_the_app.com:3000/test

If appears the message "Ready to use POST /hook endpoint!" you are good to go!

5) Configuring webhook

Go to your Git repo (like bitbucket), select your repository then go to Settings -> Webhooks and create a request to the application, ending with the /hook. For example: http://www.your_domain_running_the_app.com:port/hook.

Obs: If you are running in your local machine using localhost, you should create a proxy for receving external requests from the internet. In this case, I recommend Ngrok for testing: https://ngrok.com/.

6) It is done!

Finally, you can push changes to your repository. It will trigger the webhook to the application and do a git clone / pull to your server in the specified folder in the config file, automatically!

Obs: I recommend PM2 (Process Manager 2) to set this application to run "forever" (like npm forever) even after a crash or server restart.

Author

Renan Caldas de Oliveira

git-hook-listener's People

Contributors

renancaldas avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.