Feature/gen dep config (#714)

* update ui readme

* adjust dry auto-configure to generate config for dependency and return necessary details

* fix types
This commit is contained in:
Lucy C
2021-10-21 10:13:03 -06:00
committed by Aiden McClelland
parent 9c1d2ed96d
commit 25977292e1
2 changed files with 56 additions and 22 deletions

View File

@@ -1,18 +1,20 @@
use std::collections::BTreeMap;
use std::time::Duration;
use crate::config::action::ConfigRes;
use crate::util::display_none;
use color_eyre::eyre::eyre;
use emver::VersionRange;
use futures::future::BoxFuture;
use futures::FutureExt;
use patch_db::{DbHandle, HasModel, Map, MapModel, PatchDbHandle};
use rand::SeedableRng;
use rpc_toolkit::command;
use serde::{Deserialize, Serialize};
use tracing::instrument;
use crate::action::{ActionImplementation, NoOutput};
use crate::config::Config;
use crate::config::{Config, ConfigSpec};
use crate::context::RpcContext;
use crate::db::model::CurrentDependencyInfo;
use crate::error::ResultExt;
@@ -462,7 +464,11 @@ pub async fn configure_impl(
(pkg_id, dep_id): (PackageId, PackageId),
) -> Result<(), Error> {
let mut db = ctx.db.handle();
let new_config = configure_logic(ctx.clone(), &mut db, (pkg_id, dep_id.clone())).await?;
let ConfigDryRes {
old_config: _,
new_config,
spec: _,
} = configure_logic(ctx.clone(), &mut db, (pkg_id, dep_id.clone())).await?;
Ok(crate::config::configure(
&ctx,
&mut db,
@@ -476,12 +482,20 @@ pub async fn configure_impl(
.await?)
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct ConfigDryRes {
pub old_config: Config,
pub new_config: Config,
pub spec: ConfigSpec,
}
#[command(rename = "dry", display(display_serializable))]
#[instrument(skip(ctx))]
pub async fn configure_dry(
#[context] ctx: RpcContext,
#[parent_data] (pkg_id, dependency_id): (PackageId, PackageId),
) -> Result<Config, Error> {
) -> Result<ConfigDryRes, Error> {
let mut db = ctx.db.handle();
configure_logic(ctx, &mut db, (pkg_id, dependency_id)).await
}
@@ -490,7 +504,7 @@ pub async fn configure_logic(
ctx: RpcContext,
db: &mut PatchDbHandle,
(pkg_id, dependency_id): (PackageId, PackageId),
) -> Result<Config, Error> {
) -> Result<ConfigDryRes, Error> {
let pkg_model = crate::db::DatabaseModel::new()
.package_data()
.idx_model(&pkg_id)
@@ -563,26 +577,38 @@ pub async fn configure_logic(
crate::ErrorKind::NotFound,
)
})?;
let config: Config = dependency_config_action
let ConfigRes {
config: maybe_config,
spec,
} = dependency_config_action
.get(
&ctx,
&dependency_id,
&*dependency_version,
&*dependency_volumes,
)
.await?
.config
.ok_or_else(|| {
Error::new(
eyre!("no config get action found for {}", dependency_id),
crate::ErrorKind::NotFound,
)
})?;
Ok(dependency
.await?;
let old_config = if let Some(config) = maybe_config {
config
} else {
spec.gen(
&mut rand::rngs::StdRng::from_entropy(),
&Some(Duration::new(10, 0)),
)?
};
let new_config = dependency
.auto_configure
.sandboxed(&ctx, &pkg_id, &pkg_version, &pkg_volumes, Some(config))
.sandboxed(&ctx, &pkg_id, &pkg_version, &pkg_volumes, Some(&old_config))
.await?
.map_err(|e| Error::new(eyre!("{}", e.1), crate::ErrorKind::AutoConfigure))?)
.map_err(|e| Error::new(eyre!("{}", e.1), crate::ErrorKind::AutoConfigure))?;
Ok(ConfigDryRes {
old_config,
new_config,
spec,
})
}
#[instrument(skip(db, current_dependencies))]

View File

@@ -2,7 +2,15 @@
## Development Environment Setup
**Make sure you have git, node, npm, and rust installed**
**Make sure you have git, nvm (node, npm), and rust installed**
```
node --version
v16.11.0
npm --version
v8.0.0
```
### Building The Mock Development Server
@@ -16,9 +24,7 @@
### Building Embassy UI
**In a new terminal window:**
`npm i -g @ionic/cli`
**In a new terminal window, from `embassy-os/ui` run:**
`git clone https://github.com/Start9Labs/embassy-os.git`
@@ -28,9 +34,11 @@
`cd ui/`
`npm run build-deps`
`npm --prefix . install @ionic/cli`
`npm i`
`npm --prefix . run build-deps`
`npm --prefix . install`
Copy `config-sample.json` to new file `config.json`
In `config.json`, edit the "mocks" section to look like the following: