Skip to content

Commit e0087b6

Browse files
committed
agent: support multiple architectures
Preload `wire` with the supported architectures and it will copy its arch-specific agent store path to the nodes.
1 parent 21eafe3 commit e0087b6

File tree

4 files changed

+56
-27
lines changed

4 files changed

+56
-27
lines changed

wire/agent/default.nix

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
{
2-
perSystem =
3-
{
4-
buildRustProgram,
5-
...
6-
}:
7-
{
8-
packages = {
9-
agent = buildRustProgram {
10-
name = "agent";
11-
pname = "agent";
12-
cargoExtraArgs = "-p agent";
13-
};
14-
};
15-
};
2+
config,
3+
withSystem,
4+
lib,
5+
...
6+
}:
7+
{
8+
9+
flake.packages =
10+
# macos is not supported with the agent
11+
lib.genAttrs (builtins.filter (system: !lib.hasSuffix "darwin" system) config.systems)
12+
13+
(
14+
system:
15+
withSystem system (
16+
{ buildRustProgram, ... }:
17+
{
18+
agent = buildRustProgram {
19+
name = "agent";
20+
pname = "agent";
21+
cargoExtraArgs = "-p agent";
22+
};
23+
}
24+
)
25+
);
1626
}

wire/cli/default.nix

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
{ self, ... }:
12
{
23
perSystem =
34
{
45
pkgs,
6+
lib,
57
self',
68
buildRustProgram,
79
...
@@ -29,11 +31,19 @@
2931
nativeBuildInputs = [
3032
pkgs.makeWrapper
3133
];
32-
postBuild = ''
33-
wrapProgram $out/bin/wire \
34-
--set WIRE_RUNTIME ${../../runtime} \
35-
--set WIRE_AGENT ${self'.packages.agent}
36-
'';
34+
postBuild =
35+
let
36+
agents = lib.mapAttrsToList (name: value: {
37+
inherit name;
38+
path = value.agent;
39+
}) (lib.filterAttrs (_: value: value ? agent) self.packages);
40+
41+
in
42+
''
43+
wrapProgram $out/bin/wire \
44+
--set WIRE_RUNTIME ${../../runtime} \
45+
--set WIRE_AGENT ${pkgs.linkFarm "wire-agents-farm" agents}
46+
'';
3747
meta.mainProgram = "wire";
3848
};
3949
};

wire/lib/src/hive/key.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use prost::Message;
44
use serde::{Deserialize, Serialize};
55
use std::env;
66
use std::fmt::Display;
7+
use std::path::Path;
78
use std::pin::Pin;
89
use std::process::{ExitStatus, Stdio};
910
use std::str::from_utf8;
@@ -284,14 +285,22 @@ impl ExecuteStep for PushAgentStep {
284285
}
285286

286287
async fn execute(&self, ctx: &mut Context<'_>) -> Result<(), HiveLibError> {
287-
let agent_directory = match env::var_os("WIRE_AGENT") {
288-
Some(agent) => agent.into_string().unwrap(),
289-
None => panic!("WIRE_AGENT environment variable not set"),
290-
};
288+
let mut agent_directory = PathBuf::from(
289+
env::var_os("WIRE_AGENT")
290+
.expect("WIRE_AGENT environment variable not set!")
291+
.into_string()
292+
.unwrap(),
293+
);
294+
295+
agent_directory.push(ctx.node.system.as_str());
296+
297+
let path = String::from(agent_directory.to_str().unwrap());
298+
299+
debug!("agent path: {path}");
291300

292-
push(ctx.node, ctx.name, Push::Path(&agent_directory)).await?;
301+
push(ctx.node, ctx.name, Push::Path(&path)).await?;
293302

294-
ctx.state.agent_directory = Some(agent_directory);
303+
ctx.state.agent_directory = Some(path);
295304

296305
Ok(())
297306
}

wire/lib/src/hive/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub struct Node {
6262
#[serde()]
6363
// system is the architecture of the host, this is mainly used for
6464
// determining the correct binary to push to the host's machine.
65-
pub system: Option<String>,
65+
pub system: String,
6666
}
6767

6868
#[cfg(test)]
@@ -74,7 +74,7 @@ impl Default for Node {
7474
tags: im::HashSet::new(),
7575
allow_local_deployment: true,
7676
build_remotely: false,
77-
system: None,
77+
system: String::from("x86_64-linux"),
7878
}
7979
}
8080
}

0 commit comments

Comments
 (0)