Expand description
The start
module contains functionality relating to downloading and starting
NATS servers and wasmCloud hosts.
§Downloading and Starting NATS and wasmCloud
use anyhow::{anyhow, Result};
use wash_lib::common::CommandGroupUsage;
use wash_lib::start::{
start_wasmcloud_host,
start_nats_server,
ensure_nats_server,
ensure_wasmcloud,
NatsConfig
};
use std::path::PathBuf;
#[tokio::main]
async fn main() -> Result<()> {
let install_dir = PathBuf::from("/tmp");
// Download NATS if not already installed
let nats_binary = ensure_nats_server("v2.10.7", &install_dir).await?;
// Start NATS server, redirecting output to a log file
let nats_log_path = install_dir.join("nats.log");
let nats_log_file = tokio::fs::File::create(&nats_log_path).await?.into_std().await;
let config = NatsConfig::new_standalone("127.0.0.1", 4222, None);
let mut nats_process = start_nats_server(
nats_binary,
nats_log_file,
config,
CommandGroupUsage::UseParent,
).await?;
// Download wasmCloud if not already installed
let wasmcloud_executable = ensure_wasmcloud("v0.57.1", &install_dir).await?;
// Redirect output (which is on stderr) to a log file
let log_path = install_dir.join("wasmcloud_stderr.log");
let log_file = tokio::fs::File::create(&log_path).await?.into_std().await;
let mut wasmcloud_process = start_wasmcloud_host(
wasmcloud_executable,
std::process::Stdio::null(),
log_file,
std::collections::HashMap::new(),
).await?;
// Park thread, wasmCloud and NATS are running
// Terminate processes
nats_process.kill().await?;
wasmcloud_process.kill().await?;
Ok(())
}
Structs§
- GitHub
Release - GitHubRelease represents the necessary fields to determine wadm and/or wasmCloud GitHub release (https://developer.github.com/v3/repos/releases/) object has new patch version available. The fields are based on the response from the response schema from the docs.
- Nats
Config - Configuration for a NATS server that supports running either in “standalone” or “leaf” mode.
See the respective
NatsConfig::new_standalone
andNatsConfig::new_leaf
implementations below for more information. - Wadm
Config - Configuration for wadm
Constants§
- DOWNLOAD_
CLIENT_ USER_ AGENT - GITHUB_
WASMCLOUD_ ORG - GITHUB_
WASMCLOUD_ WADM_ REPO - GITHUB_
WASMCLOUD_ WASMCLOUD_ REPO - NATS_
SERVER_ BINARY - NATS_
SERVER_ CONF - NATS_
SERVER_ PID - WADM_
BINARY - WADM_
PID - WASMCLOUD_
HOST_ BIN
Functions§
- download_
binary_ from_ github - Reusable function to download a release tarball from GitHub and extract an embedded binary to a specified directory
- download_
nats_ server - Downloads the NATS binary for the architecture and operating system of the current host machine.
- download_
wadm - Downloads the wadm binary for the architecture and operating system of the current host machine.
- download_
wasmcloud - A wrapper around the
download_wasmcloud_for_os_arch_pair
function that uses the architecture and operating system of the current host machine. - download_
wasmcloud_ for_ os_ arch_ pair - Downloads the specified GitHub release version of the wasmCloud host from https://github.com/wasmCloud/wasmcloud-otp/releases/ and unpacking the contents for a specified OS/ARCH pair to a directory. Returns the path to the Elixir executable.
- ensure_
nats_ server - Downloads the NATS binary for the architecture and operating system of the current host machine.
- ensure_
nats_ server_ for_ os_ arch_ pair - Ensures the
nats-server
binary is installed, returning the path to the executable early if it exists or downloading the specified GitHub release version of nats-server from https://github.com/nats-io/nats-server/releases/ and unpacking the binary for a specified OS/ARCH pair to a directory. Returns the path to the NATS executable. - ensure_
wadm - Downloads the wadm binary for the architecture and operating system of the current host machine.
- ensure_
wadm_ for_ os_ arch_ pair - Ensures the
wadm
binary is installed, returning the path to the executable early if it exists or downloading the specified GitHub release version of wadm from https://github.com/wasmcloud/wadm/releases/ and unpacking the binary for a specified OS/ARCH pair to a directory. Returns the path to the wadm executable. - ensure_
wasmcloud - A wrapper around the
ensure_wasmcloud_for_os_arch_pair
function that uses the architecture and operating system of the current host machine. - ensure_
wasmcloud_ for_ os_ arch_ pair - Ensures the
wasmcloud_host
application is installed, returning the path to the executable early if it exists or downloading the specified GitHub release version of the wasmCloud host from https://github.com/wasmCloud/wasmcloud-otp/releases/ and unpacking the contents for a specified OS/ARCH pair to a directory. Returns the path to the executable. - find_
wasmcloud_ binary - Helper function to indicate if the wasmCloud host tarball is successfully installed in a directory. Returns the path to the binary if it exists
- get_
download_ client - Helper function to set up a reqwest client for performing the download
- nats_
pid_ path - Helper function to get the path to the NATS server pid file
- new_
patch_ releases_ after - Get a full list of github patch releases that exist after the provided version.
- new_
patch_ version_ of_ after_ string - Returns the latest patch version of the provided version.
- start_
nats_ server - Helper function to execute a NATS server binary with required wasmCloud arguments, e.g.
JetStream
- start_
wadm - Helper function to execute a wadm binary with optional arguments. This function does not check to see if a wadm instance is already running or managing a lattice as wadm does not need to be a singleton.
- start_
wasmcloud_ host - Helper function to start a wasmCloud host given the path to the burrito release application
- wait_
for_ server