53 lines
1.2 KiB
Python
Executable file
53 lines
1.2 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
from __future__ import print_function
|
|
|
|
import json
|
|
import tempfile
|
|
|
|
import git
|
|
from flask import Flask, request
|
|
from pid import PidFile
|
|
import sarge
|
|
from systemd.journal import JournalHandler
|
|
from twisted.internet import reactor
|
|
from twisted.web.server import Site
|
|
from twisted.web.wsgi import WSGIResource
|
|
|
|
|
|
DESTINATION = "/var/www/dennogumi-test/"
|
|
REPO = "dennogumi.org"
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/", methods=["POST"])
|
|
def push_hook_to_server():
|
|
|
|
app.logger.info("New data received. Processing...")
|
|
|
|
data = json.loads(request.data)
|
|
|
|
repository = data["repository"]
|
|
if repository["name"] != REPO:
|
|
app.logger.warning("Repository not found.")
|
|
return "OK"
|
|
|
|
repo_url = repository["url"]
|
|
temp = tempfile.mkdtemp()
|
|
app.logger.info("Cloning repository...")
|
|
git.Repo.clone_from(repo_url, temp)
|
|
|
|
cmd = "/usr/bin/jekyll_clone_repo.sh {0} {1}"
|
|
cmd = sarge.shell_format(cmd, temp, DESTINATION)
|
|
app.logger.info("Deploying Jekyll...")
|
|
pid = sarge.run(cmd, async=True)
|
|
|
|
return "OK"
|
|
|
|
if __name__ == "__main__":
|
|
|
|
resource = WSGIResource(reactor, reactor.getThreadPool(), app)
|
|
site = Site(resource)
|
|
|
|
reactor.listenTCP(5000, site, interface="127.0.0.1")
|
|
reactor.run()
|