* Support multiple system types per remote machine, e.g. a machine
list like root@example.org x86_64-linux /root/.ssh/id_buildfarm 1 root@example.org i686-darwin /root/.ssh/id_buildfarm 1 This is possible when the Nix installation on example.org itself has remote builds enabled.
This commit is contained in:
parent
63b8f09d8d
commit
9fd9c4c635
1 changed files with 24 additions and 24 deletions
|
@ -52,10 +52,7 @@ decline if $amWilling && ($localSystem eq $neededSystem);
|
||||||
|
|
||||||
|
|
||||||
# Otherwise find a willing remote machine.
|
# Otherwise find a willing remote machine.
|
||||||
my %machines;
|
my @machines;
|
||||||
my %systemTypes;
|
|
||||||
my %sshKeys;
|
|
||||||
my %maxJobs;
|
|
||||||
my %curJobs;
|
my %curJobs;
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,10 +64,12 @@ while (<CONF>) {
|
||||||
s/\#.*$//g;
|
s/\#.*$//g;
|
||||||
next if /^\s*$/;
|
next if /^\s*$/;
|
||||||
/^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s*$/ or die;
|
/^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s*$/ or die;
|
||||||
$machines{$1} = "";
|
push @machines,
|
||||||
$systemTypes{$1} = $2;
|
{ hostName => $1
|
||||||
$sshKeys{$1} = $3;
|
, systemType => $2
|
||||||
$maxJobs{$1} = $4;
|
, sshKeys => $3
|
||||||
|
, maxJobs => $4
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
close CONF;
|
close CONF;
|
||||||
|
@ -85,15 +84,15 @@ flock(MAINLOCK, LOCK_EX) or die;
|
||||||
# Find a suitable system.
|
# Find a suitable system.
|
||||||
my $rightType = 0;
|
my $rightType = 0;
|
||||||
my $machine;
|
my $machine;
|
||||||
LOOP: foreach my $cur (keys %machines) {
|
LOOP: foreach my $cur (@machines) {
|
||||||
if ($neededSystem eq $systemTypes{$cur}) {
|
if ($neededSystem eq $cur->{systemType}) {
|
||||||
$rightType = 1;
|
$rightType = 1;
|
||||||
|
|
||||||
# We have a machine of the right type. Try to get a lock on
|
# We have a machine of the right type. Try to get a lock on
|
||||||
# one of the machine's lock files.
|
# one of the machine's lock files.
|
||||||
my $slot = 0;
|
my $slot = 0;
|
||||||
while ($slot < $maxJobs{$cur}) {
|
while ($slot < $cur->{maxJobs}) {
|
||||||
my $slotLock = "$currentLoad/$cur-$slot";
|
my $slotLock = "$currentLoad/" . $cur->{systemType} . "-" . $cur->{hostName} . "-$slot";
|
||||||
open SLOTLOCK, ">>$slotLock" or die;
|
open SLOTLOCK, ">>$slotLock" or die;
|
||||||
if (flock(SLOTLOCK, LOCK_EX | LOCK_NB)) {
|
if (flock(SLOTLOCK, LOCK_EX | LOCK_NB)) {
|
||||||
$machine = $cur;
|
$machine = $cur;
|
||||||
|
@ -132,7 +131,8 @@ if ($x ne "okay") {
|
||||||
|
|
||||||
|
|
||||||
# Do the actual job.
|
# Do the actual job.
|
||||||
print "BUILDING REMOTE: $drvPath on $machine\n";
|
my $hostName = $machine->{hostName};
|
||||||
|
print "BUILDING REMOTE: $drvPath on $hostName\n";
|
||||||
|
|
||||||
# Make sure that we don't get any SSH passphrase or host key popups -
|
# Make sure that we don't get any SSH passphrase or host key popups -
|
||||||
# if there is any problem it should fail, not do something
|
# if there is any problem it should fail, not do something
|
||||||
|
@ -141,10 +141,10 @@ $ENV{"DISPLAY"} = "";
|
||||||
$ENV{"SSH_PASSWORD_FILE="} = "";
|
$ENV{"SSH_PASSWORD_FILE="} = "";
|
||||||
$ENV{"SSH_ASKPASS="} = "";
|
$ENV{"SSH_ASKPASS="} = "";
|
||||||
|
|
||||||
my $sshOpts = "-i $sshKeys{$machine} -x";
|
my $sshOpts = "-i " . $machine->{sshKeys} . " -x";
|
||||||
|
|
||||||
# Hack to support Cygwin: if we login without a password, we don't
|
# Hack to support Cygwin: if we login without a password, we don't
|
||||||
# have exactly the same right as when we do. This causes the
|
# have exactly the same rights as when we do. This causes the
|
||||||
# Microsoft C compiler to fail with certain flags:
|
# Microsoft C compiler to fail with certain flags:
|
||||||
#
|
#
|
||||||
# http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99676
|
# http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99676
|
||||||
|
@ -154,8 +154,8 @@ my $sshOpts = "-i $sshKeys{$machine} -x";
|
||||||
# password. (It only calls this command when there is no controlling
|
# password. (It only calls this command when there is no controlling
|
||||||
# terminal, but Nix ensures that is is the case. When doing this
|
# terminal, but Nix ensures that is is the case. When doing this
|
||||||
# manually, use setsid(1).)
|
# manually, use setsid(1).)
|
||||||
if ($sshKeys{$machine} =~ /^password:/) {
|
if ($machine->{sshKeys} =~ /^password:/) {
|
||||||
my $passwordFile = $sshKeys{$machine};
|
my $passwordFile = $machine->{sshKeys};
|
||||||
$passwordFile =~ s/^password://;
|
$passwordFile =~ s/^password://;
|
||||||
$sshOpts = "ssh -x";
|
$sshOpts = "ssh -x";
|
||||||
$ENV{"SSH_PASSWORD_FILE"} = $passwordFile;
|
$ENV{"SSH_PASSWORD_FILE"} = $passwordFile;
|
||||||
|
@ -178,22 +178,22 @@ print "COPYING INPUTS...\n";
|
||||||
my $maybeSign = "";
|
my $maybeSign = "";
|
||||||
$maybeSign = "--sign" if -e "/nix/etc/nix/signing-key.sec";
|
$maybeSign = "--sign" if -e "/nix/etc/nix/signing-key.sec";
|
||||||
|
|
||||||
system("NIX_SSHOPTS=\"$sshOpts\" nix-copy-closure $machine $maybeSign $drvPath $inputs") == 0
|
system("NIX_SSHOPTS=\"$sshOpts\" nix-copy-closure $hostName $maybeSign $drvPath $inputs") == 0
|
||||||
or die "cannot copy inputs to $machine: $?";
|
or die "cannot copy inputs to $hostName: $?";
|
||||||
|
|
||||||
print "BUILDING...\n";
|
print "BUILDING...\n";
|
||||||
|
|
||||||
system("ssh $sshOpts $machine 'nix-store -rvvK $drvPath'") == 0
|
system("ssh $sshOpts $hostName 'nix-store -rvvK $drvPath'") == 0
|
||||||
or die "remote build on $machine failed: $?";
|
or die "remote build on $hostName failed: $?";
|
||||||
|
|
||||||
print "REMOTE BUILD DONE: $drvPath on $machine\n";
|
print "REMOTE BUILD DONE: $drvPath on $hostName\n";
|
||||||
|
|
||||||
foreach my $output (split '\n', $outputs) {
|
foreach my $output (split '\n', $outputs) {
|
||||||
my $maybeSignRemote = "";
|
my $maybeSignRemote = "";
|
||||||
$maybeSignRemote = "--sign" if $UID != 0;
|
$maybeSignRemote = "--sign" if $UID != 0;
|
||||||
|
|
||||||
system("ssh $sshOpts $machine 'nix-store --export $maybeSignRemote $output' > dump") == 0
|
system("ssh $sshOpts $hostName 'nix-store --export $maybeSignRemote $output' > dump") == 0
|
||||||
or die "cannot copy $output from $machine: $?";
|
or die "cannot copy $output from $hostName: $?";
|
||||||
|
|
||||||
# This doesn't work yet, since the caller has a lock on the output
|
# This doesn't work yet, since the caller has a lock on the output
|
||||||
# path. We should move towards lock-free invocation of build
|
# path. We should move towards lock-free invocation of build
|
||||||
|
|
Loading…
Reference in a new issue