diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index bde1030e..f00eecf8 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -137,6 +137,15 @@ sub view_log : Chained('buildChain') PathPart('log') { } +sub view_runcommand_log : Chained('buildChain') PathPart('runcommand-log') { + my ($self, $c, $sha) = @_; + + $c->stash->{is_runcommand} = 1; + $c->stash->{log_uri} = $c->uri_for($c->controller('Root')->action_for("runcommandlog"), $sha . "-" . $c->stash->{build}->id); + $c->stash->{template} = 'log.tt'; +} + + sub showLog { my ($c, $mode, $finished, $drvPath) = @_; $mode //= "pretty"; diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 2d8224a5..abb95c7c 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -7,6 +7,7 @@ use base 'Hydra::Base::Controller::ListBuilds'; use Hydra::Helper::Nix; use Hydra::Helper::CatalystUtils; use Hydra::View::TT; +use Hydra::Model::DB; use Nix::Store; use Nix::Config; use Encode; @@ -530,4 +531,20 @@ sub log :Local :Args(1) { } } +sub runcommandlog :Local :Args(1) { + my ($self, $c, $filename) = @_; + + my $tail = $c->request->params->{"tail"}; + + die if defined $tail && $tail !~ /^[0-9]+$/; + + my $logFile = Hydra::Model::DB::getHydraPath . "/runcommand-logs/" . substr($filename, 0, 2) . "/$filename"; + if (-f $logFile) { + serveLogFile($c, $logFile, $tail); + return; + } else { + notFound($c, "The RunCommand log is not available."); + } +} + 1; diff --git a/src/lib/Hydra/Schema/Result/RunCommandLogs.pm b/src/lib/Hydra/Schema/Result/RunCommandLogs.pm index b74416e8..66fa9c56 100644 --- a/src/lib/Hydra/Schema/Result/RunCommandLogs.pm +++ b/src/lib/Hydra/Schema/Result/RunCommandLogs.pm @@ -152,6 +152,8 @@ __PACKAGE__->belongs_to( # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9AIzlQl1RjRXrs9gQCZKVw use POSIX qw(WEXITSTATUS WIFEXITED WIFSIGNALED WTERMSIG); +use Digest::SHA1 qw(sha1_hex); +use Hydra::Model::DB; =head2 started @@ -321,3 +323,29 @@ sub did_fail_with_exec_error { } 1; + +=head2 log_relative_url + +Returns the URL to the log file relative to the build it belongs to. + +Return: + +* The relative URL if a log file exists +* An empty string otherwise +=cut +sub log_relative_url() { + my ($self) = @_; + + # Do not return a URL when there is no build yet + if (not defined($self->start_time)) { + return ""; + } + + my $sha = sha1_hex($self->command); + # Do not return a URL when there is no log file yet + if (not -f Hydra::Model::DB::getHydraPath . "/runcommand-logs/" . substr($sha, 0, 2) . "/$sha-" . $self->build_id) { + return ""; + } + + return "runcommand-log/$sha"; +} diff --git a/src/root/build.tt b/src/root/build.tt index dc58f191..ba122667 100644 --- a/src/root/build.tt +++ b/src/root/build.tt @@ -525,9 +525,9 @@ END; [% IF runcommandlog.start_time != undef %]
Started at [% INCLUDE renderDateTime timestamp = runcommandlog.start_time; %]
[% IF runcommandlog.end_time != undef %] -
Ran for [% INCLUDE renderDuration duration = runcommandlog.end_time - runcommandlog.start_time %]
+
Ran for [% INCLUDE renderDuration duration = runcommandlog.end_time - runcommandlog.start_time %][% IF runcommandlog.log_relative_url() %] â€” Logs[% END %]
[% ELSE %] -
Running for [% INCLUDE renderDuration duration = curTime - runcommandlog.start_time %]
+
Running for [% INCLUDE renderDuration duration = curTime - runcommandlog.start_time %][% IF runcommandlog.log_relative_url() %] â€” Logs[% END %]
[% END %] [% ELSE %]
Pending
diff --git a/src/root/log.tt b/src/root/log.tt index 8bb4954d..4874fa77 100644 --- a/src/root/log.tt +++ b/src/root/log.tt @@ -1,6 +1,6 @@ [% WRAPPER layout.tt - titleHTML="Log of " _ (step ? " step $step.stepnr of " : "") _ "build ${build.id} of job " _ linkToJob(build.jobset, job) - title="Log of " _ (step ? " step $step.stepnr of " : "") _ "build ${build.id} of job " _ makeNameTextForJob(build.jobset, job) + titleHTML=(is_runcommand ? "RunCommand log of " : "Log of ") _ (step ? " step $step.stepnr of " : "") _ "build ${build.id} of job " _ linkToJob(build.jobset, job) + title=(is_runcommand ? "RunCommand log of " : "Log of ") _ (step ? " step $step.stepnr of " : "") _ "build ${build.id} of job " _ makeNameTextForJob(build.jobset, job) %] [% PROCESS common.tt %] @@ -11,7 +11,7 @@ [% ELSE %] is [% END %] - the build log of derivation [% IF step; step.drvpath; ELSE; build.drvpath; END %]. + [% IF is_runcommand %] the output of a RunCommand execution of[% ELSE %] the build log of[% END %] derivation [% IF step; step.drvpath; ELSE; build.drvpath; END %]. [% IF step && step.machine %] It was built on [% step.machine %]. [% END %]