Compare commits
8 Commits
nixpkgs_bu
...
hydra_inte
| Author | SHA1 | Date | |
|---|---|---|---|
|
02a5f5427b
|
|||
| 72b2ae020a | |||
|
4b222ac4b0
|
|||
|
a2b49bb36e
|
|||
|
9641ed68e2
|
|||
|
80a9fdb880
|
|||
|
a07c47846e
|
|||
|
f1f8a3c908
|
@@ -15,28 +15,6 @@ let
|
||||
keepnr = 1;
|
||||
type = 1;
|
||||
flake = "${info.head.repo.html_url}/archive/${info.head.ref}.tar.gz";
|
||||
inputs = {
|
||||
gitea_repo_name = {
|
||||
type = "string";
|
||||
value = "${info.head.repo.name}";
|
||||
emailresponsible = false;
|
||||
};
|
||||
gitea_repo_owner = {
|
||||
type = "string";
|
||||
value = "${info.head.repo.owner.username}";
|
||||
emailresponsible = false;
|
||||
};
|
||||
gitea_http_url = {
|
||||
type = "string";
|
||||
value = "https://git.dynamicdiscord.de";
|
||||
emailresponsible = false;
|
||||
};
|
||||
gitea_status_repo = {
|
||||
type = "string";
|
||||
value = "${info.head.ref}";
|
||||
emailresponsible = false;
|
||||
};
|
||||
};
|
||||
}) prs;
|
||||
mkFlakeJobset = branch: {
|
||||
description = "Build ${branch} branch of the Malobeo Infrastructure repo";
|
||||
@@ -48,7 +26,7 @@ let
|
||||
keepnr = 3;
|
||||
hidden = false;
|
||||
type = 1;
|
||||
flake = "https://git.dynamicdiscord.de/malobeo/infrastructure/archive/${branch}.tar.gz";
|
||||
flake = "git+https://git.dynamicdiscord.de/malobeo/infrastructure/archive/${branch}.tar.gz";
|
||||
};
|
||||
|
||||
desc = prJobsets // {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"type": 0,
|
||||
"inputs": {
|
||||
"nixexpr": {
|
||||
"value": "https://git.dynamicdiscord.de/malobeo/infrastructure master",
|
||||
"value": "https://git.dynamicdiscord.de/ahtlon/infrastructure master",
|
||||
"type": "git",
|
||||
"emailresponsible": false
|
||||
},
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
- [musik](./projekte/musik.md)
|
||||
- [TODO](./todo.md)
|
||||
- [Modules]()
|
||||
- [Gitea-translator](./module/gitea-translator.md)
|
||||
- [Initrd-ssh](./module/initssh.md)
|
||||
- [Disks](./module/disks.md)
|
||||
- [How-to]()
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
# Gitea-tanslator
|
||||
The module can be used by importing `inputs.self.nixosModules.malobeo.gitea-translator`
|
||||
|
||||
This module starts a python server that fetches the gitea pull request api and translates it to a file that hydra understands.
|
||||
To use, just set the parameters of the gitea server, then send a GET request to either `http://${host}:${port}/` or `http://${host}:${port}/gitea-pulls-sorted.json`
|
||||
|
||||
## Module config
|
||||
##### enable (default = false) - enables the module
|
||||
##### baseurl (default = "git.dynamicdiscord.de") - Base URL of the Gitea instance
|
||||
##### owner (default = "malobeo") - Repository owner
|
||||
##### repo (default = "infrastructure") - Repository name
|
||||
##### host (default = "127.0.0.1") - Address the server binds to
|
||||
##### port (default = 27364) - Port the server listens on
|
||||
|
||||
## Hydra config
|
||||
If you change the default port or host, the file `.hydra/spec.json` has to be modified accordingly.
|
||||
With the module running on the hydra host, create a new hydra project, then:
|
||||
|
||||
- Set `Declarative spec file` to `.hydra/spec.json`
|
||||
- Change declaritive input type to `Git checkout`
|
||||
- Set your git repo location in the field below that
|
||||
38
flake.lock
generated
38
flake.lock
generated
@@ -126,11 +126,11 @@
|
||||
"spectrum": "spectrum"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1773872447,
|
||||
"narHash": "sha256-IWTp4EMUfZwnuF5S/AjWfOFzCbbgkMzRwNd0qHC/EMg=",
|
||||
"lastModified": 1772055583,
|
||||
"narHash": "sha256-iPIm1orqkhsxqju6EVODOrV1BmyA5HNTZ8a1o812bFM=",
|
||||
"owner": "astro",
|
||||
"repo": "microvm.nix",
|
||||
"rev": "b202882536b018a76f0b6e71a48677f41f4de9d8",
|
||||
"rev": "f6dcfb7c16cc3775536c825dc0698d4ede13d063",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -177,11 +177,11 @@
|
||||
},
|
||||
"nixos-hardware": {
|
||||
"locked": {
|
||||
"lastModified": 1773533765,
|
||||
"narHash": "sha256-qonGfS2lzCgCl59Zl63jF6dIRRpvW3AJooBGMaXjHiY=",
|
||||
"lastModified": 1771969195,
|
||||
"narHash": "sha256-qwcDBtrRvJbrrnv1lf/pREQi8t2hWZxVAyeMo7/E9sw=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixos-hardware",
|
||||
"rev": "f8e82243fd601afb9f59ad230958bd073795cbfe",
|
||||
"rev": "41c6b421bdc301b2624486e11905c9af7b8ec68e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -209,11 +209,11 @@
|
||||
},
|
||||
"nixpkgs-unstable": {
|
||||
"locked": {
|
||||
"lastModified": 1773734432,
|
||||
"narHash": "sha256-IF5ppUWh6gHGHYDbtVUyhwy/i7D261P7fWD1bPefOsw=",
|
||||
"lastModified": 1771848320,
|
||||
"narHash": "sha256-0MAd+0mun3K/Ns8JATeHT1sX28faLII5hVLq0L3BdZU=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "cda48547b432e8d3b18b4180ba07473762ec8558",
|
||||
"rev": "2fc6539b481e1d2569f25f8799236694180c0993",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -225,11 +225,11 @@
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1773814637,
|
||||
"narHash": "sha256-GNU+ooRmrHLfjlMsKdn0prEKVa0faVanm0jrgu1J/gY=",
|
||||
"lastModified": 1771903837,
|
||||
"narHash": "sha256-sdaqdnsQCv3iifzxwB22tUwN/fSHoN7j2myFW5EIkGk=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "fea3b367d61c1a6592bc47c72f40a9f3e6a53e96",
|
||||
"rev": "e764fc9a405871f1f6ca3d1394fb422e0a0c3951",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -264,11 +264,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1773698643,
|
||||
"narHash": "sha256-VCiDjE8kNs8uCAK73Ezk1r3fFuc4JepvW07YFqaN968=",
|
||||
"lastModified": 1772048434,
|
||||
"narHash": "sha256-/wA0OaH6kZ/pFA+nXR/tvg5oupOmEDmMS5us79JT60o=",
|
||||
"owner": "Mic92",
|
||||
"repo": "sops-nix",
|
||||
"rev": "8237de83e8200d16fe0c4467b02a1c608ff28044",
|
||||
"rev": "334daa7c273dd8bf7a0cd370e4e16022b64e55e9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -280,11 +280,11 @@
|
||||
"spectrum": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1772189877,
|
||||
"narHash": "sha256-i1p90Rgssb//aNiTDFq46ZG/fk3LmyRLChtp/9lddyA=",
|
||||
"lastModified": 1759482047,
|
||||
"narHash": "sha256-H1wiXRQHxxPyMMlP39ce3ROKCwI5/tUn36P8x6dFiiQ=",
|
||||
"ref": "refs/heads/main",
|
||||
"rev": "fe39e122d898f66e89ffa17d4f4209989ccb5358",
|
||||
"revCount": 1255,
|
||||
"rev": "c5d5786d3dc938af0b279c542d1e43bce381b4b9",
|
||||
"revCount": 996,
|
||||
"type": "git",
|
||||
"url": "https://spectrum-os.org/git/spectrum"
|
||||
},
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
{ config, self, lib, inputs, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.malobeo.gitea-translator;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
services.malobeo.gitea-translator = {
|
||||
enable = mkOption {
|
||||
default = false;
|
||||
type = types.bool;
|
||||
description = lib.mdDoc "Start a webserver for hydra to use the gitea pull request api.";
|
||||
};
|
||||
|
||||
baseurl = mkOption {
|
||||
type = types.str;
|
||||
default = "git.dynamicdiscord.de";
|
||||
description = lib.mdDoc "Base URL of the Gitea instance.";
|
||||
};
|
||||
|
||||
owner = mkOption {
|
||||
type = types.str;
|
||||
default = "malobeo";
|
||||
description = lib.mdDoc "Repository owner on the Gitea instance.";
|
||||
};
|
||||
|
||||
repo = mkOption {
|
||||
type = types.str;
|
||||
default = "infrastructure";
|
||||
description = lib.mdDoc "Repository name on the Gitea instance.";
|
||||
};
|
||||
|
||||
host = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = lib.mdDoc "Address the server binds to.";
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 27364;
|
||||
description = lib.mdDoc "Port the server listens on.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services.gitea-translator = {
|
||||
description = "Gitea Pull Request Translator for Hydra";
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = ''
|
||||
${pkgs.python3}/bin/python3 ${../../../scripts/gitea_hydra_server.py} \
|
||||
--baseurl ${cfg.baseurl} \
|
||||
--owner ${cfg.owner} \
|
||||
--repo ${cfg.repo} \
|
||||
--host ${cfg.host} \
|
||||
--port ${toString cfg.port}
|
||||
'';
|
||||
Restart = "on-failure";
|
||||
RestartSec = 5;
|
||||
|
||||
# Hardening because why not
|
||||
DynamicUser = true;
|
||||
NoNewPrivileges = true;
|
||||
ProtectSystem = "strict";
|
||||
ProtectHome = true;
|
||||
PrivateTmp = true;
|
||||
PrivateDevices = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -118,7 +118,6 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
|
||||
users.imports = [ ./machines/modules/malobeo/users.nix ];
|
||||
backup.imports = [ ./machines/modules/malobeo/backup.nix ];
|
||||
printing.imports = [ ./machines/modules/malobeo/printing.nix ];
|
||||
gitea-translator.imports = [ ./machines/modules/malobeo/gitea_translator.nix ];
|
||||
};
|
||||
|
||||
hydraJobs = nixpkgs.lib.mapAttrs (_: nixpkgs.lib.hydraJob) (
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
#imports
|
||||
import os
|
||||
import json
|
||||
import argparse
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
import urllib.request
|
||||
|
||||
def _get_api_response(baseurl, owner, repo):
|
||||
###https://docs.gitea.com/api/1.21/#tag/repository/operation/repoListPullRequests
|
||||
###GET /api/v1/repos/{owner}/{repo}/pulls
|
||||
url=(f"https://{baseurl}/api/v1/repos/{owner}/{repo}/pulls?state=open")
|
||||
headers={"Accept": "application/json"}
|
||||
req=urllib.request.Request(url, headers=headers)
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
return json.loads(resp.read().decode("utf-8"))
|
||||
|
||||
def _parse_response(baseurl, owner, repo):
|
||||
target_repo_url=f"https://{baseurl}/{owner}/{repo}.git"
|
||||
pulls: dict={}
|
||||
response=_get_api_response(baseurl, owner, repo)
|
||||
for pr in response:
|
||||
pr["target_repo_url"]=target_repo_url
|
||||
pulls[str(pr["number"])]=pr
|
||||
return pulls
|
||||
|
||||
class PullsHandler(BaseHTTPRequestHandler):
|
||||
_VALID_PATHS={"/", "/gitea-pulls-sorted.json"}
|
||||
|
||||
# Class variables to store configuration
|
||||
baseurl = None
|
||||
owner = None
|
||||
repo = None
|
||||
|
||||
def do_GET(self):
|
||||
if self.path not in self._VALID_PATHS:
|
||||
self.send_error(404, "Not Found")
|
||||
return
|
||||
|
||||
answer=dict(_parse_response(self.baseurl, self.owner, self.repo))
|
||||
|
||||
body=json.dumps(answer, indent=2, sort_keys=True).encode("utf-8")
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json; charset=utf-8")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, fmt, *args):
|
||||
print(
|
||||
f"[gitea-translator] {self.address_string()} - {fmt % args}",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Hydra Server to Gitea-pull-request translator"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--baseurl",
|
||||
default="git.dynamicdiscord.de",
|
||||
help="Base URL of Gitea instance (default: git.dynamicdiscord.de)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--owner",
|
||||
default="malobeo",
|
||||
help="Repository owner (default: malobeo)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--repo",
|
||||
default="infrastructure",
|
||||
help="Repository name (default: infrastructure)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--host",
|
||||
default="127.0.0.1",
|
||||
help="Host to bind to (default: 127.0.0.1)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--port",
|
||||
type=int,
|
||||
default=27364,
|
||||
help="Port to bind to (default: 27364)"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Set class variables so they're accessible in request handlers
|
||||
PullsHandler.baseurl = args.baseurl
|
||||
PullsHandler.owner = args.owner
|
||||
PullsHandler.repo = args.repo
|
||||
|
||||
print(
|
||||
f"[gitea-translator] Starting, pulling from {args.baseurl}/{args.owner}/{args.repo}",
|
||||
flush=True,
|
||||
)
|
||||
server=HTTPServer((args.host, args.port), PullsHandler)
|
||||
print(
|
||||
f"[gitea-translator] online @ {args.host}:{args.port}",
|
||||
flush=True,
|
||||
)
|
||||
server.serve_forever()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user