feat(gitea): add native NATS JetStream and webhook bridge
This commit is contained in:
parent
2340c5a0e7
commit
41f5e6bae8
2 changed files with 46 additions and 0 deletions
|
|
@ -71,6 +71,7 @@
|
||||||
|
|
||||||
hosts = {
|
hosts = {
|
||||||
izanagi.modules = [ ./hosts/izanagi ];
|
izanagi.modules = [ ./hosts/izanagi ];
|
||||||
|
Gitea.modules = [ ./hosts/Gitea ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,50 @@ in {
|
||||||
options.homelab.apps.gitea.enable = lib.mkEnableOption "Gitea";
|
options.homelab.apps.gitea.enable = lib.mkEnableOption "Gitea";
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
|
services.nats = {
|
||||||
|
enable = true;
|
||||||
|
listenAddress = "0.0.0.0";
|
||||||
|
port = 4222;
|
||||||
|
jetstream = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
networking.firewall.allowedTCPPorts = [ 4222 9000 ];
|
||||||
|
|
||||||
|
systemd.services.gitea-webhook-bridge = {
|
||||||
|
description = "Gitea Webhook Bridge to NATS JetStream";
|
||||||
|
after = [ "network.target" "nats.service" ];
|
||||||
|
wants = [ "nats.service" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
path = with pkgs; [ natscli python3 ];
|
||||||
|
script = ''
|
||||||
|
python3 -c '
|
||||||
|
import http.server
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
class WebhookHandler(http.server.BaseHTTPRequestHandler):
|
||||||
|
def do_POST(self):
|
||||||
|
content_length = int(self.headers.get("Content-Length", 0))
|
||||||
|
body = self.rfile.read(content_length)
|
||||||
|
try:
|
||||||
|
subprocess.run(["nats", "pub", "--server=nats://127.0.0.1:4222", "forgejo.staging"], input=body, check=True)
|
||||||
|
self.send_response(200)
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(b"OK\n")
|
||||||
|
except Exception as e:
|
||||||
|
self.send_response(500)
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write(str(e).encode("utf-8"))
|
||||||
|
|
||||||
|
def log_message(self, format, *args):
|
||||||
|
sys.stderr.write("%s - - [%s] %s\n" % (self.client_address[0], self.log_date_time_string(), format%args))
|
||||||
|
|
||||||
|
server = http.server.ThreadingHTTPServer(("0.0.0.0", 9000), WebhookHandler)
|
||||||
|
server.serve_forever()
|
||||||
|
'
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
homelab = {
|
homelab = {
|
||||||
users = {
|
users = {
|
||||||
apps.enable = true;
|
apps.enable = true;
|
||||||
|
|
@ -438,6 +482,7 @@ in {
|
||||||
# ... oath2_client
|
# ... oath2_client
|
||||||
|
|
||||||
# ... webhook
|
# ... webhook
|
||||||
|
FORGEJO__webhook__ALLOWED_HOST_LIST = "192.168.0.0/16,127.0.0.0/8,host.docker.internal,*";
|
||||||
|
|
||||||
FORGEJO__mailer__ENABLED = "true";
|
FORGEJO__mailer__ENABLED = "true";
|
||||||
# Buffer length of channel, keep it as it is if you don't know what it is.
|
# Buffer length of channel, keep it as it is if you don't know what it is.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue