Commit b15e9ebc authored by alexandre's avatar alexandre

Merge 37.34.55.224:/home/osp/apps/osp.tool.gitlab_webhook_receiver

parents 44292687 02a35fa8
......@@ -3,34 +3,43 @@ import shlex
import subprocess
import json
from bottle import request, route, run
from bottle import request, route, run, default_app
REPO_PATH = "/home/git/repositories.new"
REPO_PATH = "/home/osp/repos"
@route('/', method='POST')
@route('/', method="POST")
def index():
print("received request")
if request.headers.get('X-Gitlab-Event') == 'Push Hook':
# print("push hook")
print("push hook")
data = json.load(request.body)
print(data)
repo = data.get("repository")
git_http_url = repo.get("git_http_url")
project = data.get("project")
#ns = data.get("namespace")
ns = "osp"
repo_name = git_http_url.split("/")[-1]
repo_local_path = os.path.join(REPO_PATH, repo_name)
repo_local_path = os.path.join(REPO_PATH, "{}.{}".format(ns, repo_name))
if os.path.isdir(repo_local_path):
# print("repo exists. Pulling")
print("repo exists. Pulling")
cmd = "git fetch origin master:master"
subprocess.Popen(shlex.split(cmd), cwd=repo_local_path)
else:
# print("repo don't exist. Cloning")
cmd = "git clone --bare %s" % git_http_url
print("repo don't exist. Cloning")
cmd = "git clone --bare {} {}.{}".format(git_http_url, ns, repo_name)
subprocess.Popen(shlex.split(cmd), cwd=REPO_PATH)
return "Hello World!"
return "Bye World!"
if __name__ == "__main__":
run(host='localhost', port=8080)
run(host='0.0.0.0', port=7331)
else:
app = default_app()
#! /usr/bin/env bash
NAME="webhook" # Name of the application
USER=www-data # the user to run as
GROUP=www-data # the group to run as
DJANGODIR=/home/osp/apps/osp.tool.gitlab_webhook_receiver # Django project directory
SOCKFILE=/tmp/gunicorn-hook.sock # we will communicte using this unix socket
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
# DJANGO_SETTINGS_MODULE=le75.settings # which settings file should Django use
# DJANGO_WSGI_MODULE=le75.wsgi # WSGI module name
#
VENV=/home/osp/apps/venvs/osp.tool.gitlab_webhook_receiver
#
echo "Starting $NAME as `whoami`"
#
# Activate the virtual environment
cd $DJANGODIR
source $VENV/bin/activate
# export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
# export PYTHONPATH=$DJANGODIR:$PYTHONPATH
#
# Create the run directory if it doesn't exist
# RUNDIR=$(dirname $SOCKFILE)
# test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec $VENV/bin/gunicorn app:app \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
import bottle
application = bottle.default_app()
# vim: set filetype=python:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment