1
0
Fork 0

Jekyll stuff

This commit is contained in:
Luca Beltrame 2015-05-17 23:51:09 +02:00
parent db1b37ad4a
commit 26dd2ffd26
2 changed files with 57 additions and 0 deletions

11
jekyll_clone_repo.sh Normal file
View file

@ -0,0 +1,11 @@
#!/bin/bash
cloned_dir=$1
destination_dir=$2
function finish {
rm -rf "$cloned_dir"
}
trap finish EXIT
/usr/local/bin/jekyll build --source "$cloned_dir" --destination "$destination_dir" 2>&1 |& systemd-cat -t "jekyll-cloner" -p "info"

46
jekyll_webhook.py Normal file
View file

@ -0,0 +1,46 @@
#!/usr/bin/env python
from __future__ import print_function
import json
import tempfile
import git
from flask import Flask, request
import sarge
from systemd.journal import JournalHandler
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...")
handler = JournalHandler()
app.logger.addHandler(handler)
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 = "/home/einar/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__":
app.run()