forked from malobeo/infrastructure
Compare commits
8 Commits
test2
...
hydra_inte
| Author | SHA1 | Date | |
|---|---|---|---|
|
02a5f5427b
|
|||
| 72b2ae020a | |||
|
4b222ac4b0
|
|||
|
a2b49bb36e
|
|||
|
9641ed68e2
|
|||
|
80a9fdb880
|
|||
|
a07c47846e
|
|||
|
f1f8a3c908
|
@@ -1,31 +0,0 @@
|
|||||||
name: Weekly Flake Update
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types:
|
|
||||||
- opened
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
hydra_callback:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
NIXPKGS_ALLOW_UNFREE: 1
|
|
||||||
steps:
|
|
||||||
- name: Install sudo
|
|
||||||
run: |
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y sudo
|
|
||||||
- name: Set up Nix
|
|
||||||
uses: https://github.com/cachix/install-nix-action@v31
|
|
||||||
with:
|
|
||||||
github_access_token: ${{ secrets.AHTLONS_GITHUB_TOKEN }}
|
|
||||||
- name: Find pr number
|
|
||||||
run: |
|
|
||||||
echo PR=$(echo "${{ github.ref }}" | cut -d / -f 3) >> "$GITHUB_ENV"
|
|
||||||
- name: run hydra wait
|
|
||||||
run: |
|
|
||||||
echo "Running now @ pr no $PR"
|
|
||||||
nix run nixpkgs#hydra-cli -- -H https://hydra.dynamicdiscord.de jobset-wait malobeo2 "$PR"
|
|
||||||
@@ -15,28 +15,6 @@ let
|
|||||||
keepnr = 1;
|
keepnr = 1;
|
||||||
type = 1;
|
type = 1;
|
||||||
flake = "${info.head.repo.html_url}/archive/${info.head.ref}.tar.gz";
|
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;
|
}) prs;
|
||||||
mkFlakeJobset = branch: {
|
mkFlakeJobset = branch: {
|
||||||
description = "Build ${branch} branch of the Malobeo Infrastructure repo";
|
description = "Build ${branch} branch of the Malobeo Infrastructure repo";
|
||||||
@@ -48,7 +26,7 @@ let
|
|||||||
keepnr = 3;
|
keepnr = 3;
|
||||||
hidden = false;
|
hidden = false;
|
||||||
type = 1;
|
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 // {
|
desc = prJobsets // {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ hosts are deployed automatically from master. The [hydra build server](https://h
|
|||||||
Big changes (like updating flake lock) could be commited to the staging branch first. [Hydra builds staging seperate](https://hydra.dynamicdiscord.de/jobset/malobeo/staging), and on success you can merge into master.
|
Big changes (like updating flake lock) could be commited to the staging branch first. [Hydra builds staging seperate](https://hydra.dynamicdiscord.de/jobset/malobeo/staging), and on success you can merge into master.
|
||||||
|
|
||||||
### deploy fresh host
|
### deploy fresh host
|
||||||
if you want to deploy a completldy new host refer to [docs](https://docs.malobeo.org/anleitung/create.html)
|
if you want to deploy a completly new host refer to [docs](https://docs.malobeo.org/anleitung/create.html)
|
||||||
|
|
||||||
### testing configuration
|
### testing configuration
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
- [musik](./projekte/musik.md)
|
- [musik](./projekte/musik.md)
|
||||||
- [TODO](./todo.md)
|
- [TODO](./todo.md)
|
||||||
- [Modules]()
|
- [Modules]()
|
||||||
- [Gitea-translator](./module/gitea-translator.md)
|
|
||||||
- [Initrd-ssh](./module/initssh.md)
|
- [Initrd-ssh](./module/initssh.md)
|
||||||
- [Disks](./module/disks.md)
|
- [Disks](./module/disks.md)
|
||||||
- [How-to]()
|
- [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
|
|
||||||
@@ -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 ${inputs.self + /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;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -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