Skip to content

Commit

Permalink
Merge pull request #155 from Holo-Host/holo_happ_manager/06-12
Browse files Browse the repository at this point in the history
Holo happ manager script
  • Loading branch information
zo-el committed Jun 29, 2023
2 parents 2da1634 + bdace4b commit 10ba548
Show file tree
Hide file tree
Showing 26 changed files with 661 additions and 67 deletions.
64 changes: 49 additions & 15 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
members = [
"crates/configure-holochain",
"crates/hpos_connect_hc",
"crates/holo_happ_manager",
"crates/test_utils"
]

[profile.dev]
Expand Down
8 changes: 3 additions & 5 deletions crates/configure-holochain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "configure-holochain"
version = "0.4.0"
version = "0.5.0"
authors = ["Oleksii Filonenko <[email protected]>", "zo-el <[email protected]>"]
edition = "2021"

Expand All @@ -15,7 +15,7 @@ url = "2.2"
# observability = "0.1.3"
holochain_types = "0.2.0"
thiserror = "1.0"
hpos_hc_connect = { path = "../hpos_connect_hc" }
hpos_hc_connect = { version = "0.1.0", path = "../hpos_connect_hc" }

[dependencies.hpos-config-core]
git = "https://github.com/Holo-Host/hpos-config"
Expand All @@ -25,8 +25,6 @@ rev = "bfaced6044ae570bf20d4528fa9aaafcc43ddeec"
nix = "0.26.2"

[dev-dependencies]
lair_keystore_api = "0.2.3"
snafu = "0.7.1"
chrono = "0.4.22"
test-case = "2.2.2"
serial_test = { version = "0.9.0", features = ["async"] }
test_utils = { path = "../test_utils" }
13 changes: 7 additions & 6 deletions crates/configure-holochain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod utils;

#[instrument(err, skip(config))]
pub async fn run(config: Config) -> Result<()> {
debug!("Starting...");
debug!("Starting configure holochain...");
let happ_file = HappsFile::load_happ_file(&config.happs_file_path)
.context("failed to load hApps YAML config")?;
install_happs(&happ_file, &config).await?;
Expand Down Expand Up @@ -53,7 +53,7 @@ pub async fn install_happs(happ_file: &HappsFile, config: &Config) -> Result<()>
} else {
info!("Installing app {}", &happ.id());
let mem_proof_vec =
hpos_membrane_proof::create_vec_for_happ(&happ.id(), agent.membrane_proof.clone())
hpos_membrane_proof::create_vec_for_happ(happ, agent.membrane_proof.clone())
.await?;

if let Err(err) = admin_websocket
Expand Down Expand Up @@ -111,9 +111,10 @@ async fn install_ui(happ: &Happ, config: &Config) -> Result<()> {
.context("failed to download UI archive")?
}
};

let unpack_path = config.ui_store_folder.join(happ.ui_name());
extract_zip(&source_path, &unpack_path).context("failed to extract UI archive")?;
debug!("installed UI: {}", happ.id());
if let Some(ui_home) = config.ui_store_folder.clone() {
let unpack_path = ui_home.join(happ.ui_name());
extract_zip(&source_path, &unpack_path).context("failed to extract UI archive")?;
debug!("installed UI: {}", happ.id());
}
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{
'bundle_url': 'https://github.com/Holo-Host/dummy-dna/releases/download/v0.6.1/test-skip-proof.happ',
'ui_url': 'https://github.com/holochain/elemental-chat-ui/releases/download/v0.0.1-alpha40/elemental-chat-ui.zip',
"agent_bundle_override" : "../test_utils/config/hp-primary-bzywj.json",
},
],
}
19 changes: 11 additions & 8 deletions crates/configure-holochain/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod setup;
use anyhow::Context;
use configure_holochain;
use hpos_config_core::Config;
Expand Down Expand Up @@ -55,10 +54,13 @@ use test_case::test_case;

