Skip to content

Commit

Permalink
pull on get, see: logsol#14
Browse files Browse the repository at this point in the history
  • Loading branch information
glaslos committed Nov 20, 2015
1 parent c127104 commit 5aeb334
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ To set it up, do the following:
* Enter the matching for your project(s) in the git_deploy.conf.json file
* Start the server by typing "python git_deploy.py"
* To run it as a daemon add --daemon-mode
* To trigger the pull and deploy via get add --get-to-pull
* On the Github page go to a repository, then "Admin", "Service Hooks", "Post-Receive URLs" and add the url of your machine + port (e.g. http://example.com:8001).

You can even test the whole thing here, by clicking on the "Test Hook" button, whohoo!
Expand Down
19 changes: 19 additions & 0 deletions git_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class GitDeploy(BaseHTTPRequestHandler):
quiet = False
daemon = False
branch = None
is_get_available = False

@classmethod
def get_config(cls):
Expand All @@ -33,6 +34,22 @@ def get_config(cls):
and not os.path.isdir(repository['path'] + '/objects'):
sys.exit('Directory ' + repository['path'] + ' is not a Git repository')

def do_GET(self):
if GitDeploy.is_get_available:
paths = [repository['path'] for repository in self.getConfig()['repositories']]
for path in paths:
self.pull(path)
self.deploy(path)
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write("<html>")
self.wfile.write("<head><title>Github Autodeploy</title></head>")
self.wfile.write("<body><p>Ok, updated.</p></body>")
self.wfile.write("</html>")
else:
self.send_response(500)

def do_POST(self):
event = self.headers.getheader('X-Github-Event')
if event == 'ping':
Expand Down Expand Up @@ -109,6 +126,8 @@ def main():
GitDeploy.quiet = True
if arg == '-q' or arg == '--quiet':
GitDeploy.quiet = True
if arg == '-g' or arg == '--get-to-pull':
GitDeploy.is_get_available = True

if GitDeploy.daemon:
pid = os.fork()
Expand Down

0 comments on commit 5aeb334

Please sign in to comment.