Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ berth sets up and looks after agent workstations. These are Ubuntu machines with
| --- | --- |
| `crates/berth/` | The `berth` program, for Linux, macOS and Windows. `main.rs` opens the screens, and `src/cli/` is the command line, the same on every system. In `cli/`, `args.rs` is the grammar in clap and `docs.rs` writes the reference page from it. `client.rs` reaches the server. `ask.rs` asks, `follow.rs` shows progress, and `out.rs` prints. On Linux, `src/local/` adds the commands of the server's own machine and `berth serve` (`src/local/serve/`), behind one `#[cfg(target_os = "linux")]`, and `client_only.rs` stands in for it elsewhere. In `serve/`, `here.rs` is the server in berth's own process that the screens and commands use when no other is set, `actions.rs` has the actions of hosts and of the installation, `keys.rs` the key ring's routes, `provisioners.rs` and `resources.rs` those of provisioners and resources |
| `crates/berth-api/` | Types and the operations table shared by every program (`ops.rs` names each operation, its HTTP route and its role) |
| `crates/berth-core/` | Hosts, profiles, links to hosts, registries and secrets, and plugins. The store is in `store/`. `kept.rs` and `plugin_state.rs` write files from it, and `import.rs` takes in the files of older versions. `kept_profile.rs` is the profile a host keeps of itself and `berth host adopt`. `runner.rs` runs every action as a job. `keys/` is the key ring and how berth logs in to hosts. `host_type.rs` says what a host of each type can do. `provisioner.rs` and `resource.rs` are the provisioners of plugins and what they made |
| `crates/berth-core/` | Hosts, profiles, links to hosts, registries and secrets, and plugins. The store is in `store/`. `kept.rs` and `plugin_state.rs` write files from it, and `import.rs` takes in the files of older versions. `kept_profile.rs` is the profile a host keeps of itself and `berth host adopt`. `runner.rs` runs every action as a job. `keys/` is the key ring and how berth logs in to hosts. `host_type.rs` says what a host of each type can do. `provisioner.rs` and `resource.rs` are the provisioners of plugins and what they made. `simulate.rs` is the world of `berth serve --simulate`: its hosts, its provisioner `sim/cloud` and its seed |
| `crates/berth-tui/` | The parts of the screens with no terminal in them. `fields.rs`, `setup.rs` and `flow.rs` describe a host's set-up once, for the screens' tabs and the command line's prompts and flags alike, and `theme.rs` has the colours both draw with |
| `crates/berth-pty/` | Terminals for sessions |
| `crates/berthd/`, `crates/box/` | The controller on each host and the agent's own tool there |
Expand Down
9 changes: 9 additions & 0 deletions crates/berth-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ pub struct Version {
/// when the host keeps no record.
#[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
pub host_type: Option<HostType>,
/// Whether it is simulated, as `berth serve --simulate` and its hosts
/// are: nothing it does reaches a real machine.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub simulated: bool,
}

impl Version {
Expand Down Expand Up @@ -1014,6 +1018,10 @@ pub struct Config {
pub systemd: Option<bool>,
/// A wrapper that gives the agent its environment.
pub agent_env: String,
/// Whether the host is simulated: in single-user mode its commands then
/// run through `agent_env` too, and its version says so.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub simulated: bool,
}

impl Default for Config {
Expand All @@ -1025,6 +1033,7 @@ impl Default for Config {
units: vec![],
systemd: None,
agent_env: "/usr/local/bin/agent-env".into(),
simulated: false,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/berth-core/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ impl Host {
/// How to open a connection to the host's berthd. `password` is the SSH
/// user's sudo password, for a host that asks for one.
pub fn link(&self, paths: &Paths, password: Option<&str>) -> Result<LinkSpec> {
// A simulated server reaches no machine: each host is a berthd of its own.
if let Some(simulation) = crate::simulate::active() {
return simulation.link(&self.name);
}
// A profile can name the command itself, as for a container:
// ["docker", "exec", "-i", "NAME", "berthd", "connect"].
if let Some(command) = self.access().link {
Expand Down
1 change: 1 addition & 0 deletions crates/berth-core/src/host_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ mod tests {
mode: "system".into(),
applied: None,
host_type,
simulated: false,
};
assert_eq!(seen(Ok(&version(None))), Some(HostType::Managed));
assert_eq!(
Expand Down
1 change: 1 addition & 0 deletions crates/berth-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod seal;
pub mod seed;
pub mod server;
pub mod server_image;
pub mod simulate;
pub mod store;
pub mod tailnet;

Expand Down
2 changes: 2 additions & 0 deletions crates/berth-core/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub mod layout {
pub const CONTROLLER_PLAYBOOK: &str = "provision/ansible/controller.yml";
/// Ansible's settings for that playbook.
pub const ANSIBLE_CONFIG: &str = "provision/ansible.cfg";
/// The controller a host runs, as built into the role's files.
pub const BERTHD: &str = "provision/ansible/roles/devbox/files/bin/berthd";
/// The profile a new host starts from.
pub const EXAMPLE: &str = "provision/config/example.json";
/// Where a source of berth 0.2 and earlier had its builder.
Expand Down
1 change: 1 addition & 0 deletions crates/berth-core/src/rollout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ mod tests {
mode: "system".into(),
applied: self.applied.clone(),
host_type: None,
simulated: false,
}))
}
fn apply(&mut self, _out: &mut dyn Write) -> std::result::Result<(), String> {
Expand Down
Loading
Loading