async fn run_configure_holochain(f_r_a_k: &str, r_o_m_p: &str) {
// Point HPOS_CONFIG_PATH to test config file
set_var("HPOS_CONFIG_PATH", "./tests/config/hp-primary-bzywj.json");
set_var(
"HPOS_CONFIG_PATH",
"../test_utils/config/hp-primary-bzywj.json",
);

let tmp_dir = setup::holochain::create_tmp_dir();
let log_dir = setup::holochain::create_log_dir();
let tmp_dir = test_utils::holochain::create_tmp_dir();
let log_dir = test_utils::holochain::create_log_dir();

// Set HOST_PUBKEY_PATH in a writable temp location
set_var("HOST_PUBKEY_PATH", &tmp_dir.clone().join("agent.key"));
Expand Down Expand Up @@ -89,17 +91,18 @@ async fn run_configure_holochain(f_r_a_k: &str, r_o_m_p: &str) {
// spin up lair
println!("Starting lair-keystore");
let (_lair, lair_config) =
setup::lair::spawn(&tmp_dir, &log_dir, &device_bundle, None).unwrap();
test_utils::lair::spawn(&tmp_dir, &log_dir, &device_bundle, None).unwrap();

println!("Spinning up holochain");
let _holochain = setup::holochain::spawn_holochain(&tmp_dir, &log_dir, lair_config);
let _holochain = test_utils::holochain::spawn_holochain(&tmp_dir, &log_dir, lair_config);

let happs_file_path: PathBuf = "./tests/config/config.yaml".into();
let happs_file_path: PathBuf = "./tests/config.yaml".into();
let config = hpos_hc_connect::holo_config::Config {
admin_port: 4444,
happ_port: 42233,
ui_store_folder: "./tmp".into(),
ui_store_folder: Some("./tmp".into()),
happs_file_path: happs_file_path.clone(),
lair_url: None,
};
println!("Test running with config: {:?}", &config);

Expand Down
30 changes: 30 additions & 0 deletions crates/holo_happ_manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "holo_happ_manager"
version = "0.1.0"
authors = ["zo-el <[email protected]>"]
edition = "2021"

[dependencies]
anyhow = "1.0"
hpos_hc_connect = { version = "0.1.0", path = "../hpos_connect_hc" }
holochain_conductor_api = "0.2.0"
holochain_types = "0.2.0"
holochain_keystore = "0.2.0"
getrandom = "0.2.10"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.96"
sodoken = "0.0.9"
rmp-serde = "1.1.1"
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
tokio = "1.28.2"
url2 = "0.0.6"

[dev-dependencies]
configure-holochain = { version = "0.5.0", path = "../configure-holochain"}
serial_test = { version = "0.9.0", features = ["async"] }
test_utils = { version = "0.1.0", path = "../test_utils" }

[dev-dependencies.hpos-config-core]
git = "https://github.com/Holo-Host/hpos-config"
rev = "bfaced6044ae570bf20d4528fa9aaafcc43ddeec"
37 changes: 37 additions & 0 deletions crates/holo_happ_manager/src/get_my_apps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use super::hha::HHAAgent;
use anyhow::{anyhow, Result};
use holochain_conductor_api::AppResponse;
use holochain_types::prelude::ActionHashB64;
use holochain_types::prelude::{zome_io::ExternIO, FunctionName, ZomeName};
use hpos_hc_connect::holo_config::{Config, Happ};
use serde::Deserialize;
use tracing::debug;

#[derive(Deserialize, Debug, Clone)]
pub struct PresentedHappBundle {
pub id: ActionHashB64,
pub bundle_url: String,
}

pub async fn published(core_happ: &Happ, config: &Config) -> Result<Vec<PresentedHappBundle>> {
let mut agent = HHAAgent::spawn(core_happ, config).await?;
let response = agent
.zome_call(
ZomeName::from("hha"),
FunctionName::from("get_my_happs"),
ExternIO::encode(())?,
)
.await?;

match response {
// This is the happs list that is returned from the hha DNA
// https://github.com/Holo-Host/holo-hosting-app-rsm/blob/develop/zomes/hha/src/lib.rs#L54
// return Vec of happ_list.happ_id
AppResponse::ZomeCalled(r) => {
let happ_bundles: Vec<PresentedHappBundle> = rmp_serde::from_slice(r.as_bytes())?;
debug!("got happ bundles {:?}", happ_bundles);
Ok(happ_bundles)
}
_ => Err(anyhow!("unexpected response: {:?}", response)),
}
}
Loading

0 comments on commit 10ba548

Please sign in to comment.