Skip to content

Commit

Permalink
fix(system-services): allow overriding binary paths for system servic…
Browse files Browse the repository at this point in the history
…es [fixes NET-503] (#1663)

* allow overriding binary paths for system services
* set default paths
* automatically add configured paths to allowed_binaries
  • Loading branch information
kmd-fl authored Jul 14, 2023
1 parent 06f7668 commit d4ff356
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 25 deletions.
8 changes: 8 additions & 0 deletions crates/server-config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,11 @@ pub fn default_deal_contract_address_hex() -> String {
pub fn default_deal_contract_block_hex() -> String {
"latest".to_string()
}

pub fn default_ipfs_binary_path() -> String {
"/usr/bin/ipfs".to_string()
}

pub fn default_curl_binary_path() -> String {
"/usr/bin/curl".to_string()
}
6 changes: 5 additions & 1 deletion crates/server-config/src/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ impl UnresolvedNodeConfig {
.unwrap_or(KeypairConfig::default())
.get_keypair(default_builtins_keypair_path())?;

let mut allowed_binaries = self.allowed_binaries;
allowed_binaries.push(self.system_services.aqua_ipfs.ipfs_binary_path.clone());
allowed_binaries.push(self.system_services.connector.curl_binary_path.clone());

let result = NodeConfig {
bootstrap_nodes,
root_key_pair,
Expand Down Expand Up @@ -199,7 +203,7 @@ impl UnresolvedNodeConfig {
force_builtins_redeploy: self.force_builtins_redeploy,
transport_config: self.transport_config,
listen_config: self.listen_config,
allowed_binaries: self.allowed_binaries,
allowed_binaries,
system_services: self.system_services,
http_config: self.http_config,
};
Expand Down
20 changes: 20 additions & 0 deletions crates/server-config/src/system_services_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub struct SystemServicesConfig {
pub decider: DeciderConfig,
#[serde(default)]
pub registry: RegistryConfig,
#[serde(default)]
pub connector: ConnectorConfig,
}

impl Default for SystemServicesConfig {
Expand All @@ -68,6 +70,7 @@ impl Default for SystemServicesConfig {
aqua_ipfs: Default::default(),
decider: Default::default(),
registry: Default::default(),
connector: Default::default(),
}
}
}
Expand All @@ -78,13 +81,30 @@ pub struct AquaIpfsConfig {
pub external_api_multiaddr: String,
#[serde(default = "default_ipfs_multiaddr")]
pub local_api_multiaddr: String,
#[serde(default = "default_ipfs_binary_path")]
pub ipfs_binary_path: String,
}

impl Default for AquaIpfsConfig {
fn default() -> Self {
Self {
external_api_multiaddr: default_ipfs_multiaddr(),
local_api_multiaddr: default_ipfs_multiaddr(),
ipfs_binary_path: default_ipfs_binary_path(),
}
}
}

#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct ConnectorConfig {
#[serde(default = "default_curl_binary_path")]
pub curl_binary_path: String,
}

impl Default for ConnectorConfig {
fn default() -> Self {
Self {
curl_binary_path: default_curl_binary_path(),
}
}
}
Expand Down
87 changes: 63 additions & 24 deletions crates/system-services/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use particle_execution::FunctionOutcome;
use particle_modules::{AddBlueprint, ModuleRepository};
use particle_services::{ParticleAppServices, ServiceError, ServiceType};
use serde_json::{json, Value as JValue};
use server_config::system_services_config::RegistryConfig;
use server_config::system_services_config::ServiceKey::*;
use server_config::{system_services_config::ServiceKey, DeciderConfig, SystemServicesConfig};
use server_config::system_services_config::{ConnectorConfig, RegistryConfig};
use server_config::{
system_services_config::ServiceKey, AquaIpfsConfig, DeciderConfig, SystemServicesConfig,
};
use sorcerer::{get_spell_info, install_spell, remove_spell};
use spell_event_bus::api::SpellEventBusApi;
use spell_storage::SpellStorage;
Expand Down Expand Up @@ -40,7 +42,7 @@ enum ServiceUpdateStatus {
// This is supposed to be in a separate lib for all system services crates
struct ServiceDistro {
modules: HashMap<&'static str, &'static [u8]>,
config: &'static [u8],
config: TomlMarineConfig,
name: String,
}

Expand Down Expand Up @@ -107,7 +109,7 @@ impl Deployer {
}

fn deploy_aqua_ipfs(&self) -> eyre::Result<()> {
let aqua_ipfs_distro = Self::get_ipfs_service_distro();
let aqua_ipfs_distro = Self::get_ipfs_service_distro(&self.config.aqua_ipfs)?;
let service_name = aqua_ipfs_distro.name.clone();
let service_id = match self.deploy_service_common(aqua_ipfs_distro)? {
ServiceStatus::Existing(_id) => {
Expand Down Expand Up @@ -138,7 +140,7 @@ impl Deployer {
}

fn deploy_connector(&self) -> eyre::Result<()> {
let connector_distro = Self::get_connector_distro();
let connector_distro = Self::get_connector_distro(&self.config.connector)?;
self.deploy_service_common(connector_distro)?;
Ok(())
}
Expand All @@ -151,14 +153,14 @@ impl Deployer {

async fn deploy_registry(&self) -> eyre::Result<()> {
let (registry_distro, registry_spell_distro) =
Self::get_registry_distro(self.config.registry.clone());
Self::get_registry_distro(self.config.registry.clone())?;
self.deploy_service_common(registry_distro)?;
self.deploy_system_spell(registry_spell_distro).await?;
Ok(())
}

fn deploy_trust_graph(&self) -> eyre::Result<()> {
let service_distro = Self::get_trust_graph_distro();
let service_distro = Self::get_trust_graph_distro()?;
let service_name = service_distro.name.clone();
let service_id = match self.deploy_service_common(service_distro)? {
ServiceStatus::Existing(_id) => {
Expand Down Expand Up @@ -188,19 +190,21 @@ impl Deployer {
}

// The plan is to move this to the corresponding crates
fn get_trust_graph_distro() -> ServiceDistro {
fn get_trust_graph_distro() -> eyre::Result<ServiceDistro> {
use trust_graph_distro::*;
ServiceDistro {
let config: TomlMarineConfig = toml::from_slice(CONFIG)?;
Ok(ServiceDistro {
modules: modules(),
config: CONFIG,
config,
name: TrustGraph.to_string(),
}
})
}

fn get_registry_distro(config: RegistryConfig) -> (ServiceDistro, SpellDistro) {
fn get_registry_distro(config: RegistryConfig) -> eyre::Result<(ServiceDistro, SpellDistro)> {
let marine_config: TomlMarineConfig = toml::from_slice(registry_distro::CONFIG)?;
let distro = ServiceDistro {
modules: registry_distro::modules(),
config: registry_distro::CONFIG,
config: marine_config,
name: Registry.to_string(),
};

Expand All @@ -220,25 +224,42 @@ impl Deployer {
trigger_config,
};

(distro, spell_distro)
Ok((distro, spell_distro))
}

fn get_ipfs_service_distro() -> ServiceDistro {
fn get_ipfs_service_distro(config: &AquaIpfsConfig) -> eyre::Result<ServiceDistro> {
use aqua_ipfs_distro::*;
ServiceDistro {
let mut marine_config: TomlMarineConfig = toml::from_slice(CONFIG)?;
Self::apply_binary_path_override(
&mut marine_config,
"ipfs_effector",
"ipfs",
config.ipfs_binary_path.clone(),
);

Ok(ServiceDistro {
modules: modules(),
config: CONFIG,
config: marine_config,
name: AquaIpfs.to_string(),
}
})
}

fn get_connector_distro() -> ServiceDistro {
fn get_connector_distro(config: &ConnectorConfig) -> eyre::Result<ServiceDistro> {
let connector_service_distro = decider_distro::connector_service_modules();
ServiceDistro {
let mut marine_config: TomlMarineConfig =
toml::from_slice(connector_service_distro.config)?;
Self::apply_binary_path_override(
&mut marine_config,
"curl_adapter",
"curl",
config.curl_binary_path.clone(),
);

Ok(ServiceDistro {
modules: connector_service_distro.modules,
config: connector_service_distro.config,
config: marine_config,
name: connector_service_distro.name.to_string(),
}
})
}

fn get_decider_distro(decider_settings: DeciderConfig) -> SpellDistro {
Expand Down Expand Up @@ -611,9 +632,8 @@ impl Deployer {
}

fn add_modules(&self, service_distro: ServiceDistro) -> eyre::Result<String> {
let marine_config: TomlMarineConfig = toml::from_slice(service_distro.config)?;
let mut hashes = Vec::new();
for config in marine_config.module {
for config in service_distro.config.module {
let name = config.name.clone();
// TODO: introduce nice errors for this
let module = service_distro
Expand All @@ -640,4 +660,23 @@ impl Deployer {
.add_blueprint(AddBlueprint::new(service_distro.name, hashes))?;
Ok(blueprint_id)
}

/// Override a binary path to a binary for a module in the service configuration
fn apply_binary_path_override(
config: &mut TomlMarineConfig,
// Name of the module for which we override the path
module_name: &str,
// The name of the binary to override
binary_name: &str,
// Path to the binary to use instead
binary_path: String,
) {
if let Some(module_config) = config.module.iter_mut().find(|p| p.name == module_name) {
if let Some(mounted_binaries) = &mut module_config.config.mounted_binaries {
if let Some(path) = mounted_binaries.get_mut(binary_name) {
*path = toml::Value::String(binary_path);
}
}
}
}
}

0 comments on commit d4ff356

Please sign in to comment.