From ceff5c5cfeaf211691f4d1156f358a940b5ef7b4 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Mon, 12 Feb 2024 18:30:03 +0100 Subject: [PATCH 1/5] flake: fix gitea integration test This is an integration test that confirms that jobset definitions from git repositories are correctly built and status updates pushed to the gitea instance. The following things needed to be fixed: * We're still on 23.05 where gitea is marked as insecure. Not going to update nixpkgs right now, but going for the quick fix. * Since gitea 1.19 tokens have scopes that describe what's possible. Not specifying the scope in the DB appears to imply that no permissions are granted. * Apparently we have three status updates now (for three status hooks, queued/started/finished). No idea why that was broken before, but the behavior still looks correct. --- flake.nix | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 306ed292..a6dfb977 100644 --- a/flake.nix +++ b/flake.nix @@ -180,13 +180,9 @@ root=d7f16a3412e01a43a414535b16007c6931d3a9c7 ''; + nixpkgs.config.permittedInsecurePackages = [ "gitea-1.19.4" ]; nix = { - distributedBuilds = true; - buildMachines = [{ - hostName = "localhost"; - systems = [ system ]; - }]; - binaryCaches = [ ]; + settings.substituters = [ ]; }; services.gitea = { enable = true; @@ -202,7 +198,7 @@ testScript = let scripts.mktoken = pkgs.writeText "token.sql" '' - INSERT INTO access_token (id, uid, name, created_unix, updated_unix, token_hash, token_salt, token_last_eight) VALUES (1, 1, 'hydra', 1617107360, 1617107360, 'a930f319ca362d7b49a4040ac0af74521c3a3c3303a86f327b01994430672d33b6ec53e4ea774253208686c712495e12a486', 'XRjWE9YW0g', '31d3a9c7'); + INSERT INTO access_token (id, uid, name, created_unix, updated_unix, token_hash, token_salt, token_last_eight, scope) VALUES (1, 1, 'hydra', 1617107360, 1617107360, 'a930f319ca362d7b49a4040ac0af74521c3a3c3303a86f327b01994430672d33b6ec53e4ea774253208686c712495e12a486', 'XRjWE9YW0g', '31d3a9c7', 'all'); ''; scripts.git-setup = pkgs.writeShellScript "setup.sh" '' @@ -357,9 +353,10 @@ response = json.loads(data) - assert len(response) == 2, "Expected exactly two status updates for latest commit!" - assert response[0]['status'] == "success", "Expected latest status to be success!" - assert response[1]['status'] == "pending", "Expected first status to be pending!" + assert len(response) == 3, "Expected exactly three status updates for latest commit (queued, started, finished)!" + assert response[0]['status'] == "success", "Expected finished status to be success!" + assert response[1]['status'] == "pending", "Expected started status to be pending!" + assert response[2]['status'] == "pending", "Expected queued status to be pending!" machine.shutdown() ''; From 9db5d0a88daee61b8b4507e517d53cab7377a70d Mon Sep 17 00:00:00 2001 From: K900 Date: Fri, 23 Feb 2024 14:02:36 +0300 Subject: [PATCH 2/5] urlencode drv names when fetching logs Otherwise names with special characters like + break things. --- src/lib/Hydra/Controller/Build.pm | 5 +++-- src/lib/Hydra/Controller/Root.pm | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index c3869838..6b25ff80 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -15,6 +15,7 @@ use Nix::Config; use List::SomeUtils qw(all); use Encode; use JSON::PP; +use WWW::Form::UrlEncoded::PP qw(); use feature 'state'; @@ -141,7 +142,7 @@ sub view_nixlog : Chained('buildChain') PathPart('nixlog') { $c->stash->{step} = $step; my $drvPath = $step->drvpath; - my $log_uri = $c->uri_for($c->controller('Root')->action_for("log"), [basename($drvPath)]); + my $log_uri = $c->uri_for($c->controller('Root')->action_for("log"), [WWW::Form::UrlEncoded::PP::url_encode(basename($drvPath))]); showLog($c, $mode, $log_uri); } @@ -150,7 +151,7 @@ sub view_log : Chained('buildChain') PathPart('log') { my ($self, $c, $mode) = @_; my $drvPath = $c->stash->{build}->drvpath; - my $log_uri = $c->uri_for($c->controller('Root')->action_for("log"), [basename($drvPath)]); + my $log_uri = $c->uri_for($c->controller('Root')->action_for("log"), [WWW::Form::UrlEncoded::PP::url_encode(basename($drvPath))]); showLog($c, $mode, $log_uri); } diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 548cfac3..e6c3049f 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -16,6 +16,7 @@ use List::Util qw[min max]; use List::SomeUtils qw{any}; use Net::Prometheus; use Types::Standard qw/StrMatch/; +use WWW::Form::UrlEncoded::PP qw(); use constant NARINFO_REGEX => qr{^([a-z0-9]{32})\.narinfo$}; # e.g.: https://hydra.example.com/realisations/sha256:a62128132508a3a32eef651d6467695944763602f226ac630543e947d9feb140!out.doi @@ -553,7 +554,7 @@ sub log :Local :Args(1) { my $logPrefix = $c->config->{log_prefix}; if (defined $logPrefix) { - $c->res->redirect($logPrefix . "log/" . basename($drvPath)); + $c->res->redirect($logPrefix . "log/" . WWW::Form::UrlEncoded::PP::url_encode(basename($drvPath))); } else { notFound($c, "The build log of $drvPath is not available."); } From 669617ab54a667623fdbbc07dfd7354b5d66286b Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Thu, 7 Mar 2024 18:44:13 +0100 Subject: [PATCH 3/5] Use `submit` event in login form It's a pet peeve from me when logging into my personal Hydra that I always have to press the button rather than hitting Return after entering my password. Reason for that is that the form doesn't have a "submit" button, so far it was always listened to the "click" event. Submit does that and you can hit Return alternatively. --- src/root/auth.tt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/root/auth.tt b/src/root/auth.tt index d1539765..d49ba5bd 100644 --- a/src/root/auth.tt +++ b/src/root/auth.tt @@ -33,7 +33,7 @@