* Downloading closures.

This commit is contained in:
Eelco Dolstra 2008-11-18 14:48:40 +00:00
parent 9f1f939226
commit f6462ff5bb
6 changed files with 82 additions and 2 deletions

View file

@ -13,7 +13,10 @@ use Catalyst qw/-Debug
/; /;
our $VERSION = '0.01'; our $VERSION = '0.01';
__PACKAGE__->config( name => 'HydraFrontend' ); __PACKAGE__->config(
name => 'HydraFrontend',
default_view => "TT"
);
__PACKAGE__->setup(); __PACKAGE__->setup();

View file

@ -3,6 +3,7 @@ package HydraFrontend::Controller::Root;
use strict; use strict;
use warnings; use warnings;
use parent 'Catalyst::Controller'; use parent 'Catalyst::Controller';
use HydraFrontend::Helper::Nix;
# #
# Sets the actions in this controller to be registered with no prefix # Sets the actions in this controller to be registered with no prefix
@ -391,7 +392,13 @@ sub closure :Local {
my $product = $build->buildproducts->find({productnr => $productnr}); my $product = $build->buildproducts->find({productnr => $productnr});
return error($c, "Build $buildId doesn't have a product $productnr.") if !defined $product; return error($c, "Build $buildId doesn't have a product $productnr.") if !defined $product;
return error($c, "Not yet implemented."); return error($c, "Product is not a Nix build.") if $product->type ne "nix-build";
return error($c, "Path " . $product->path . " is no longer available.") unless HydraFrontend::Helper::Nix::isValidPath($product->path);
$c->stash->{current_view} = 'HydraFrontend::View::NixClosure';
$c->stash->{storePath} = $product->path;
$c->stash->{name} = $build->nixname;
} }

View file

@ -0,0 +1,14 @@
package HydraFrontend::Helper::Nix;
use strict;
sub isValidPath {
my $path = shift;
$SIG{CHLD} = 'DEFAULT'; # !!! work around system() failing if SIGCHLD is ignored
return system("nix-store --check-validity $path") == 0;
}
1;

View file

@ -0,0 +1,26 @@
package HydraFrontend::View::NixClosure;
use strict;
use base qw/Catalyst::View/;
use IO::Pipe;
use POSIX qw(dup2);
sub process {
my ( $self, $c ) = @_;
$c->response->content_type('application/x-nix-export');
$c->response->header('Content-Disposition' => 'attachment; filename=' . $c->stash->{name} . '.closure.gz');
my $storePath = $c->stash->{storePath};
open(OUTPUT, "nix-store --export `nix-store -qR $storePath` | gzip |");
my $fh = new IO::Handle;
$fh->fdopen(fileno(OUTPUT), "r") or die;
$c->response->body($fh);
return 1;
}
1;

View file

@ -1,5 +1,6 @@
[% WRAPPER layout.tt title="Hydra Overview" %] [% WRAPPER layout.tt title="Hydra Overview" %]
[% PROCESS common.tt %] [% PROCESS common.tt %]
[% USE HTML %]
[% USE date %] [% USE date %]
[% USE mibs=format("%.2f") %] [% USE mibs=format("%.2f") %]
@ -205,6 +206,24 @@
<img src="/static/images/nix-build.png" alt="Source" /> <img src="/static/images/nix-build.png" alt="Source" />
Nix build of path <tt>[% product.path %]</tt> Nix build of path <tt>[% product.path %]</tt>
</a> </a>
[<a class="productDetailsToggle" href="javascript:">help</a>]
<div class="help productDetails">
<p>If you have Nix installed on your machine, this build and all
its dependencies can be unpacked into your local Nix store by
doing:</p>
<pre>$ gunzip < [% HTML.escape(build.nixname) %].closure.gz | nix-store --import</pre>
or to download and unpack in one command:
<pre>$ curl [% c.uri_for('/closure' build.id product.productnr) %] | gunzip | nix-store --import</pre>
<p>The package can then be found in the path <tt>[%
product.path %]</tt>. If you get the error message “imported
archive lacks a signature”, you should make sure that you have
sufficient access rights to the Nix store, e.g., run the
command as <tt>root</tt>.</p>
</div>
[% CASE "file" %] [% CASE "file" %]
<a href="[% c.uri_for('/download' build.id product.productnr product.name) %]"> <a href="[% c.uri_for('/download' build.id product.productnr product.name) %]">

View file

@ -205,6 +205,17 @@ div.jobset-edit h3, div.jobset h3 {
margin-top: 0.5em; margin-top: 0.5em;
} }
div.help {
border: solid black 1px;
padding-left: 1em;
padding-right: 1em;
}
div.help pre {
padding-left: 1.5em;
color: #400000;
}
/* Sortable tables */ /* Sortable tables */