Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tools.gitlab_webhook_receiver
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
osp
tools.gitlab_webhook_receiver
Commits
b15e9ebc
Commit
b15e9ebc
authored
Jan 11, 2017
by
alexandre
Browse files
Options
Browse Files
Download
Plain Diff
Merge 37.34.55.224:/home/osp/apps/osp.tool.gitlab_webhook_receiver
parents
44292687
02a35fa8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
15 deletions
+53
-15
app.py
app.py
+18
-9
gunicorn.sh
gunicorn.sh
+35
-0
wsgi.py
wsgi.py
+0
-6
No files found.
app.py
View file @
b15e9ebc
...
...
@@ -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
()
gunicorn.sh
0 → 100755
View file @
b15e9ebc
#! /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
=
-
wsgi.py
deleted
100644 → 0
View file @
44292687
import
bottle
application
=
bottle
.
default_app
()
# vim: set filetype=python:
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment