Prefer 'remote builder' over 'slave'

This commit is contained in:
Graham Christensen 2018-09-07 22:10:56 -04:00 committed by Eelco Dolstra
parent 5b2fdfdca2
commit 0aca1ffb6e
2 changed files with 19 additions and 19 deletions

View file

@ -275,7 +275,7 @@ as a means of providing Nix store access to a restricted ssh user.
<listitem><para>Allow the connected client to request the realization <listitem><para>Allow the connected client to request the realization
of derivations. In effect, this can be used to make the host act of derivations. In effect, this can be used to make the host act
as a build slave.</para></listitem> as a remote builder.</para></listitem>
</varlistentry> </varlistentry>

View file

@ -8,8 +8,8 @@ makeTest (
let let
# The configuration of the build slaves. # The configuration of the remote builders.
slave = builder =
{ config, pkgs, ... }: { config, pkgs, ... }:
{ services.openssh.enable = true; { services.openssh.enable = true;
virtualisation.writableStore = true; virtualisation.writableStore = true;
@ -36,21 +36,21 @@ in
{ {
nodes = nodes =
{ slave1 = slave; { builder1 = builder;
slave2 = slave; builder2 = builder;
client = client =
{ config, pkgs, ... }: { config, pkgs, ... }:
{ nix.maxJobs = 0; # force remote building { nix.maxJobs = 0; # force remote building
nix.distributedBuilds = true; nix.distributedBuilds = true;
nix.buildMachines = nix.buildMachines =
[ { hostName = "slave1"; [ { hostName = "builder1";
sshUser = "root"; sshUser = "root";
sshKey = "/root/.ssh/id_ed25519"; sshKey = "/root/.ssh/id_ed25519";
system = "i686-linux"; system = "i686-linux";
maxJobs = 1; maxJobs = 1;
} }
{ hostName = "slave2"; { hostName = "builder2";
sshUser = "root"; sshUser = "root";
sshKey = "/root/.ssh/id_ed25519"; sshKey = "/root/.ssh/id_ed25519";
system = "i686-linux"; system = "i686-linux";
@ -75,33 +75,33 @@ in
$client->copyFileFromHost("key", "/root/.ssh/id_ed25519"); $client->copyFileFromHost("key", "/root/.ssh/id_ed25519");
$client->succeed("chmod 600 /root/.ssh/id_ed25519"); $client->succeed("chmod 600 /root/.ssh/id_ed25519");
# Install the SSH key on the slaves. # Install the SSH key on the builders.
$client->waitForUnit("network.target"); $client->waitForUnit("network.target");
foreach my $slave ($slave1, $slave2) { foreach my $builder ($builder1, $builder2) {
$slave->succeed("mkdir -p -m 700 /root/.ssh"); $builder->succeed("mkdir -p -m 700 /root/.ssh");
$slave->copyFileFromHost("key.pub", "/root/.ssh/authorized_keys"); $builder->copyFileFromHost("key.pub", "/root/.ssh/authorized_keys");
$slave->waitForUnit("sshd"); $builder->waitForUnit("sshd");
$client->succeed("ssh -o StrictHostKeyChecking=no " . $slave->name() . " 'echo hello world'"); $client->succeed("ssh -o StrictHostKeyChecking=no " . $builder->name() . " 'echo hello world'");
} }
# Perform a build and check that it was performed on the slave. # Perform a build and check that it was performed on the builder.
my $out = $client->succeed( my $out = $client->succeed(
"nix-build ${expr nodes.client.config 1} 2> build-output", "nix-build ${expr nodes.client.config 1} 2> build-output",
"grep -q Hello build-output" "grep -q Hello build-output"
); );
$slave1->succeed("test -e $out"); $builder1->succeed("test -e $out");
# And a parallel build. # And a parallel build.
my ($out1, $out2) = split /\s/, my ($out1, $out2) = split /\s/,
$client->succeed('nix-store -r $(nix-instantiate ${expr nodes.client.config 2})\!out $(nix-instantiate ${expr nodes.client.config 3})\!out'); $client->succeed('nix-store -r $(nix-instantiate ${expr nodes.client.config 2})\!out $(nix-instantiate ${expr nodes.client.config 3})\!out');
$slave1->succeed("test -e $out1 -o -e $out2"); $builder1->succeed("test -e $out1 -o -e $out2");
$slave2->succeed("test -e $out1 -o -e $out2"); $builder2->succeed("test -e $out1 -o -e $out2");
# And a failing build. # And a failing build.
$client->fail("nix-build ${expr nodes.client.config 5}"); $client->fail("nix-build ${expr nodes.client.config 5}");
# Test whether the build hook automatically skips unavailable slaves. # Test whether the build hook automatically skips unavailable builders.
$slave1->block; $builder1->block;
$client->succeed("nix-build ${expr nodes.client.config 4}"); $client->succeed("nix-build ${expr nodes.client.config 4}");
''; '';