Skip to content

alghanmi/git_hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

#Python Git Post Receive Hook This a skeliton git post receive hook using Python, Flask and deployed using uWSGI on Nginx.

###Setup

#Install needed software
sudo aptitude install build-essential python python-pip python-dev supervisor
sudo pip install Werkzeug Flask
sudo pip install http://projects.unbit.it/downloads/uwsgi-lts.tar.gz
sudo pip install simplejson


#Setup Logging directories
sudo mkdir /var/log/uwsgi
sudo chmod 755 /var/log/uwsgi

###Configuration We are using githook.ini to configure uWSGI's behaviour.

###Running the Application To run the application, simply call uWSGI and give it the ini file:

sudo uwsgi --ini githook.ini

###Testing the Application You can test the app locally by running

python githook.py

You can test POST commands using curl, e.g.

curl -X POST -H "Content-Type: application/json" -d '{"username":"xyz","password":"xyz"}' http://localhost:5000/deploy

###Nginx Configuration

server {
        listen          80;
        server_name     usc.alghanmi.org;

        access_log      /home/www/logs/access.log;
        error_log       /home/www/logs/error.log warn;

        index           index.html index.htm;
        root            /home/www/public_html;

        location = /githook { rewrite ^ /githook/; }
        location /githook { try_files $uri @githook; }
        location @githook {
                 include uwsgi_params;
                 uwsgi_param SCRIPT_NAME /githook;
                 uwsgi_modifier1 30;
                 uwsgi_pass unix:/tmp/uwsgi-githook.sock;
        }
}

###Supervisor Configuration Supervisor is an application used to monitor and control your Flask app. Your webserver, for example, is setup to start after a machine crash or reboot. Supervisor will take care to restarting uWSGI and in turn your Flask app.

In debian-based systems, you install application configuration in the /etc/supervisor/conf.d directory. The configuration for our githook app would look like:

[program:githook]
command=uwsgi --ini /path/to/git_hook/githook.ini
directory=/path/to/git_hook/githook.ini
numprocs=1
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/githook-supervisord.log
redirect_stderr=true
stopsignal=INT

###References The following references were used when developing this hook:

About

Flask-based implementation of a git post receive hook

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages