Skip to content

Commit

Permalink
Add acap-ssh-utils bin and lib crate
Browse files Browse the repository at this point in the history
Benefits of having this include
* documents how to quickly deploy and test incremental changes.
* makes it easier for other tools to do so by taking care of the many
  details while presenting a friendly interface.

This will come in handy for implementing analogs of `cargo run` and
`cargo test`, both of which will cross-compile a binary and execute it
on target.

Exclude the new crate when checking other targets because supporting
other targets is not a priority, especially not for this crate that
will depend on `sshpass`, `ssh`, and `scp` for the foreseeable future
which makes it less portable.

Change the behavior of `make run` to always set the `RUST_LOG*`
environment variables to decouple the log level of the tool that runs
on host from the log level of the app that is running on target.

Always require a password because it is not possible to set up public
key authentication for users other than root, so we have to support
password authentication and supporting only one method makes both the
implementation and the user experience more straightforward.
  • Loading branch information
andersplj authored and apljungquist committed May 9, 2024
1 parent e6e76d4 commit b18c252
Show file tree
Hide file tree
Showing 6 changed files with 431 additions and 5 deletions.
133 changes: 131 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ stop:
## * The app is stopped.
## * The device has SSH enabled the ssh user root configured.
run: target/$(ARCH)/$(PACKAGE)/$(PACKAGE)
scp $< root@$(DEVICE_IP):/usr/local/packages/$(PACKAGE)/$(PACKAGE)
ssh root@$(DEVICE_IP) \
"cd /usr/local/packages/$(PACKAGE) && su - acap-$(PACKAGE) -s /bin/sh --preserve-environment -c '$(if $(RUST_LOG_STYLE),RUST_LOG_STYLE=$(RUST_LOG_STYLE) )$(if $(RUST_LOG),RUST_LOG=$(RUST_LOG) )./$(PACKAGE)'"
acap-ssh-utils $(DEVICE_IP) --password $(PASS) run \
--environment RUST_LOG=debug \
--environment RUST_LOG_STYLE=always \
$< $(PACKAGE)

## Install development dependencies
sync_env:
cargo install --root venv --target-dir $(CURDIR)/target --path $(CURDIR)/crates/acap-ssh-utils
cargo install --root venv --target-dir $(CURDIR)/target cross
PIP_CONSTRAINT=constraints.txt pip install --requirement requirements.txt

Expand All @@ -111,6 +113,7 @@ check_build: target/aarch64/$(PACKAGE)/_envoy target/armv7hf/$(PACKAGE)/_envoy
--exclude licensekey_handler \
--workspace
cross build \
--exclude acap-ssh-utils \
--target aarch64-unknown-linux-gnu \
--workspace

Expand All @@ -127,6 +130,7 @@ check_docs:
--workspace
RUSTDOCFLAGS="-Dwarnings" cross doc \
--document-private-items \
--exclude acap-ssh-utils \
--no-deps \
--target aarch64-unknown-linux-gnu \
--workspace
Expand All @@ -148,6 +152,7 @@ check_lint:
--workspace
RUSTFLAGS="-Dwarnings" cross clippy \
--all-targets \
--exclude acap-ssh-utils \
--no-deps \
--target aarch64-unknown-linux-gnu \
--workspace
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Ensure global prerequisites are installed:
* Docker
* Rust e.g. [using rustup](https://www.rust-lang.org/tools/install)
* Python e.g. using [pyenv](https://github.com/pyenv/pyenv)
* `scp`, `ssh`, and `sshpass` (needed only for `make run`)

Create, activate and populate the local development environment like

Expand Down
11 changes: 11 additions & 0 deletions crates/acap-ssh-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "acap-ssh-utils"
version = "0.0.0"
edition.workspace = true

[dependencies]
anyhow = { version = "1.0.79" }
clap = { version = "4.5.1", features = ["derive"] }
env_logger = { version = "0.11.1" }
log = { version = "0.4.21" }
url = { version = "2.5.0" }
Loading

0 comments on commit b18c252

Please sign in to comment.