Use caddy-exec to handling Forgejo webhooks on astral
This commit is contained in:
parent
01015c19b9
commit
39f73ef2f2
2 changed files with 20 additions and 33 deletions
|
|
@ -1,39 +1,21 @@
|
|||
{ pkgs, ... }:
|
||||
{ pkgs, lib, ... }:
|
||||
let
|
||||
domain = "nettika.leaf.ninja";
|
||||
root = "/srv/links";
|
||||
webhookHandler = pkgs.writeScript "webhook-handler.py" ''
|
||||
#!${pkgs.python3}/bin/python3
|
||||
|
||||
import http.server
|
||||
import socketserver
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
class WebhookHandler(http.server.SimpleHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
os.chdir('${root}')
|
||||
subprocess.run(['${pkgs.git}/bin/git', 'pull'], check=True)
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(b'OK')
|
||||
|
||||
with socketserver.TCPServer(("127.0.0.1", 8081), WebhookHandler) as httpd:
|
||||
httpd.serve_forever()
|
||||
'';
|
||||
in {
|
||||
systemd.services.links-webhook = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
ExecStart = "${pkgs.python3}/bin/python3 ${webhookHandler}";
|
||||
Restart = "always";
|
||||
};
|
||||
services.caddy.virtualHosts = {
|
||||
${domain}.extraConfig = ''
|
||||
root * ${root}
|
||||
file_server
|
||||
'';
|
||||
"http://localhost:8081".extraConfig = let git = lib.getExe pkgs.git;
|
||||
in ''
|
||||
route {
|
||||
exec {
|
||||
command ${git} pull --rebase
|
||||
directory ${root}
|
||||
}
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
||||
services.caddy.virtualHosts.${domain}.extraConfig = ''
|
||||
root * ${root}
|
||||
file_server
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue