diff --git a/.agents/skills/README.md b/.agents/skills/README.md
index b688d36..e07c74a 100644
--- a/.agents/skills/README.md
+++ b/.agents/skills/README.md
@@ -6,6 +6,6 @@ has the instructions in Markdown.
| Skill | Use it to |
| --- | --- |
-| [`install-berth`](install-berth/SKILL.md) | Install the berth client, a berth server, an Incus and Docker host, or Ubuntu on a server from a rescue system |
+| [`install-berth`](install-berth/SKILL.md) | Install the berth client, a berth server, a node for Incus and Docker machines, or Ubuntu on a server from a rescue system |
`.claude/skills` is a link to this folder, so Claude Code finds the same skills.
diff --git a/.agents/skills/install-berth/SKILL.md b/.agents/skills/install-berth/SKILL.md
index bfeda7a..55399e6 100644
--- a/.agents/skills/install-berth/SKILL.md
+++ b/.agents/skills/install-berth/SKILL.md
@@ -1,6 +1,6 @@
---
name: install-berth
-description: "Use when installing or setting up berth. That covers the client, a berth server and an Incus and Docker host for machines. It also covers a server installed from a provider's rescue system. Covers which recipe to pick, the exact commands, what is destructive, and how to hand the server over to the user."
+description: "Use when installing or setting up berth. That covers the client, a berth server and a node, a server that hosts Incus and Docker machines. It also covers a server installed from a provider's rescue system. Covers which recipe to pick, the exact commands, what is destructive, and how to hand the server over to the user."
---
# Install berth
@@ -14,8 +14,9 @@ terminal. A set-up has these pieces:
| --- | --- |
| `berth` client | The program on the user's machine. It has a terminal UI and commands. |
| berth server | Optional. `berth serve`, usually in a Docker container, reached over a tailnet with TLS. It keeps the hosts, profiles and secrets. |
-| Host | A machine berth works with, at one of three levels. `reachable` means berth only logs in, `controller` adds berthd and box, and `workstation` is set up from a profile. A machine that exists is added with `berth host add NAME ADDRESS --user USER`. |
-| Provisioner | Creates the machine for a host, such as on Docker or Incus. Plugins bring the types `docker/container`, `incus/vm` and `incus/container`, and berth runs each provisioner under a name of its own, registered with `berth provisioner add NAME TYPE`. The `incus-host` recipe registers `incus-vm`, `incus-container` and `docker`. `berth provisioner` lists them, and the Provisioners tab of the terminal UI (key `2`) shows each one's page. |
+| Host | A machine berth logs in to over SSH. Its type is one of four: `ssh` means berth only logs in, `managed` adds berthd and box, `node` is a server berth applies without a desktop, and `workstation` is set up from a profile. A machine that exists is added with `berth host add NAME ADDRESS --user USER`. |
+| Node | A server for machines. Its features `incus/server` and `docker/engine` install Incus and Docker, and after the apply berth registers their provisioners, such as `big-incus-vm`, `big-incus-container` and `big-docker-container`. |
+| Provisioner | Creates the machine for a host, such as on Docker or Incus. Plugins bring the types `docker/container`, `incus/vm` and `incus/container`, and berth runs each provisioner under a name of its own, registered with `berth provisioner add NAME TYPE` or by a node. `berth provisioner list` lists them, and the Provisioners tab of the terminal UI (key `2`) shows each one's page. |
## Where to look things up
@@ -24,21 +25,23 @@ terminal. A set-up has these pieces:
| `README.md` | Installing the client |
| `docs/content/docs/(guide)/start/quick-start.mdx` | A first host from the terminal UI |
| `docs/content/docs/(guide)/use/server.mdx` | Running a server and connecting to it |
-| `docs/content/docs/(guide)/use/levels.mdx` | Host levels, and adding a machine by its address |
+| `docs/content/docs/(guide)/use/types.mdx` | Host types, and adding a machine by its address |
+| `docs/content/docs/(guide)/use/nodes.mdx` | Nodes, which are servers for Incus and Docker machines, and taking in one that exists |
| `docs/content/docs/(guide)/use/store.mdx` | Where a server keeps its state, and restoring it |
| `docs/content/docs/(guide)/deploy/index.mdx` | The install methods |
| `docs/content/docs/(guide)/deploy/provisioners.mdx` | Creating a host's machine with a provisioner |
| `recipes/README.md` | The list of recipes |
| `recipes/*/README.md` | One recipe, with what it needs, its command and its settings |
-| `plugins/incus/guide.md`, `plugins/docker/guide.md` | The provisioners and their arguments |
+| `plugins/incus/guide.md`, `plugins/docker/guide.md` | The provisioners and their arguments, and the settings of the features `incus/server` and `docker/engine` |
| `AGENTS.md` | Working in this repository |
## Choosing a set-up
| The user has or wants | Follow |
| --- | --- |
-| A rented dedicated server whose installer fails | `rescue-install`, then `incus-host` |
-| An empty server to host many machines | `incus-host`. Add `berth_server=true` to run the server there too. |
+| A rented dedicated server whose installer fails | `rescue-install`, then add it as a node |
+| An empty server to host many machines | Add it as a node with the features `incus/server` and `docker/engine`. To run the server there too, `berth-server` with `berth_server_node=true` first. |
+| A server the old `incus-host` recipe set up | Add it as a node with the same features. They keep its pools, bridge, trust and guests. |
| A small VM just for the server | `berth-server` |
| Only a client | The install instructions in `README.md` and the quick start |
@@ -69,50 +72,37 @@ Find the disks with `lsblk` first. Afterwards the user sets the server to start
from its disk in the provider's panel, restarts it and logs in over SSH. A
second run would wipe the disks again, so there is no reason to repeat it.
-### `incus-host`
+### A node for machines
-Turns an empty Ubuntu server into a host for machines. It installs Incus with QEMU and Docker,
-and sets up a btrfs storage pool, the bridge `incusbr0` and a `ufw` firewall. berth creates
-its hosts there as Incus guests. It needs Ubuntu 24.04 or later, run as root on
-the server, from a fresh install. It does not wipe anything.
+berth applies a node itself, with no recipe. It needs Ubuntu 24.04 or later on
+x86_64 and a login as root or as an account with sudo. On the user's own
+machine, or on a berth connected to their server, with the made-up name `big`:
```bash
-curl -fsSL https://github.com/helightdev/berth/archive/refs/heads/main.tar.gz \
- | tar xz --strip-components=1 --wildcards '*/recipes'
-cd recipes/incus-host
-sudo ./install.sh -e tailscale_auth_key=tskey-auth-EXAMPLE
-```
-
-To run a berth server on the same machine:
-
-```bash
-sudo ./install.sh -e berth_server=true -e tailscale_auth_key=tskey-auth-EXAMPLE
+berth host add big 192.0.2.20 --user root --auth ssh --type node \
+ --feature docker/engine --feature incus/server
+berth apply big
```
-To also install Sysbox, so that berth's Docker provisioner can run containers
-with `runtime=sysbox` instead of privileged, add `-e sysbox=true` on the first
-run. It downloads a package and checks it against a sum in `vars.yml`.
-
-A second run changes nothing in place. It leaves a server alone that has a
-storage pool, so it never touches existing guests. Settings are in `vars.yml`,
-and the README lists them.
-
-### Add the server to berth
-
-A server from `rescue-install` and `incus-host` takes the user's public key for
-`root`. On the user's own machine, with the made-up name `big`:
-
-```bash
-berth host add big 192.0.2.20 --user root --auth ssh
-berth host install big
-```
-
-`host add` saves a reachable host. The default `--auth berth` uses berth's own
-key, which berth installs on first contact with a password or a private key that
-logs in once. `--auth ssh` uses the user's own SSH configuration and agent, and
-works with a local berth only. `host install` puts the controller alone on the
-server, for status, updates, a reboot and commands. Sessions then run as `root`.
-Such a server is never applied as a workstation.
+`--auth ssh` uses the user's own SSH configuration and agent, and works with a
+local berth only. The default `--auth berth` uses berth's own key, which berth
+installs on first contact with a password or a private key that logs in once.
+The apply gives the SSH user berth's key and allows only keys for SSH. Root
+keeps a login with keys. Its `ufw` firewall keeps these open: SSH, the
+tailnet, the guests' bridge `incusbr0` and the Incus API on port 8444. berth
+then registers the provisioners. Check with `berth run big status` and
+`berth provisioner list`.
+
+The features never erase a disk. They make an Incus storage pool in a folder,
+or use one the user names in `devbox_incus_pool`. A server with Incus or Docker
+already keeps its pools, networks, trusted clients, containers and guests, and
+a provisioner registered for it by hand becomes the node's when it names the
+node's address. The apply names any it left alone, with the command that makes
+it the node's: `berth provisioner run NAME adopt node=big`.
+
+Virtual machines need KVM. On a rented virtual server without it, set
+`devbox_incus_virtual_machines` to `false` in `ansible_vars`. For Sysbox beside
+Docker, set `devbox_docker_sysbox` to `true` on the first apply.
### `berth-server`
@@ -123,15 +113,29 @@ port 7777 on this machine only, Tailscale, `tailscale serve` with TLS and a
```bash
curl -fsSL https://github.com/helightdev/berth/archive/refs/heads/main.tar.gz \
- | tar xz --strip-components=1 --wildcards '*/recipes'
+ | tar xz --strip-components=1 --wildcards '*/recipes' \
+ '*/provision/ansible/roles/devbox/files/berth-server-upgrade.py'
cd recipes/berth-server
sudo ./install.sh -e tailscale_auth_key=tskey-auth-EXAMPLE
```
-A second run changes nothing in place. It leaves the container `berth` as it
-is and starts it when it was stopped. To update, run `sudo docker pull
-ghcr.io/helightdev/berth`, `sudo docker rm -f berth`, then `sudo ./install.sh`.
-The data in `/srv/berth` stays.
+To let the server apply its own machine as a node, add
+`-e berth_server_node=true`. The server's own key then logs in to it as
+`root`. The container finds the machine at the name `node` and has the Docker
+socket. Add the
+node from the server with `berth host add big node --user root --type node`,
+then as in the node's section above.
+
+A second run changes nothing in place. The container `berth` keeps its image,
+data and options. A stopped one is started. To update the
+server, fetch the recipe of the new version and run
+`sudo ./install.sh -e berth_server_update=true`. It makes the container again
+from the new image with the options of the old one, and starts the old one
+again if the new one fails. On a node, the node's action `upgrade-server` does
+the same. Never update with `docker rm -f berth`: a new container loses the
+options passed by hand, such as the name `incus-host` the provisioners of
+berth 0.5 reach. A server of berth 0.5 is updated before its clients and hosts:
+the page Upgrading from 0.5 in the docs has the order.
## Things that go wrong
@@ -139,11 +143,13 @@ The data in `/srv/berth` stays.
| --- | --- |
| The tailnet address does not work | HTTPS certificates must be on for the tailnet. Or set `berth_server_tailscale_serve` to `false` to keep the server on the machine only. |
| The image does not pull | A private image needs `sudo docker login ghcr.io` before the run. |
-| Virtual machines fail on a rented virtual server | They need KVM. Set `incus_virtual_machines` to `false` and use containers. |
-| The bridge clashes with the server's network | Change `incus_bridge_address` if `10.77.0.0/24` is taken. |
-| Locked out of SSH | With `ssh_from` set to one address, SSH from anywhere else is refused. The provider's console is the way back in. |
+| Virtual machines fail on a rented virtual server | They need KVM. Set `devbox_incus_virtual_machines` to `false` and use containers. |
+| The bridge clashes with the server's network | Change `devbox_incus_bridge_address` if `10.77.0.0/24` is taken. |
+| Locked out of SSH | With `ssh_from` in `berth-server`, or `devbox_ssh_from` on a node, set to one address, SSH from anywhere else is refused. The provider's console is the way back in. |
+| A storage pool on its own disk | The features never erase a disk. Create it with `incus storage create` and name it in `devbox_incus_pool`. |
| Docker ports are open to the world | Docker publishes past `ufw`. Publish on `127.0.0.1` or the tailnet address. |
| The enrollment key leaks | Pass `tailscale_auth_key` on the command line. Never save it in a file you commit. |
+| Hosts berth sets up do not join the tailnet | berth makes their keys itself, with the secret `tailnet_api_key`: a Tailscale OAuth client as `CLIENT_ID:CLIENT_SECRET`, a Tailscale API access token or a Headscale API key. Ask the user to set it with `berth secret set tailnet_api_key`. Only the recipes' own machine takes a key by hand, because the recipe runs before berth does. |
| A rescue install refuses to run | It refuses a system that did not start with UEFI, and a disk the running system is on. |
## Hand the server over to the user
@@ -154,16 +160,16 @@ The server starts with a setup key. On the server machine this prints a
one-time key that is valid for 24 hours:
```bash
-sudo docker exec berth berth setup-key
+sudo docker exec berth berth server setup-key
```
The recipes make a key on the first run and print it at the end. Give the
user the key and the address, which `tailscale serve status` shows:
-1. On their own machine they run `berth connect https://THIS-MACHINE.YOUR-TAILNET.ts.net` and enter the key.
-2. Or they open `https://THIS-MACHINE.YOUR-TAILNET.ts.net/#setup-key=KEY` in a browser.
+1. On their own machine they run `berth login https://THIS-MACHINE.YOUR-TAILNET.ts.net` and enter the key. It works on Windows and macOS too.
+2. Then `berth ui` opens the screens, and the other commands use that server.
-The key ends when they choose Done, or when `berth connect` has saved the token.
+The key ends when they choose Done, or when `berth login` has saved the token.
**Return the setup key and the address to the user. Never read, store or print
the permanent token in `serve.token`.**
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index db0cf93..eda4ac5 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -109,9 +109,9 @@ A pull request is ready when:
vale --minAlertLevel=warning "docs/content/docs/(guide)" README.md AGENTS.md
```
-- The terminal client and the page in a browser do the same things. A feature
- added to one is added to the other, with the shared part in
- `crates/berth-tui`.
+- The screens do everything through the API of a server, whichever it is. A
+ feature of theirs is an operation or an action of the server first, and
+ then their part in `crates/berth-page` and `crates/berth-tui`.
- Commits follow [Conventional Commits](https://www.conventionalcommits.org/),
with a short subject that says what changed.
- The pull request links its issue and stays within it. Leave unrelated
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index adaea1f..d38fad9 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -11,5 +11,5 @@ Issue: #
- [ ] `ci/run.sh all` passes
- [ ] Tried on a real host as well as in the containers (say which kind above)
- [ ] Documentation is updated and Vale doesn't report warnings
-- [ ] The terminal client and the page in a browser both have it, where it applies
+- [ ] The screens do it through the API, and the client build for macOS and Windows still checks
- [ ] I read every line of this change myself
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 51196b3..f13437d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -81,7 +81,7 @@ jobs:
key: e2e-${{ hashFiles('Cargo.lock', 'ci/dev.Dockerfile') }}-${{ github.sha }}
restore-keys: e2e-${{ hashFiles('Cargo.lock', 'ci/dev.Dockerfile') }}-
- name: Build berth
- run: ci/run.sh run cargo build --locked -p berth --features web
+ run: ci/run.sh run cargo build --locked -p berth
# berth, and the berthd and box it puts into the role's files. A tar
# keeps their modes, which an artifact does not.
- name: Pack what the shards test
diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index dfddb30..5dfbd9b 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -24,16 +24,10 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 24
- # The site has the page of berth serve under /web, which building berth makes.
- - uses: dtolnay/rust-toolchain@stable
- with:
- targets: x86_64-unknown-linux-musl, wasm32-unknown-unknown
- - uses: Swatinem/rust-cache@v2
- run: npm install --no-audit --no-fund && npm run build
working-directory: docs
env:
DOCS_BASE_PATH: ${{ steps.pages.outputs.base_path }}
- - run: test -f docs/out/web/berth-web_bg.wasm
- uses: actions/upload-pages-artifact@v5
with:
path: docs/out
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 23e0059..fa65a69 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -8,97 +8,30 @@ on:
permissions:
contents: read
jobs:
+ # berth for each system, built on that system so that its version can be
+ # run there. On Linux it carries berthd and box for the hosts, which are
+ # built for x86_64 wherever berth is; on macOS and Windows it is a client
+ # of a berth serve elsewhere.
binary:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v7
- # A tag vX.Y.Z builds version X.Y.Z. Any other build says the version in
- # Cargo.toml, which is that of the latest release.
- - name: The version
- run: |
- if [ "$GITHUB_REF_TYPE" = tag ]; then
- version=${GITHUB_REF_NAME#v}
- if ! echo "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then
- echo "::error::$GITHUB_REF_NAME is not a version tag such as v1.2.0 or v1.2.0-rc.1"
- exit 1
- fi
- echo "BERTH_BUILD_VERSION=$version" >> "$GITHUB_ENV"
- fi
- - uses: dtolnay/rust-toolchain@stable
- with:
- targets: x86_64-unknown-linux-musl, wasm32-unknown-unknown
- - name: musl compiler for the bundled SQLite
- run: sudo apt-get update && sudo apt-get install -y --no-install-recommends musl-tools
- - uses: Swatinem/rust-cache@v2
- - name: Build berth, with berthd and box inside
- run: cargo build --release --locked --target x86_64-unknown-linux-musl -p berth
- - name: Pack
- run: |
- mkdir dist
- cp target/x86_64-unknown-linux-musl/release/berth LICENSE-MIT LICENSE-APACHE dist/
- tar -czf berth-x86_64-linux.tar.gz -C dist berth LICENSE-MIT LICENSE-APACHE
- sha256sum berth-x86_64-linux.tar.gz > berth-x86_64-linux.tar.gz.sha256
- cp target/host/x86_64-unknown-linux-musl/release/berthd target/host/x86_64-unknown-linux-musl/release/box dist/
- - name: Build berth with the page for a browser
- run: cargo build --release --locked --target x86_64-unknown-linux-musl -p berth --features web
- - name: Pack it
- run: |
- cp target/x86_64-unknown-linux-musl/release/berth dist/berth
- tar -czf berth-web-x86_64-linux.tar.gz -C dist berth LICENSE-MIT LICENSE-APACHE
- sha256sum berth-web-x86_64-linux.tar.gz > berth-web-x86_64-linux.tar.gz.sha256
- - name: Check the versions
- # berth in both archives, and the berthd and box it carries, all say the same.
- run: |
- want=${BERTH_BUILD_VERSION:-$(sed -n '/^\[workspace.package\]/,/^\[/s/^version = "\(.*\)"/\1/p' Cargo.toml)}
- mkdir check check-web
- tar -xzf berth-x86_64-linux.tar.gz -C check berth
- tar -xzf berth-web-x86_64-linux.tar.gz -C check-web berth
- for program in check/berth check-web/berth dist/berthd dist/box; do
- said=$("$program" --version)
- echo "$program: $said"
- case "$said" in
- "${program##*/} $want" | "${program##*/} $want "*) ;;
- *) echo "::error::$program says $said, not $want"; exit 1 ;;
- esac
- done
- rm -r check check-web
- - uses: actions/upload-artifact@v4
- with:
- name: berth-x86_64-linux
- path: |
- berth-x86_64-linux.tar.gz
- berth-x86_64-linux.tar.gz.sha256
- berth-web-x86_64-linux.tar.gz
- berth-web-x86_64-linux.tar.gz.sha256
- - uses: actions/upload-artifact@v4
- with:
- name: host-programs-x86_64-linux
- path: |
- dist/berthd
- dist/box
- # berth-remote, the page of berth serve in a terminal, to use a server's
- # hosts from another machine. Each is built on the system it is for, so
- # that its version can be run there.
- remote:
strategy:
fail-fast: false
matrix:
include:
- - runner: windows-latest
- target: x86_64-pc-windows-msvc
- asset: berth-remote-x86_64-windows.zip
- - runner: macos-15
- target: aarch64-apple-darwin
- asset: berth-remote-aarch64-macos.tar.gz
- - runner: macos-15-intel
- target: x86_64-apple-darwin
- asset: berth-remote-x86_64-macos.tar.gz
- runner: ubuntu-latest
target: x86_64-unknown-linux-musl
- asset: berth-remote-x86_64-linux.tar.gz
+ asset: berth-x86_64-linux.tar.gz
- runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-musl
- asset: berth-remote-aarch64-linux.tar.gz
+ asset: berth-aarch64-linux.tar.gz
+ - runner: macos-15
+ target: aarch64-apple-darwin
+ asset: berth-aarch64-macos.tar.gz
+ - runner: macos-15-intel
+ target: x86_64-apple-darwin
+ asset: berth-x86_64-macos.tar.gz
+ - runner: windows-latest
+ target: x86_64-pc-windows-msvc
+ asset: berth-x86_64-windows.zip
runs-on: ${{ matrix.runner }}
defaults:
run:
@@ -106,11 +39,14 @@ jobs:
env:
# The C runtime goes into the program, so that Windows needs nothing installed.
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS: -C target-feature=+crt-static
- # ring's C is built against musl too, so that the program runs on any Linux.
+ # The bundled SQLite and ring's C are built against musl too, so that
+ # the program runs on any Linux.
CC_x86_64_unknown_linux_musl: musl-gcc
CC_aarch64_unknown_linux_musl: musl-gcc
steps:
- uses: actions/checkout@v7
+ # A tag vX.Y.Z builds version X.Y.Z. Any other build says the version in
+ # Cargo.toml, which is that of the latest release.
- name: The version
run: |
if [ "$GITHUB_REF_TYPE" = tag ]; then
@@ -123,20 +59,26 @@ jobs:
fi
- uses: dtolnay/rust-toolchain@stable
with:
- targets: ${{ matrix.target }}
- - name: musl compiler for ring
+ # On Linux the host programs are built for x86_64 as well.
+ targets: ${{ matrix.target }}${{ runner.os == 'Linux' && ',x86_64-unknown-linux-musl' || '' }}
+ - name: musl compiler
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends musl-tools
+ # berthd and box have no C in them: on an arm runner they are linked
+ # for x86_64 by Rust's own linker.
+ - name: A linker for the host programs
+ if: matrix.target == 'aarch64-unknown-linux-musl'
+ run: echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=rust-lld" >> "$GITHUB_ENV"
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- - name: Build berth-remote
- run: cargo build --release --locked --target ${{ matrix.target }} -p berth-remote
+ - name: Build berth
+ run: cargo build --release --locked --target ${{ matrix.target }} -p berth
- name: Pack
run: |
mkdir dist
- program=berth-remote
- [ "$RUNNER_OS" = Windows ] && program=berth-remote.exe
+ program=berth
+ [ "$RUNNER_OS" = Windows ] && program=berth.exe
cp "target/${{ matrix.target }}/release/$program" LICENSE-MIT LICENSE-APACHE dist/
case "${{ matrix.asset }}" in
*.zip) (cd dist && 7z a -tzip -bso0 "../${{ matrix.asset }}" "$program" LICENSE-MIT LICENSE-APACHE) ;;
@@ -147,21 +89,39 @@ jobs:
else
shasum -a 256 "${{ matrix.asset }}" > "${{ matrix.asset }}.sha256"
fi
- - name: Check the version
+ - name: Check the versions
+ # berth, and on Linux the berthd and box it carries, all say the same.
run: |
want=${BERTH_BUILD_VERSION:-$(sed -n '/^\[workspace.package\]/,/^\[/s/^version = "\(.*\)"/\1/p' Cargo.toml)}
- said=$(dist/berth-remote --version)
- echo "berth-remote: $said"
- [ "$said" = "berth-remote $want" ] || { echo "::error::berth-remote says $said, not $want"; exit 1; }
+ programs=dist/berth
+ if [ "$RUNNER_OS" = Linux ]; then
+ cp target/host/x86_64-unknown-linux-musl/release/berthd target/host/x86_64-unknown-linux-musl/release/box dist/
+ [ "${{ matrix.target }}" = x86_64-unknown-linux-musl ] && programs="$programs dist/berthd dist/box"
+ fi
+ for program in $programs; do
+ said=$("$program" --version)
+ echo "$program: $said"
+ case "$said" in
+ "${program##*/} $want" | "${program##*/} $want "*) ;;
+ *) echo "::error::$program says $said, not $want"; exit 1 ;;
+ esac
+ done
- uses: actions/upload-artifact@v4
with:
- name: berth-remote-${{ matrix.target }}
+ name: berth-${{ matrix.target }}
path: |
${{ matrix.asset }}
${{ matrix.asset }}.sha256
+ - uses: actions/upload-artifact@v4
+ if: matrix.target == 'x86_64-unknown-linux-musl'
+ with:
+ name: host-programs-x86_64-linux
+ path: |
+ dist/berthd
+ dist/box
release:
if: startsWith(github.ref, 'refs/tags/v')
- needs: [binary, remote]
+ needs: [binary]
runs-on: ubuntu-latest
permissions:
contents: write
@@ -169,10 +129,7 @@ jobs:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v4
with:
- name: berth-x86_64-linux
- - uses: actions/download-artifact@v4
- with:
- pattern: berth-remote-*
+ pattern: berth-*
merge-multiple: true
- name: Publish the release
env:
@@ -186,9 +143,8 @@ jobs:
# A release made on GitHub's page exists already, and only lacks the files.
gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1 \
|| gh release create "$GITHUB_REF_NAME" --verify-tag --generate-notes $prerelease
- gh release upload "$GITHUB_REF_NAME" --clobber berth-x86_64-linux.tar.gz berth-x86_64-linux.tar.gz.sha256 berth-web-x86_64-linux.tar.gz berth-web-x86_64-linux.tar.gz.sha256 \
- berth-remote-*.zip berth-remote-*.zip.sha256 berth-remote-*.tar.gz berth-remote-*.tar.gz.sha256 \
- install.sh install-remote.sh install.ps1 VERSION
+ gh release upload "$GITHUB_REF_NAME" --clobber berth-*.tar.gz berth-*.tar.gz.sha256 \
+ berth-*.zip berth-*.zip.sha256 install.sh install.ps1 VERSION
image:
runs-on: ubuntu-latest
permissions:
diff --git a/.vale.ini b/.vale.ini
index 0e5e382..0c691a0 100644
--- a/.vale.ini
+++ b/.vale.ini
@@ -17,6 +17,10 @@ Vale.Spelling = NO
[{**/LICENSE*,crates/vendor/**,docs/node_modules/**,docs/.next/**,docs/out/**,docs/.source/**,build/**,.vale/**}]
BasedOnStyles =
+# The command reference is made from berth's --help texts, which keep to the terminal's short style.
+[docs/content/docs/(guide)/reference/cli.mdx]
+BasedOnStyles =
+
# Tables put a group next to a task of the same name.
[README.md]
Vale.Repetition = NO
diff --git a/AGENTS.md b/AGENTS.md
index 202ce0e..9e495b8 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -6,15 +6,13 @@ berth sets up and looks after agent workstations. These are Ubuntu machines with
| Path | What it is |
| --- | --- |
-| `crates/berth/` | The `berth` program: terminal UI, commands and `berth serve` (`crates/berth/src/serve/`). In `serve/`, `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/` | 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 adopt`. `runner.rs` runs every action as a job. `keys/` is the key ring and how berth logs in to hosts. `level.rs` says what a host can do at each level. `provisioner.rs` and `resource.rs` are the provisioners of plugins and what they made |
-| `crates/berth-tui/` | The parts of the UI that run in a terminal and in a browser |
+| `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-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 |
-| `crates/berth-page/` | The screens of the page of `berth serve`, shared by `berth-web` and `berth-remote`. `device.rs` is what a browser and a terminal each give them, and `portal.rs` the server's portal over it |
-| `crates/berth-web/` | The page of `berth serve --web`, built for WebAssembly: the browser's side of `berth-page`'s device |
-| `crates/berth-remote/` | `berth-remote`, the same screens in a terminal on Linux, macOS and Windows, for a `berth serve` on another machine |
+| `crates/berth-page/` | berth's screens in a terminal. They do everything through the API of a server: one elsewhere, a `berth serve` on its socket, or the one in the process. `net.rs` reaches it, `portal.rs` is its portal, `settings.rs` keeps the server and its token, and `device.rs` is what the program starts them with |
| `crates/vendor/` | The vendored `tui-input` crate |
| `provision/` | The installer side of the provisioning source: the role in `ansible/`, first-boot provisioning in `bootstrap/`, the builder of seeds and releases in `bin/devbox.py` and the example profile in `config/`. berth names these paths in `layout` in `crates/berth-core/src/paths.rs` |
| `plugins/` | The plugins that come with berth, each an npm-format package with a `guide.md`. With `provision/` they make the provisioning source, which berth carries and unpacks with the same layout |
@@ -40,7 +38,7 @@ A new skill gets its own folder and a row here and in `.agents/skills/README.md`
- Follow the `install-berth` skill. It says which recipe in `recipes/` fits and gives its command.
- A recipe that erases disks needs the user's word first, for that server and those disks.
- Do not write an enrollment key or a password into a file in the repository.
-- When a berth server is installed, give the user its address and a setup key from `berth setup-key`. Do not read or print the token in `serve.token`.
+- When a berth server is installed, give the user its address and a setup key from `berth server setup-key`. Do not read or print the token in `serve.token`.
## Build and check
@@ -48,16 +46,15 @@ Use cargo for everything Rust. These are what CI runs:
```bash
cargo test --locked
-cargo test --locked -p berth --features web
-cargo fmt --check -p berth-api -p berth-pty -p berth-core -p berth-tui -p berth -p berthd -p box -p berth-page -p berth-web -p berth-remote
+cargo fmt --check -p berth-api -p berth-pty -p berth-core -p berth-tui -p berth -p berthd -p box -p berth-page
cargo clippy --locked --all-targets -- -D warnings
-cargo clippy --locked --all-targets -p berth --features web -- -D warnings
-cargo clippy --locked -p berth-web --target wasm32-unknown-unknown -- -D warnings
python3 -m unittest discover -s tests -v
-vale --minAlertLevel=warning README.md docs/content/docs plugins/*/guide.md
+vale --minAlertLevel=warning README.md AGENTS.md docs/content/docs plugins/*/guide.md
```
-Development and test builds embed quick builds of berthd, box and the page (the `host-dev` and `web-dev` profiles). Only `--release` embeds the release builds. The `web` feature needs the `wasm32-unknown-unknown` target. The Python tests skip their YAML checks without PyYAML, so install `provision/requirements.txt` in a virtual environment to run them all.
+On macOS and Windows berth is the client alone. Check that it still builds there with `cargo check -p berth --target x86_64-pc-windows-msvc` or `--target aarch64-apple-darwin`; the release builds it on those systems.
+
+Development and test builds embed quick builds of berthd and box (the `host-dev` profile). Only `--release` embeds the release builds. The Python tests skip their YAML checks without PyYAML, so install `provision/requirements.txt` in a virtual environment to run them all.
### In containers
@@ -79,6 +76,7 @@ The end-to-end tests in `tests/e2e/` use throw-away containers over SSH, with be
| `e2e_controller.Controller` | The same host and berth's controller alone, with one playbook run |
| `e2e_provisioners` | A provisioner of a made-up plugin, and no test host. With Docker, `ci/run.sh` starts an engine on the test network for the Docker plugin's cases |
| `e2e_restore` | The host `studio` as it is, and a server of its own with an encrypted store. It leaves the host as it is |
+| `e2e_node` | The bare host `dock` applied as a node, with a made-up plugin's feature that offers a provisioner. It runs last there and leaves the node |
| The rest | A full apply of the profile |
That engine starts with Docker when the run is complete, names `e2e_provisioners` or is the shard that holds it. `BERTH_CI_DOCKER` (`1` or `0`) forces it on or off, and `BERTH_CI_DIND_IMAGES` lists images of your own engine to load into it, as it cannot pull. The header of `ci/run.sh` has the rest.
@@ -92,21 +90,22 @@ CI builds berth once and runs the tests of each test host as a shard, in a job o
## API changes
- Add the operation to `crates/berth-api/src/ops.rs` with the role it needs. A test fails when a route has no operation or the other way round.
-- The API documents in `docs/openapi/` are committed. Regenerate them with `BERTH_UPDATE_DOCS=1 cargo test -p berth -p berthd`.
-- The pages under `docs/content/docs/api/host` and `api/serve` are generated from those documents. Do not edit them by hand.
+- The API documents in `docs/openapi/` are committed. Regenerate them with `BERTH_UPDATE_DOCS=1 cargo test -p berth -p berthd`. The same writes the command line's reference page, `docs/content/docs/(guide)/reference/cli.mdx`, from the grammar in `crates/berth/src/cli/args.rs`. A test fails while either is stale.
+- The pages under `docs/content/docs/api/host` and `api/serve` are generated from those documents when the docs are built (`docs/scripts/reference.mjs`), and are not committed. Do not edit them by hand.
+- The screenshots of the docs are taken offscreen by `docs/scripts/screens.py`, from made-up hosts.
### Actions
-Give a new thing a host, the installation, a provisioner or a resource can do an action in the matching registry. It does not get a route of its own. The routes `hosts.act`, `actions.act`, `provisioners.act` and `resources.act` run it, and each action says whether it can run now and what role it needs.
+Give a new thing a host, the installation, a provisioner or a resource can do an action in the matching registry. It does not get a route of its own. The routes `hosts.act`, `installation.act`, `provisioners.act` and `resources.act` run it, and each action says whether it can run now and what role it needs.
| Subject | Where its actions are |
| --- | --- |
-| A host | `HOST` in `crates/berth/src/serve/actions.rs`, besides the tasks its controller lists |
+| A host | `HOST` in `crates/berth/src/local/serve/actions.rs`, besides the actions its controller lists |
| The installation | `INSTALLATION` in the same file |
| A provisioner | `provisioner::actions` in `crates/berth-core/src/provisioner.rs`: its plugin's actions and berth's own |
| A resource | `resource::actions` in `crates/berth-core/src/resource.rs`: those of its kind and its plugin's |
-An action that changes something runs as a job through `runner.rs`.
+An action that changes something runs as a job through `runner.rs`. The screens do everything through the API. What works only with the server's own machine, such as writing a USB drive, is an action that is available to a caller there alone (`Seen::local`: the socket or the process), and says why not to one over the network.
## Versions and releases
diff --git a/Cargo.lock b/Cargo.lock
index c8145e5..06f0ea7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2,12 +2,6 @@
# It is not intended for manual editing.
version = 4
-[[package]]
-name = "adler2"
-version = "2.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
-
[[package]]
name = "aead"
version = "0.5.2"
@@ -33,6 +27,56 @@ version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
+[[package]]
+name = "anstream"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
+dependencies = [
+ "anstyle",
+ "anstyle-parse",
+ "anstyle-query",
+ "anstyle-wincon",
+ "colorchoice",
+ "is_terminal_polyfill",
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle"
+version = "1.0.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
+
+[[package]]
+name = "anstyle-parse"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
+dependencies = [
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle-query"
+version = "1.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
+dependencies = [
+ "windows-sys 0.61.2",
+]
+
+[[package]]
+name = "anstyle-wincon"
+version = "3.0.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
+dependencies = [
+ "anstyle",
+ "once_cell_polyfill",
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "anyhow"
version = "1.0.104"
@@ -63,6 +107,45 @@ version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
+[[package]]
+name = "asn1-rs"
+version = "0.7.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b7f43a50ac4fdca5df8e885c21b835997f0a1cdee65494a6847694a98652d9d8"
+dependencies = [
+ "asn1-rs-derive",
+ "asn1-rs-impl",
+ "displaydoc",
+ "nom",
+ "num-traits",
+ "rusticata-macros",
+ "thiserror 2.0.21",
+ "time",
+]
+
+[[package]]
+name = "asn1-rs-derive"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3109e49b1e4909e9db6515a30c633684d68cdeaa252f215214cb4fa1a5bfee2c"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+ "synstructure",
+]
+
+[[package]]
+name = "asn1-rs-impl"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
[[package]]
name = "async-trait"
version = "0.1.92"
@@ -102,7 +185,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90"
dependencies = [
"axum-core",
- "base64",
+ "base64 0.22.1",
"bytes",
"form_urlencoded",
"futures-util",
@@ -161,67 +244,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]]
-name = "base64ct"
-version = "1.8.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
-
-[[package]]
-name = "beamterm-core"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0375f7f3df163a52a06807f2150bac9a5da1933864ed40d52dda7dcd7cfa193b"
-dependencies = [
- "beamterm-data",
- "beamterm-unicode",
- "bitflags 2.13.2",
- "compact_str",
- "glow",
- "lru 0.16.4",
- "rustc-hash",
- "thiserror 2.0.21",
- "unicode-width",
-]
-
-[[package]]
-name = "beamterm-data"
-version = "1.0.0"
+name = "base64"
+version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f21ff1fc630079352bae9b024f85519bf1f641cf7f326623f4c0b59f7ea834fd"
-dependencies = [
- "compact_str",
- "miniz_oxide",
- "thiserror 2.0.21",
-]
+checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5"
[[package]]
-name = "beamterm-renderer"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d8db76d04d575a0534ad5dba63acc05ccbe69597f977f11c59a612cbea199112"
-dependencies = [
- "beamterm-core",
- "beamterm-data",
- "bitflags 2.13.2",
- "compact_str",
- "console_error_panic_hook",
- "glow",
- "js-sys",
- "thiserror 2.0.21",
- "unicode-width",
- "wasm-bindgen",
- "wasm-bindgen-futures",
- "web-sys",
-]
-
-[[package]]
-name = "beamterm-unicode"
-version = "1.0.0"
+name = "base64ct"
+version = "1.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1f44155933cdd0625a699c554c504aab30a571e4df68f3532fb95bf9cf53b935"
-dependencies = [
- "unicode-width",
-]
+checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
[[package]]
name = "berth"
@@ -231,15 +263,14 @@ dependencies = [
"berth-api",
"berth-core",
"berth-page",
- "berth-pty",
- "berth-remote",
"berth-tui",
"berthd",
+ "clap",
+ "clap_complete",
"crossterm",
"futures-util",
"jsonwebtoken",
"libc",
- "pulldown-cmark",
"ratatui",
"ring",
"serde",
@@ -249,8 +280,6 @@ dependencies = [
"tui-input",
"utoipa",
"utoipa-axum",
- "vt100",
- "wasm-bindgen-cli-support",
]
[[package]]
@@ -279,6 +308,7 @@ dependencies = [
"hmac 0.12.1",
"libc",
"postgres",
+ "rcgen",
"rusqlite",
"rustls",
"serde",
@@ -298,26 +328,6 @@ version = "0.5.2"
dependencies = [
"berth-api",
"berth-tui",
- "ratatui",
- "serde_json",
- "tui-input",
- "web-time",
-]
-
-[[package]]
-name = "berth-pty"
-version = "0.5.2"
-dependencies = [
- "libc",
-]
-
-[[package]]
-name = "berth-remote"
-version = "0.5.2"
-dependencies = [
- "berth-api",
- "berth-page",
- "berth-tui",
"crossterm",
"futures-util",
"ratatui",
@@ -327,9 +337,17 @@ dependencies = [
"tempfile",
"tokio",
"tokio-rustls",
+ "tui-input",
"webpki-roots",
]
+[[package]]
+name = "berth-pty"
+version = "0.5.2"
+dependencies = [
+ "libc",
+]
+
[[package]]
name = "berth-tui"
version = "0.5.2"
@@ -342,21 +360,6 @@ dependencies = [
"serde_json",
"tui-input",
"vt100",
- "web-time",
-]
-
-[[package]]
-name = "berth-web"
-version = "0.5.2"
-dependencies = [
- "berth-page",
- "berth-tui",
- "console_error_panic_hook",
- "critical-section",
- "js-sys",
- "ratzilla",
- "wasm-bindgen",
- "web-sys",
]
[[package]]
@@ -387,7 +390,7 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
dependencies = [
- "bit-vec",
+ "bit-vec 0.6.3",
]
[[package]]
@@ -396,6 +399,15 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
+[[package]]
+name = "bit-vec"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b71798fca2c1fe1086445a7258a4bc81e6e49dcd24c8d0dd9a1e57395b603f51"
+dependencies = [
+ "serde",
+]
+
[[package]]
name = "bitflags"
version = "1.3.2"
@@ -408,18 +420,6 @@ version = "2.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
-[[package]]
-name = "bitvec"
-version = "1.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ddcec3d12c579d40898fe0a9a358a803c23e9c52ca3c425707f81c9436211837"
-dependencies = [
- "funty",
- "radium",
- "tap",
- "wyz",
-]
-
[[package]]
name = "block-buffer"
version = "0.10.4"
@@ -558,12 +558,68 @@ dependencies = [
"zeroize",
]
+[[package]]
+name = "clap"
+version = "4.6.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"
+dependencies = [
+ "clap_builder",
+ "clap_derive",
+]
+
+[[package]]
+name = "clap_builder"
+version = "4.6.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "clap_lex",
+ "strsim",
+ "terminal_size",
+]
+
+[[package]]
+name = "clap_complete"
+version = "4.6.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "037e2a1a92236d0aff7e845093f64661d6df4c02c9fcc61a60e9e1d736fa392f"
+dependencies = [
+ "clap",
+]
+
+[[package]]
+name = "clap_derive"
+version = "4.6.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn 3.0.9",
+]
+
+[[package]]
+name = "clap_lex"
+version = "1.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486"
+
[[package]]
name = "cmov"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a"
+[[package]]
+name = "colorchoice"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
+
[[package]]
name = "compact_str"
version = "0.9.1"
@@ -578,16 +634,6 @@ dependencies = [
"static_assertions",
]
-[[package]]
-name = "console_error_panic_hook"
-version = "0.1.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
-dependencies = [
- "cfg-if",
- "wasm-bindgen",
-]
-
[[package]]
name = "const-oid"
version = "0.9.6"
@@ -649,31 +695,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
-[[package]]
-name = "crossbeam-deque"
-version = "0.8.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a"
-dependencies = [
- "crossbeam-epoch",
- "crossbeam-utils",
-]
-
-[[package]]
-name = "crossbeam-epoch"
-version = "0.9.21"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dc74980687109a3b14c72fd458107bf0baa1da1a1a805e178d15501ba9b86d9d"
-dependencies = [
- "crossbeam-utils",
-]
-
-[[package]]
-name = "crossbeam-utils"
-version = "0.8.23"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
-
[[package]]
name = "crossterm"
version = "0.29.0"
@@ -837,6 +858,20 @@ dependencies = [
"zeroize",
]
+[[package]]
+name = "der-parser"
+version = "10.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "07da5016415d5a3c4dd39b11ed26f915f52fc4e0dc197d87908bc916e51bc1a6"
+dependencies = [
+ "asn1-rs",
+ "displaydoc",
+ "nom",
+ "num-bigint",
+ "num-traits",
+ "rusticata-macros",
+]
+
[[package]]
name = "der_derive"
version = "0.7.3"
@@ -900,6 +935,17 @@ dependencies = [
"ctutils",
]
+[[package]]
+name = "displaydoc"
+version = "0.2.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.9",
+]
+
[[package]]
name = "document-features"
version = "0.2.12"
@@ -1105,12 +1151,6 @@ dependencies = [
"percent-encoding",
]
-[[package]]
-name = "funty"
-version = "2.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
-
[[package]]
name = "futures-channel"
version = "0.3.34"
@@ -1198,29 +1238,6 @@ dependencies = [
"rand_core 0.10.1",
]
-[[package]]
-name = "gimli"
-version = "0.32.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
-dependencies = [
- "fallible-iterator 0.3.0",
- "indexmap",
- "stable_deref_trait",
-]
-
-[[package]]
-name = "glow"
-version = "0.17.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "29038e1c483364cc6bb3cf78feee1816002e127c331a1eec55a4d202b9e1adb5"
-dependencies = [
- "js-sys",
- "slotmap",
- "wasm-bindgen",
- "web-sys",
-]
-
[[package]]
name = "group"
version = "0.13.0"
@@ -1241,8 +1258,6 @@ dependencies = [
"allocator-api2",
"equivalent",
"foldhash",
- "serde",
- "serde_core",
]
[[package]]
@@ -1393,15 +1408,6 @@ dependencies = [
"tower-service",
]
-[[package]]
-name = "id-arena"
-version = "2.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
-dependencies = [
- "rayon",
-]
-
[[package]]
name = "ident_case"
version = "1.0.1"
@@ -1451,6 +1457,12 @@ dependencies = [
"syn 3.0.9",
]
+[[package]]
+name = "is_terminal_polyfill"
+version = "1.70.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
+
[[package]]
name = "itertools"
version = "0.14.0"
@@ -1483,7 +1495,7 @@ version = "11.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e75fe14a82d81e5f5af639997db37d8b96045938a7ac6ab18cdbe1c7467e05e1"
dependencies = [
- "base64",
+ "base64 0.22.1",
"ed25519-dalek",
"getrandom 0.2.17",
"hmac 0.12.1",
@@ -1525,18 +1537,6 @@ dependencies = [
"spin",
]
-[[package]]
-name = "leb128"
-version = "0.2.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c83bff1d572d6b9aeef67ddfc8448e4a3737909cb28e81f97c791b9018703e52"
-
-[[package]]
-name = "leb128fmt"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
-
[[package]]
name = "libc"
version = "0.2.191"
@@ -1605,15 +1605,6 @@ version = "0.4.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
-[[package]]
-name = "lru"
-version = "0.16.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
-dependencies = [
- "hashbrown 0.16.1",
-]
-
[[package]]
name = "lru"
version = "0.18.5"
@@ -1682,15 +1673,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
-[[package]]
-name = "miniz_oxide"
-version = "0.9.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
-dependencies = [
- "adler2",
-]
-
[[package]]
name = "mio"
version = "1.2.4"
@@ -1738,6 +1720,16 @@ dependencies = [
"minimal-lexical",
]
+[[package]]
+name = "num-bigint"
+version = "0.4.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367"
+dependencies = [
+ "num-integer",
+ "num-traits",
+]
+
[[package]]
name = "num-bigint-dig"
version = "0.8.6"
@@ -1842,12 +1834,27 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "oid-registry"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "12f40cff3dde1b6087cc5d5f5d4d65712f34016a03ed60e9c08dcc392736b5b7"
+dependencies = [
+ "asn1-rs",
+]
+
[[package]]
name = "once_cell"
version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
+[[package]]
+name = "once_cell_polyfill"
+version = "1.70.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
+
[[package]]
name = "opaque-debug"
version = "0.3.1"
@@ -1955,6 +1962,16 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4"
+[[package]]
+name = "pem"
+version = "4.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d354a98a3d1251555de99e8fdd8afda05573c31b82f59063a7b0a29b5527f120"
+dependencies = [
+ "base64 0.23.1",
+ "serde_core",
+]
+
[[package]]
name = "pem-rfc7468"
version = "0.7.0"
@@ -2164,7 +2181,7 @@ version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08808e3c483c46e999108051c78334f473d5adb59d78bb80a1268c7e6aa6c514"
dependencies = [
- "base64",
+ "base64 0.22.1",
"byteorder",
"bytes",
"fallible-iterator 0.2.0",
@@ -2268,12 +2285,6 @@ version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
-[[package]]
-name = "radium"
-version = "0.7.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
-
[[package]]
name = "rand"
version = "0.8.8"
@@ -2379,7 +2390,7 @@ dependencies = [
"hashbrown 0.17.1",
"itertools",
"kasuari",
- "lru 0.18.5",
+ "lru",
"palette",
"serde",
"strum",
@@ -2464,39 +2475,17 @@ dependencies = [
]
[[package]]
-name = "ratzilla"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d53309a50b2cfb9828d1ea653b77fc6d2fe08137b05e65aa070ab87630e35b49"
-dependencies = [
- "beamterm-renderer",
- "bitvec",
- "compact_str",
- "console_error_panic_hook",
- "ratatui",
- "thiserror 2.0.21",
- "unicode-width",
- "web-sys",
-]
-
-[[package]]
-name = "rayon"
-version = "1.12.0"
+name = "rcgen"
+version = "0.14.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d"
+checksum = "8774e05a7d0de114588e6a28fe7e71694b82614ed569d86d8b389dfbc98b8ad8"
dependencies = [
- "either",
- "rayon-core",
-]
-
-[[package]]
-name = "rayon-core"
-version = "1.13.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
-dependencies = [
- "crossbeam-deque",
- "crossbeam-utils",
+ "pem",
+ "ring",
+ "rustls-pki-types",
+ "time",
+ "x509-parser",
+ "yasna",
]
[[package]]
@@ -2606,24 +2595,6 @@ dependencies = [
"sqlite-wasm-rs",
]
-[[package]]
-name = "rustc-demangle"
-version = "0.1.28"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b74b56ffa8bb2830709a538c2cbcae9aa062db0d2a42563bfb09bdaae44020eb"
-
-[[package]]
-name = "rustc-hash"
-version = "2.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
-
-[[package]]
-name = "rustc-std-workspace-core"
-version = "1.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "aa9c45b374136f52f2d6311062c7146bff20fec063c3f5d46a410bd937746955"
-
[[package]]
name = "rustc_version"
version = "0.4.1"
@@ -2633,6 +2604,15 @@ dependencies = [
"semver",
]
+[[package]]
+name = "rusticata-macros"
+version = "4.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632"
+dependencies = [
+ "nom",
+]
+
[[package]]
name = "rustix"
version = "1.1.6"
@@ -2931,15 +2911,6 @@ version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
-[[package]]
-name = "slotmap"
-version = "1.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bdd58c3c93c3d278ca835519292445cb4b0d4dc59ccfdf7ceadaab3f8aeb4038"
-dependencies = [
- "version_check",
-]
-
[[package]]
name = "smallvec"
version = "1.16.4"
@@ -2984,12 +2955,6 @@ dependencies = [
"wasm-bindgen",
]
-[[package]]
-name = "stable_deref_trait"
-version = "1.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
-
[[package]]
name = "stacker"
version = "0.1.25"
@@ -3093,10 +3058,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
[[package]]
-name = "tap"
-version = "1.0.1"
+name = "synstructure"
+version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
+checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
[[package]]
name = "tempfile"
@@ -3124,6 +3094,16 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "terminal_size"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "230a1b821ccbd75b185820a1f1ff7b14d21da1e442e22c0863ea5f08771a8874"
+dependencies = [
+ "rustix",
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "terminfo"
version = "0.9.0"
@@ -3162,7 +3142,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4676b37242ccbd1aabf56edb093a4827dc49086c0ffd764a5705899e0f35f8f7"
dependencies = [
"anyhow",
- "base64",
+ "base64 0.22.1",
"bitflags 2.13.2",
"fancy-regex",
"filedescriptor",
@@ -3250,6 +3230,7 @@ dependencies = [
"powerfmt",
"serde_core",
"time-core",
+ "time-macros",
]
[[package]]
@@ -3258,6 +3239,16 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109"
+[[package]]
+name = "time-macros"
+version = "0.2.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85"
+dependencies = [
+ "num-conv",
+ "time-core",
+]
+
[[package]]
name = "tinyvec"
version = "1.13.3"
@@ -3545,9 +3536,6 @@ name = "unicode-width"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
-dependencies = [
- "rustc-std-workspace-core",
-]
[[package]]
name = "universal-hash"
@@ -3662,35 +3650,6 @@ dependencies = [
"utf8parse",
]
-[[package]]
-name = "walrus"
-version = "0.27.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5691aeb3546554822fe2c13d63149c26a027cd07d900a72c7c7f37f4321bfaea"
-dependencies = [
- "anyhow",
- "gimli",
- "id-arena",
- "leb128",
- "log",
- "rayon",
- "walrus-macro",
- "wasm-encoder",
- "wasmparser",
-]
-
-[[package]]
-name = "walrus-macro"
-version = "0.26.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a9b0525d7ea6e5f906aca581a172e5c91b4c595290dfa8ad4a2bc9ffef33b44"
-dependencies = [
- "heck",
- "proc-macro2",
- "quote",
- "syn 2.0.119",
-]
-
[[package]]
name = "want"
version = "0.3.2"
@@ -3746,35 +3705,6 @@ dependencies = [
"wasm-bindgen-shared",
]
-[[package]]
-name = "wasm-bindgen-cli-support"
-version = "0.2.129"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a0724352b96c7779dcfd3f580b9e7e29beac8f4229c9a27cd2ea53e04f1cc65a"
-dependencies = [
- "anyhow",
- "base64",
- "leb128",
- "log",
- "rustc-demangle",
- "serde",
- "serde_json",
- "walrus",
- "wasm-bindgen-shared",
- "wasmparser",
-]
-
-[[package]]
-name = "wasm-bindgen-futures"
-version = "0.4.79"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3cbab34de2d982e9b48e18d216d04c4a6f641066ff19ffb699980f591ee3610e"
-dependencies = [
- "js-sys",
- "tokio",
- "wasm-bindgen",
-]
-
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.129"
@@ -3807,29 +3737,6 @@ dependencies = [
"unicode-ident",
]
-[[package]]
-name = "wasm-encoder"
-version = "0.245.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3f9dca005e69bf015e45577e415b9af8c67e8ee3c0e38b5b0add5aa92581ed5c"
-dependencies = [
- "leb128fmt",
- "wasmparser",
-]
-
-[[package]]
-name = "wasmparser"
-version = "0.245.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e"
-dependencies = [
- "bitflags 2.13.2",
- "hashbrown 0.16.1",
- "indexmap",
- "semver",
- "serde",
-]
-
[[package]]
name = "web-sys"
version = "0.3.106"
@@ -3840,16 +3747,6 @@ dependencies = [
"wasm-bindgen",
]
-[[package]]
-name = "web-time"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
-dependencies = [
- "js-sys",
- "wasm-bindgen",
-]
-
[[package]]
name = "webpki-roots"
version = "1.0.12"
@@ -4060,15 +3957,6 @@ version = "0.57.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
-[[package]]
-name = "wyz"
-version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed"
-dependencies = [
- "tap",
-]
-
[[package]]
name = "x509-cert"
version = "0.2.5"
@@ -4081,6 +3969,34 @@ dependencies = [
"tls_codec",
]
+[[package]]
+name = "x509-parser"
+version = "0.18.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d43b0f71ce057da06bc0851b23ee24f3f86190b07203dd8f567d0b706a185202"
+dependencies = [
+ "asn1-rs",
+ "data-encoding",
+ "der-parser",
+ "lazy_static",
+ "nom",
+ "oid-registry",
+ "ring",
+ "rusticata-macros",
+ "thiserror 2.0.21",
+ "time",
+]
+
+[[package]]
+name = "yasna"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5f6765e852b9b4dc8e2a76843e4d64d1cea8e79bcde0b6901aea8e7c7f08282"
+dependencies = [
+ "bit-vec 0.9.1",
+ "time",
+]
+
[[package]]
name = "zerocopy"
version = "0.8.63"
diff --git a/Cargo.toml b/Cargo.toml
index a2fd53a..1fd468f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,9 +1,9 @@
[workspace]
resolver = "3"
-members = ["crates/berth-api", "crates/berth-pty", "crates/berth-core", "crates/berth-tui", "crates/berth", "crates/berthd", "crates/box", "crates/berth-page", "crates/berth-web", "crates/berth-remote"]
+members = ["crates/berth-api", "crates/berth-pty", "crates/berth-core", "crates/berth-tui", "crates/berth", "crates/berthd", "crates/box", "crates/berth-page"]
# The vendored crate is a member because it lives inside; it is left out of what
# is built, tested and linted by default.
-default-members = ["crates/berth-api", "crates/berth-pty", "crates/berth-core", "crates/berth-tui", "crates/berth", "crates/berthd", "crates/box", "crates/berth-page", "crates/berth-remote"]
+default-members = ["crates/berth-api", "crates/berth-pty", "crates/berth-core", "crates/berth-tui", "crates/berth", "crates/berthd", "crates/box", "crates/berth-page"]
[workspace.package]
version = "0.5.2"
@@ -12,7 +12,7 @@ rust-version = "1.88"
license = "MIT OR Apache-2.0"
[workspace.dependencies]
-# Members that talk to a server ask for the client; the browser build does not.
+# Members that talk to a server ask for the client; the screens alone do not.
berth-api = { path = "crates/berth-api", default-features = false }
berth-pty = { path = "crates/berth-pty" }
berth-core = { path = "crates/berth-core" }
@@ -51,25 +51,10 @@ debug = false
[profile.release]
strip = true
-# The page of berth serve: small rather than fast, since it is carried in berth.
-[profile.web]
-inherits = "release"
-opt-level = "s"
-lto = "fat"
-codegen-units = 1
-
# What a development or test build of berth carries. berthd and box are built
-# incrementally, and small, as berth packs them. The page keeps its
-# optimisation without the whole-program link that takes most of its build
-# time after a change.
+# incrementally, and small, as berth packs them.
[profile.host-dev]
inherits = "dev"
opt-level = "s"
debug = false
strip = true
-
-[profile.web-dev]
-inherits = "web"
-lto = false
-codegen-units = 16
-incremental = true
diff --git a/README.md b/README.md
index 847c71c..01a587c 100644
--- a/README.md
+++ b/README.md
@@ -12,14 +12,14 @@ installs and can apply again. Once the host runs, its page in berth has the
status, sign-ins, updates and secrets. A machine you only log in to can be
a host too: `berth host add dock 192.0.2.4 --user ops`.
-
+
**Status:** early. Try a profile in the container or a VM before booting the
installer on real hardware: **the installer erases the disk it selects.**
## Install
-On Linux x86_64:
+On Linux or macOS:
```bash
curl -fsSL https://raw.githubusercontent.com/helightdev/berth/main/install.sh | sh
@@ -37,21 +37,21 @@ Setting up hosts also needs `ssh`, `python3` and `ansible-playbook` on your
machine. berth is also an image, `ghcr.io/helightdev/berth`, which runs its
local API server by default.
-`berth-remote` uses the hosts of a berth server from a terminal on Windows,
-macOS or Linux:
+On macOS and Windows berth uses the hosts of a berth server elsewhere, with the
+same screens. `install.sh` installs it on macOS too, and on Windows:
```powershell
-irm https://raw.githubusercontent.com/helightdev/berth/main/install.ps1 | iex # Windows
+irm https://raw.githubusercontent.com/helightdev/berth/main/install.ps1 | iex
```
-```bash
-curl -fsSL https://raw.githubusercontent.com/helightdev/berth/main/install-remote.sh | sh # macOS, Linux
-```
+Coming from berth 0.5? Update the server first, then the clients and the
+hosts, as [Upgrading from 0.5](docs/content/docs/%28guide%29/use/upgrading.mdx)
+says.
## Quick start
```bash
-berth studio # a new profile: choose how to install, features and settings
+berth studio # a new host: choose how to install, features and settings
berth # the home screen with all hosts
berth run studio status
```
@@ -69,6 +69,7 @@ The documentation site is built from [`docs/`](docs) (`cd docs && npm install &&
- [Getting started](docs/content/docs/%28guide%29/start/install.mdx): installing berth and a first host.
- [Deploying](docs/content/docs/%28guide%29/deploy/index.mdx): the install methods, and testing in QEMU.
- [Using berth](docs/content/docs/%28guide%29/use/index.mdx): the terminal UI and commands, sign-ins, secrets and updates.
+- [Upgrading from 0.5](docs/content/docs/%28guide%29/use/upgrading.mdx): the order, what is converted, and going back.
- [Extending](docs/content/docs/%28guide%29/extend/index.mdx): plugins, services and `berth serve`.
- [Reference](docs/content/docs/%28guide%29/reference/index.mdx): tools, `box`, profile fields, building and releasing.
- The API reference of berthd and `berth serve`, generated from [`docs/openapi/`](docs/openapi).
diff --git a/ci/boot.compose.yml b/ci/boot.compose.yml
index eeefa0c..86360a4 100644
--- a/ci/boot.compose.yml
+++ b/ci/boot.compose.yml
@@ -40,6 +40,8 @@ services:
BERTH_BOOT_SSH_PORT: ${BERTH_CI_BOOT_SSH_PORT:-22722}
BERTH_BOOT_CONTROL_URL: ${BERTH_CI_BOOT_CONTROL_URL:-}
BERTH_BOOT_CONTROL_KEY: ${BERTH_CI_BOOT_CONTROL_KEY:-}
+ BERTH_BOOT_CONTROL_USER: ${BERTH_CI_BOOT_CONTROL_USER:-}
+ BERTH_BOOT_CONTROL_TAGS: ${BERTH_CI_BOOT_CONTROL_TAGS:-}
CI: ${CI:-}
GITHUB_ACTIONS: ${GITHUB_ACTIONS:-}
TMPDIR: /work/tmp
diff --git a/ci/boot.sh b/ci/boot.sh
index 8ebf7c8..fee4b3a 100644
--- a/ci/boot.sh
+++ b/ci/boot.sh
@@ -19,8 +19,12 @@
# BERTH_CI_BOOT_CPUS its vCPUs (default: 4, at most what is there)
# BERTH_CI_BOOT_SSH_PORT the loopback port of its SSH with --keep (default: 22722)
# BERTH_CI_BOOT_CONTROL_URL, BERTH_CI_BOOT_CONTROL_KEY
-# a tailnet control server and a key to enrol the
-# guest with on its first boot
+# a tailnet control server, a Headscale address or
+# tailscale for Tailscale's own, and its API key, with
+# which berth makes the key the guest joins with on
+# its first boot
+# BERTH_CI_BOOT_CONTROL_USER, BERTH_CI_BOOT_CONTROL_TAGS
+# berth's tailnet_user and tailnet_tags for it
boot_compose() { "$engine" compose -f ci/boot.compose.yml "$@"; }
@@ -63,7 +67,7 @@ boot() {
boot_compose build --quiet
fi
# The guest gets berth's host programs from the role's files, which this build puts there.
- dev cargo build --locked -p berth --features web
+ dev cargo build --locked -p berth
local kind status=0 run
for kind in "${kinds[@]}"; do
diff --git a/ci/checks.sh b/ci/checks.sh
index 6c2bd00..1217a4a 100755
--- a/ci/checks.sh
+++ b/ci/checks.sh
@@ -4,18 +4,15 @@
set -euo pipefail
cd /src
-crates=(-p berth-api -p berth-pty -p berth-core -p berth-tui -p berth -p berthd -p box -p berth-page -p berth-web -p berth-remote)
+crates=(-p berth-api -p berth-pty -p berth-core -p berth-tui -p berth -p berthd -p box -p berth-page)
# Each runs as the condition of an if, where set -e does not stop it: the
# steps are joined with && instead.
-rust-tests() {
- cargo test --locked &&
- cargo test --locked -p berth --features web
-}
+rust-tests() { cargo test --locked; }
python-tests() { python3 -m unittest discover -s tests -v; }
shell-syntax() {
local script bad=0
- for script in install.sh install-remote.sh provision/bin/*.sh provision/bootstrap/*.sh container/*.sh ci/*.sh \
+ for script in install.sh provision/bin/*.sh provision/bootstrap/*.sh container/*.sh ci/*.sh \
provision/ansible/roles/devbox/files/*.sh provision/ansible/roles/devbox/files/tasks/*.sh plugins/*/files/*.sh \
recipes/*/*.sh; do
bash -n "$script" || bad=1
@@ -25,15 +22,10 @@ shell-syntax() {
ansible-syntax() {
(cd provision && ansible-playbook -i localhost, ansible/site.yml --syntax-check) &&
(cd provision && ansible-playbook -i localhost, ansible/controller.yml --syntax-check) &&
- (cd recipes/incus-host && ansible-playbook -i localhost, site.yml --syntax-check) &&
(cd recipes/berth-server && ansible-playbook -i localhost, site.yml --syntax-check)
}
fmt() { cargo fmt --check "${crates[@]}"; }
-clippy() {
- cargo clippy --locked --all-targets -- -D warnings &&
- cargo clippy --locked --all-targets -p berth --features web -- -D warnings &&
- cargo clippy --locked -p berth-web --target wasm32-unknown-unknown -- -D warnings
-}
+clippy() { cargo clippy --locked --all-targets -- -D warnings; }
vale() { command vale --minAlertLevel=warning README.md AGENTS.md docs/content/docs plugins/*/guide.md; }
all=(fmt shell-syntax ansible-syntax vale python-tests rust-tests clippy)
diff --git a/ci/dev.Dockerfile b/ci/dev.Dockerfile
index a48d1d2..13da9fc 100644
--- a/ci/dev.Dockerfile
+++ b/ci/dev.Dockerfile
@@ -11,7 +11,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
procps python3 python3-venv tini xz-utils \
&& rm -rf /var/lib/apt/lists/* \
&& rustup component add clippy rustfmt \
- && rustup target add x86_64-unknown-linux-musl wasm32-unknown-unknown
+ && rustup target add x86_64-unknown-linux-musl
RUN curl -fsSL "https://github.com/errata-ai/vale/releases/download/v${VALE_VERSION}/vale_${VALE_VERSION}_Linux_64-bit.tar.gz" \
| tar -xz -C /usr/local/bin vale
COPY provision/requirements.txt /tmp/requirements.txt
diff --git a/ci/run.sh b/ci/run.sh
index c9fb3bd..c59d924 100755
--- a/ci/run.sh
+++ b/ci/run.sh
@@ -144,7 +144,7 @@ docker_up() {
e2e() {
# The test host and the runner have no way out, so berth is built first.
if [[ ${BERTH_CI_PREBUILT:-} != 1 ]]; then
- dev cargo build --locked -p berth --features web
+ dev cargo build --locked -p berth
fi
e2e_down
trap e2e_down EXIT
diff --git a/container/berth.Dockerfile b/container/berth.Dockerfile
index e2bac4c..e7cef49 100644
--- a/container/berth.Dockerfile
+++ b/container/berth.Dockerfile
@@ -12,12 +12,11 @@
FROM rust:1-bookworm AS build
RUN apt-get update && apt-get install -y --no-install-recommends musl-tools python3 \
&& rm -rf /var/lib/apt/lists/* \
- && rustup target add x86_64-unknown-linux-musl wasm32-unknown-unknown
+ && rustup target add x86_64-unknown-linux-musl
WORKDIR /src
COPY . .
ARG BERTH_BUILD_VERSION=
-# With the page for a browser, which the default command serves.
-RUN cargo build --release --locked --target x86_64-unknown-linux-musl -p berth --features web \
+RUN cargo build --release --locked --target x86_64-unknown-linux-musl -p berth \
&& said=$(target/x86_64-unknown-linux-musl/release/berth --version) && echo "$said" \
&& { [ -z "$BERTH_BUILD_VERSION" ] || [ "$said" = "berth $BERTH_BUILD_VERSION" ]; }
@@ -37,4 +36,4 @@ ENV XDG_CONFIG_HOME=/config XDG_DATA_HOME=/data TERM=xterm-256color
VOLUME ["/config", "/data"]
EXPOSE 7777
ENTRYPOINT ["tini", "--", "berth"]
-CMD ["serve", "--listen", "0.0.0.0:7777", "--expose", "--web"]
+CMD ["serve", "--listen", "0.0.0.0:7777", "--expose"]
diff --git a/crates/berth-api/Cargo.toml b/crates/berth-api/Cargo.toml
index 62521b1..7a4cb24 100644
--- a/crates/berth-api/Cargo.toml
+++ b/crates/berth-api/Cargo.toml
@@ -20,5 +20,5 @@ futures-util = { workspace = true, optional = true }
[features]
default = ["client"]
# The client over a byte stream; without it only the types and tables remain,
-# which is what a browser build takes.
+# which is all the shared screens take.
client = ["dep:tokio", "dep:hyper", "dep:hyper-util", "dep:http-body-util", "dep:tokio-tungstenite", "dep:futures-util"]
diff --git a/crates/berth-api/src/client.rs b/crates/berth-api/src/client.rs
index 910fd1f..a71c9be 100644
--- a/crates/berth-api/src/client.rs
+++ b/crates/berth-api/src/client.rs
@@ -68,6 +68,20 @@ fn transport(error: impl std::fmt::Display) -> Error {
pub type Result = std::result::Result;
+/// A connection to a server, whatever carries it: TCP, TLS, a unix socket,
+/// or a pipe to a server in the same process.
+pub trait Io: AsyncRead + AsyncWrite + Unpin + Send {}
+impl Io for T {}
+pub type Stream = Box;
+
+/// How a client reaches its server: each call opens a new connection, for a
+/// request or for a WebSocket.
+pub type Dial = std::sync::Arc<
+ dyn Fn() -> std::pin::Pin> + Send>>
+ + Send
+ + Sync,
+>;
+
/// A raw answer: status, headers and body.
pub struct Response {
pub status: u16,
@@ -238,12 +252,27 @@ where
Ok((stream, _)) => Ok(stream),
Err(tungstenite::Error::Http(response)) => {
let body = response.body().clone().unwrap_or_default();
- Err(Response {
- status: response.status().as_u16(),
- headers: Default::default(),
- body: body.into(),
+ let status = response.status().as_u16();
+ // The body may still be on its way when the head is read, and
+ // then only the headers say which error it was.
+ let header = |name: &str| response.headers().get(name)?.to_str().ok();
+ let named = header(crate::ERROR_HEADER);
+ let said = header(crate::ERROR_MESSAGE_HEADER)
+ .map(decode)
+ .filter(|said| !said.is_empty());
+ match (serde_json::from_slice::(&body), named) {
+ (Err(_), Some(code)) => Err(Error::Api {
+ status,
+ code: code.to_owned(),
+ message: said.unwrap_or_else(|| format!("HTTP {status}: {code}")),
+ }),
+ _ => Err(Response {
+ status,
+ headers: Default::default(),
+ body: body.into(),
+ }
+ .error()),
}
- .error())
}
Err(error) => Err(transport(error)),
}
@@ -261,3 +290,31 @@ pub async fn websocket_unix(
}
pub use crate::escape::{decode, encode, encode_path};
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use tokio::io::{AsyncReadExt, AsyncWriteExt};
+
+ #[tokio::test]
+ async fn a_refused_stream_says_why_from_the_head_alone() {
+ let (ours, mut theirs) = tokio::io::duplex(4096);
+ let server = tokio::spawn(async move {
+ let mut asked = [0; 1024];
+ let _ = theirs.read(&mut asked).await;
+ let said = crate::error_message_header("Nothing answers at db: né");
+ // The head alone: the body it promises never comes.
+ let head = format!(
+ "HTTP/1.1 503 Service Unavailable\r\ncontent-length: 80\r\n{}: unreachable\r\n{}: {said}\r\n\r\n",
+ crate::ERROR_HEADER,
+ crate::ERROR_MESSAGE_HEADER,
+ );
+ theirs.write_all(head.as_bytes()).await.unwrap();
+ theirs
+ });
+ let refused = websocket(ours, "/v1/sessions/1", "").await.err().unwrap();
+ assert_eq!(refused.status(), 503);
+ assert_eq!(refused.to_string(), "Nothing answers at db: né");
+ drop(server.await);
+ }
+}
diff --git a/crates/berth-api/src/compat.rs b/crates/berth-api/src/compat.rs
new file mode 100644
index 0000000..604148b
--- /dev/null
+++ b/crates/berth-api/src/compat.rs
@@ -0,0 +1,119 @@
+//! What berth says when two of its programs are of different versions: a
+//! client and its server, or the server and a host's controller. Each is one
+//! sentence that names both versions and what to update, the same for the
+//! command line and the screens.
+
+use crate::{API, HostType, VERSION};
+
+/// The lowest `api` of a host's controller this berth can work with.
+pub const NEEDS_HOST_API: u32 = 2;
+
+/// Where updating from an older berth is explained.
+pub const UPGRADE_DOCS: &str =
+ "https://github.com/helightdev/berth/blob/main/docs/content/docs/(guide)/use/upgrading.mdx";
+
+/// The operations of berth 0.5 that this server does not have, which only a
+/// client of that version still calls.
+pub const OLDER_OPS: &[&str] = &["tasks.list", "tasks.run", "tasks.choices", "actions.act"];
+
+/// Why a client refuses to work with the server at `url`, which says it is
+/// berth `version` of `api`; `None` when the server is new enough.
+pub fn older_server(url: &str, version: &str, api: u32) -> Option {
+ (api < API).then(|| {
+ format!(
+ "The berth server at {url} is berth {version} (API {api}), older than this berth {VERSION} (API {API}), and would not understand what it is sent. Update the server first, then the clients and the hosts: {UPGRADE_DOCS}"
+ )
+ })
+}
+
+/// What updates the controller on a host of this type.
+pub fn controller_update(host: &str, host_type: HostType) -> String {
+ match host_type {
+ HostType::Workstation | HostType::Node => format!("berth apply {host}"),
+ HostType::Managed | HostType::Ssh => format!("berth run {host} install-controller"),
+ }
+}
+
+/// What a host says when its controller is berth `version` of `api`, too
+/// old for this berth; `None` when it is new enough.
+pub fn older_controller(
+ host: &str,
+ version: &str,
+ api: u32,
+ host_type: HostType,
+) -> Option {
+ (api < NEEDS_HOST_API).then(|| controller_is_older(host, version, host_type))
+}
+
+/// That the controller on `host`, berth `version`, is too old for this berth,
+/// and what updates it.
+pub fn controller_is_older(host: &str, version: &str, host_type: HostType) -> String {
+ format!(
+ "The controller on {host} is berth {version}, older than this berth {VERSION}. Update it with {}",
+ controller_update(host, host_type)
+ )
+}
+
+/// What the server answers a client that calls an operation it does not
+/// have: for one of an older berth, that the client is older.
+pub fn no_operation(name: &str) -> String {
+ match OLDER_OPS.contains(&name) {
+ true => format!(
+ "No operation {name}: it is a call of berth 0.5, and this server is berth {VERSION}. Update berth where this call comes from: {UPGRADE_DOCS}"
+ ),
+ false => format!("No operation {name}"),
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn an_older_server_is_named_with_both_versions() {
+ assert_eq!(older_server("https://pier.example", VERSION, API), None);
+ let said = older_server("https://pier.example", "0.5.2", 1).unwrap();
+ assert!(said.contains("is berth 0.5.2 (API 1)"), "{said}");
+ assert!(
+ said.contains(&format!("this berth {VERSION} (API {API})")),
+ "{said}"
+ );
+ assert!(said.contains("Update the server first"), "{said}");
+ assert!(said.ends_with(UPGRADE_DOCS), "{said}");
+ }
+
+ #[test]
+ fn an_older_controller_says_what_updates_it() {
+ assert_eq!(
+ older_controller("studio", VERSION, NEEDS_HOST_API, HostType::Workstation),
+ None
+ );
+ let said = older_controller("studio", "0.5.2", 1, HostType::Workstation).unwrap();
+ assert!(said.starts_with("The controller on studio is berth 0.5.2, older than this berth"));
+ assert!(
+ said.ends_with("Update it with berth apply studio"),
+ "{said}"
+ );
+ let said = older_controller("big", "0.5.2", 1, HostType::Node).unwrap();
+ assert!(said.ends_with("berth apply big"), "{said}");
+ let said = older_controller("pier", "0.5.2", 1, HostType::Managed).unwrap();
+ assert!(
+ said.ends_with("berth run pier install-controller"),
+ "{said}"
+ );
+ }
+
+ #[test]
+ fn a_call_of_an_older_client_says_so() {
+ assert_eq!(no_operation("hosts.nothing"), "No operation hosts.nothing");
+ assert!(no_operation("tasks.list").contains("a call of berth 0.5"));
+ // None of them is an operation now.
+ for name in OLDER_OPS {
+ assert!(
+ crate::ops::find(crate::ops::SERVE, name).is_none(),
+ "{name}"
+ );
+ assert!(crate::ops::find(crate::ops::HOST, name).is_none(), "{name}");
+ }
+ }
+}
diff --git a/crates/berth-api/src/lib.rs b/crates/berth-api/src/lib.rs
index c9182a6..b365743 100644
--- a/crates/berth-api/src/lib.rs
+++ b/crates/berth-api/src/lib.rs
@@ -3,12 +3,15 @@
#[cfg(feature = "client")]
pub mod client;
+pub mod compat;
pub mod escape;
pub mod ops;
#[cfg(feature = "client")]
pub mod portal;
pub mod profile;
pub mod streams;
+#[cfg(feature = "client")]
+pub mod tunnel;
mod types;
pub use types::*;
@@ -26,7 +29,7 @@ const _: () = assert!(
"BERTH_BUILD_VERSION is a version such as 0.3.0, without the v of its tag"
);
/// Rises when something is added to the API.
-pub const API: u32 = 1;
+pub const API: u32 = 2;
/// Where berthd listens in system mode.
pub const RUN_DIR: &str = "/run/berth";
diff --git a/crates/berth-api/src/ops.rs b/crates/berth-api/src/ops.rs
index c7fe239..a6def3a 100644
--- a/crates/berth-api/src/ops.rs
+++ b/crates/berth-api/src/ops.rs
@@ -29,6 +29,16 @@
//! ↔ {"sub": 7, "end": true} the last frame; from the server it may carry "error"
//! ```
//!
+//! A request to open a stream may add `"window": BYTES`. A server that keeps
+//! to it says so in its answer, `{"open": true, "window": BYTES}`, with the
+//! window it took. Each side then sends at most that many bytes of binary
+//! frames of the stream that the other side has not yet said it took, and
+//! says what it took as it goes:
+//!
+//! ```text
+//! ↔ {"sub": 7, "credit": 131072} so many more bytes may come
+//! ```
+//!
//! Bytes in a result or as input are `{"base64": "…"}` (a result adds
//! `content_type`), up to [`PORTAL_BYTES`]; larger transfers are HTTP's.
@@ -72,7 +82,7 @@ pub enum Body {
pub enum Role {
/// Look: hosts, sessions and their output, logs, the inbox, the store.
View,
- /// Use the hosts: run tasks and commands, write files, control units.
+ /// Use the hosts: run actions and commands, write files, control units.
Operate,
/// Set up: profiles, secrets, registries, plugins, and applying them to hosts.
Admin,
@@ -111,6 +121,10 @@ pub struct Op {
/// What the caller shows instead of a token with a role, for an
/// operation that checks a key of its own; empty for the others.
pub key: &'static str,
+ /// Why only `berth serve` calls it on a host, for itself; empty for the
+ /// others. It passes none of these through for a caller, and no portal
+ /// carries them.
+ pub server_only: &'static str,
}
const fn call(name: &'static str, method: &'static str, path: &'static str) -> Op {
@@ -128,6 +142,7 @@ const fn call(name: &'static str, method: &'static str, path: &'static str) -> O
_ => Role::Operate,
},
key: "",
+ server_only: "",
}
}
@@ -142,6 +157,7 @@ const fn stream(name: &'static str, path: &'static str) -> Op {
http_only: "",
role: Role::Operate,
key: "",
+ server_only: "",
}
}
@@ -167,6 +183,14 @@ const fn keyed(mut op: Op, key: &'static str) -> Op {
op
}
+/// An operation of berthd that `berth serve` calls itself after checks of
+/// its own, and that no caller reaches through it.
+const fn server_only(mut op: Op, why: &'static str) -> Op {
+ op.server_only = why;
+ op.http_only = why;
+ op
+}
+
const fn headers(mut op: Op, headers: &'static [(&'static str, &'static str)]) -> Op {
op.headers = headers;
op
@@ -188,12 +212,12 @@ pub static HOST: &[Op] = &[
call("sessions.input", "POST", "/v1/sessions/{id}/input"),
call("sessions.resize", "POST", "/v1/sessions/{id}/resize"),
call("sessions.signal", "POST", "/v1/sessions/{id}/signal"),
- call("tasks.list", "GET", "/v1/tasks"),
- call("tasks.run", "POST", "/v1/tasks/{name}"),
+ call("actions.list", "GET", "/v1/actions"),
+ call("actions.run", "POST", "/v1/actions/{action}"),
call(
- "tasks.choices",
+ "actions.choices",
"GET",
- "/v1/tasks/{name}/choices/{argument}",
+ "/v1/actions/{action}/choices/{argument}",
),
call("system.stats", "GET", "/v1/stats"),
call("system.power", "POST", "/v1/power/{verb}"),
@@ -218,6 +242,11 @@ pub static HOST: &[Op] = &[
"/v1/services/{plugin}/{name}/{method}",
),
stream("services.serve", "/v1/services/{plugin}/{name}/serve"),
+ stream("ports.connect", "/v1/ports/{port}"),
+ server_only(
+ stream("endpoints.connect", "/v1/endpoints/{address}/{port}"),
+ "berth serve dials it itself, only for an endpoint a provisioner reported: open the endpoint with resources.connect",
+ ),
];
const IF_MATCH: (&str, &str) = ("if_match", "if-match");
@@ -248,9 +277,13 @@ pub static SERVE: &[Op] = &[
call("hosts.act", "POST", "/v1/hosts/{name}/actions/{action}"),
Role::View,
),
- call("actions.list", "GET", "/v1/actions"),
+ call("installation.actions", "GET", "/v1/installation/actions"),
role(
- call("actions.act", "POST", "/v1/actions/{action}"),
+ call(
+ "installation.act",
+ "POST",
+ "/v1/installation/actions/{action}",
+ ),
Role::View,
),
admin(call("secrets.list", "GET", "/v1/secrets")),
@@ -321,10 +354,16 @@ pub static SERVE: &[Op] = &[
Role::Operate,
),
stream("resources.follow", "/v1/resources/{id}/logs"),
+ stream(
+ "resources.connect",
+ "/v1/resources/{id}/endpoints/{endpoint}",
+ ),
call("jobs.list", "GET", "/v1/jobs"),
call("jobs.get", "GET", "/v1/jobs/{id}"),
role(stream("jobs.follow", "/v1/jobs/{id}"), Role::View),
call("jobs.output", "GET", "/v1/jobs/{id}/output"),
+ // Anyone let in may ask; the role that starts a job of its kind is checked.
+ role(call("jobs.stop", "POST", "/v1/jobs/{id}/stop"), Role::View),
call("inbox.list", "GET", "/v1/inbox"),
role(stream("inbox.follow", "/v1/inbox"), Role::View),
call("inbox.done", "POST", "/v1/inbox/{host}/{id}/done"),
@@ -445,6 +484,7 @@ mod tests {
assert_eq!(role(HOST, "files.read"), Role::Operate);
assert_eq!(role(HOST, "applied.profile"), Role::Admin);
assert_eq!(role(HOST, "sessions.attach"), Role::Operate);
+ assert_eq!(role(HOST, "ports.connect"), Role::Operate);
assert_eq!(role(SERVE, "hosts.save"), Role::Admin);
assert_eq!(role(SERVE, "hosts.act"), Role::View);
assert_eq!(role(SERVE, "provisioners.get"), Role::View);
@@ -456,6 +496,7 @@ mod tests {
assert_eq!(role(SERVE, "resources.act"), Role::View);
assert_eq!(role(SERVE, "resources.logs"), Role::Operate);
assert_eq!(role(SERVE, "resources.follow"), Role::Operate);
+ assert_eq!(role(SERVE, "resources.connect"), Role::Operate);
let (op, args) = recognise(
SERVE,
Kind::Call,
diff --git a/crates/berth-api/src/portal.rs b/crates/berth-api/src/portal.rs
index 5f97bf8..fc0fa83 100644
--- a/crates/berth-api/src/portal.rs
+++ b/crates/berth-api/src/portal.rs
@@ -2,14 +2,14 @@
//! WebSocket. The frames are described in [`crate::ops`].
use crate::client::{Error, Result};
-use futures_util::{Sink, SinkExt, Stream, StreamExt};
+use futures_util::{Sink, SinkExt, Stream, StreamExt, task::AtomicWaker};
use serde_json::{Value, json};
use std::{
collections::HashMap,
pin::Pin,
sync::{
Arc, Mutex,
- atomic::{AtomicU32, Ordering},
+ atomic::{AtomicBool, AtomicI64, AtomicU32, AtomicUsize, Ordering},
},
task::{Context, Poll},
};
@@ -27,15 +27,152 @@ pub enum Piece {
}
enum Event {
- Piece(Piece),
+ /// A frame, with the bytes it counts as unread.
+ Piece(Piece, usize),
End(Option),
}
+/// The window a client asks for on each stream it opens: bytes of binary
+/// frames on their way each way. Its frames wait in the other side's queue
+/// for its reader, so this is what one stream can hold there.
+pub const WINDOW: u32 = 256 * 1024;
+
+/// The least and the most window a server takes.
+pub const WINDOWS: (u32, u32) = (16 * 1024, 4 << 20);
+
+/// The most bytes of one message on the portal: an operation's bytes as
+/// base64, and room for the rest of the frame.
+pub const FRAME_BYTES: usize = crate::ops::PORTAL_BYTES / 3 * 4 + (1 << 20);
+
+/// The most bytes a server holds for one portal's calls in flight, their
+/// answers until they are written, and input waiting for its stream.
+pub const HELD_BYTES: usize = 64 << 20;
+
+/// The most calls in flight on one portal.
+pub const CALLS: usize = 256;
+
+/// The most streams open on one portal.
+pub const STREAMS: usize = 256;
+
+/// The most bytes of a stream a client holds that it has not read yet. A
+/// server within the window sends far less; one that sends more ends the
+/// stream.
+pub const UNREAD_BYTES: usize = 16 << 20;
+
+/// The longest name of an operation a server takes.
+pub const NAME_BYTES: usize = 128;
+
+/// The longest message of an error a server sends back.
+pub const MESSAGE_BYTES: usize = 2048;
+
+/// A message cut to [`MESSAGE_BYTES`], at a character.
+pub fn shorten(message: &str) -> String {
+ if message.len() <= MESSAGE_BYTES {
+ return message.to_owned();
+ }
+ let mut end = MESSAGE_BYTES - 3;
+ while !message.is_char_boundary(end) {
+ end -= 1;
+ }
+ format!("{}…", &message[..end])
+}
+
+/// What one side of a stream may still send, by what the other side said it
+/// took. Without a window it may always send.
+#[derive(Default)]
+pub struct Credit {
+ on: AtomicBool,
+ room: AtomicI64,
+ waiting: AtomicWaker,
+}
+
+impl Credit {
+ pub fn with(window: Option) -> Credit {
+ let credit = Credit::default();
+ if let Some(window) = window {
+ credit.start(window);
+ }
+ credit
+ }
+
+ pub fn start(&self, window: u32) {
+ self.room.store(window as i64, Ordering::SeqCst);
+ self.on.store(true, Ordering::SeqCst);
+ }
+
+ /// The other side took so many more bytes.
+ pub fn grant(&self, bytes: u64) {
+ self.room
+ .fetch_add(bytes.min(i64::MAX as u64) as i64, Ordering::SeqCst);
+ self.waiting.wake();
+ }
+
+ /// So many bytes were sent. One frame may go beyond the window, so a
+ /// frame larger than it is not held forever.
+ pub fn spend(&self, bytes: usize) {
+ if self.on.load(Ordering::SeqCst) {
+ self.room.fetch_sub(bytes as i64, Ordering::SeqCst);
+ }
+ }
+
+ /// Ready once a frame may be sent. One task waits on it at a time.
+ pub fn poll_room(&self, cx: &mut Context<'_>) -> Poll<()> {
+ let open = || !self.on.load(Ordering::SeqCst) || self.room.load(Ordering::SeqCst) > 0;
+ if open() {
+ return Poll::Ready(());
+ }
+ self.waiting.register(cx.waker());
+ // A grant between the look and the registration would be missed otherwise.
+ if open() {
+ Poll::Ready(())
+ } else {
+ Poll::Pending
+ }
+ }
+
+ pub async fn room(&self) {
+ std::future::poll_fn(|cx| self.poll_room(cx)).await
+ }
+}
+
+/// What the receiving side of a stream took and has not yet said: the credit
+/// to send, once it is half the window, so not every frame costs one.
+pub struct Taken {
+ window: Option,
+ bytes: u64,
+}
+
+impl Taken {
+ pub fn new(window: Option) -> Taken {
+ Taken { window, bytes: 0 }
+ }
+
+ /// The frame that says what was taken, when it is time for one.
+ pub fn took(&mut self, sub: u32, bytes: usize) -> Option {
+ let window = self.window?;
+ self.bytes += bytes as u64;
+ if self.bytes < u64::from(window / 2) {
+ return None;
+ }
+ let credit = std::mem::take(&mut self.bytes);
+ Some(json!({"sub": sub, "credit": credit}))
+ }
+}
+
+struct Open {
+ frames: mpsc::UnboundedSender,
+ credit: Arc,
+ /// Bytes of its frames that are not read yet.
+ unread: Arc,
+}
+
#[derive(Default)]
struct Shared {
next: AtomicU32,
calls: Mutex>>>,
- streams: Mutex>>,
+ // Unbounded so the reader never waits on one stream: what the server may
+ // send a stream with a window is bounded by it.
+ streams: Mutex>,
/// Why the connection ended, once it has.
closed: Mutex