mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
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:
@@ -1,18 +1,20 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use crate::config::action::ConfigRes;
|
||||||
use crate::util::display_none;
|
use crate::util::display_none;
|
||||||
use color_eyre::eyre::eyre;
|
use color_eyre::eyre::eyre;
|
||||||
use emver::VersionRange;
|
use emver::VersionRange;
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use patch_db::{DbHandle, HasModel, Map, MapModel, PatchDbHandle};
|
use patch_db::{DbHandle, HasModel, Map, MapModel, PatchDbHandle};
|
||||||
|
use rand::SeedableRng;
|
||||||
use rpc_toolkit::command;
|
use rpc_toolkit::command;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use crate::action::{ActionImplementation, NoOutput};
|
use crate::action::{ActionImplementation, NoOutput};
|
||||||
use crate::config::Config;
|
use crate::config::{Config, ConfigSpec};
|
||||||
use crate::context::RpcContext;
|
use crate::context::RpcContext;
|
||||||
use crate::db::model::CurrentDependencyInfo;
|
use crate::db::model::CurrentDependencyInfo;
|
||||||
use crate::error::ResultExt;
|
use crate::error::ResultExt;
|
||||||
@@ -462,7 +464,11 @@ pub async fn configure_impl(
|
|||||||
(pkg_id, dep_id): (PackageId, PackageId),
|
(pkg_id, dep_id): (PackageId, PackageId),
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut db = ctx.db.handle();
|
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(
|
Ok(crate::config::configure(
|
||||||
&ctx,
|
&ctx,
|
||||||
&mut db,
|
&mut db,
|
||||||
@@ -476,12 +482,20 @@ pub async fn configure_impl(
|
|||||||
.await?)
|
.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))]
|
#[command(rename = "dry", display(display_serializable))]
|
||||||
#[instrument(skip(ctx))]
|
#[instrument(skip(ctx))]
|
||||||
pub async fn configure_dry(
|
pub async fn configure_dry(
|
||||||
#[context] ctx: RpcContext,
|
#[context] ctx: RpcContext,
|
||||||
#[parent_data] (pkg_id, dependency_id): (PackageId, PackageId),
|
#[parent_data] (pkg_id, dependency_id): (PackageId, PackageId),
|
||||||
) -> Result<Config, Error> {
|
) -> Result<ConfigDryRes, Error> {
|
||||||
let mut db = ctx.db.handle();
|
let mut db = ctx.db.handle();
|
||||||
configure_logic(ctx, &mut db, (pkg_id, dependency_id)).await
|
configure_logic(ctx, &mut db, (pkg_id, dependency_id)).await
|
||||||
}
|
}
|
||||||
@@ -490,7 +504,7 @@ pub async fn configure_logic(
|
|||||||
ctx: RpcContext,
|
ctx: RpcContext,
|
||||||
db: &mut PatchDbHandle,
|
db: &mut PatchDbHandle,
|
||||||
(pkg_id, dependency_id): (PackageId, PackageId),
|
(pkg_id, dependency_id): (PackageId, PackageId),
|
||||||
) -> Result<Config, Error> {
|
) -> Result<ConfigDryRes, Error> {
|
||||||
let pkg_model = crate::db::DatabaseModel::new()
|
let pkg_model = crate::db::DatabaseModel::new()
|
||||||
.package_data()
|
.package_data()
|
||||||
.idx_model(&pkg_id)
|
.idx_model(&pkg_id)
|
||||||
@@ -563,26 +577,38 @@ pub async fn configure_logic(
|
|||||||
crate::ErrorKind::NotFound,
|
crate::ErrorKind::NotFound,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
let config: Config = dependency_config_action
|
let ConfigRes {
|
||||||
|
config: maybe_config,
|
||||||
|
spec,
|
||||||
|
} = dependency_config_action
|
||||||
.get(
|
.get(
|
||||||
&ctx,
|
&ctx,
|
||||||
&dependency_id,
|
&dependency_id,
|
||||||
&*dependency_version,
|
&*dependency_version,
|
||||||
&*dependency_volumes,
|
&*dependency_volumes,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.config
|
|
||||||
.ok_or_else(|| {
|
let old_config = if let Some(config) = maybe_config {
|
||||||
Error::new(
|
config
|
||||||
eyre!("no config get action found for {}", dependency_id),
|
} else {
|
||||||
crate::ErrorKind::NotFound,
|
spec.gen(
|
||||||
)
|
&mut rand::rngs::StdRng::from_entropy(),
|
||||||
})?;
|
&Some(Duration::new(10, 0)),
|
||||||
Ok(dependency
|
)?
|
||||||
|
};
|
||||||
|
|
||||||
|
let new_config = dependency
|
||||||
.auto_configure
|
.auto_configure
|
||||||
.sandboxed(&ctx, &pkg_id, &pkg_version, &pkg_volumes, Some(config))
|
.sandboxed(&ctx, &pkg_id, &pkg_version, &pkg_volumes, Some(&old_config))
|
||||||
.await?
|
.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))]
|
#[instrument(skip(db, current_dependencies))]
|
||||||
|
|||||||
20
ui/README.md
20
ui/README.md
@@ -2,7 +2,15 @@
|
|||||||
|
|
||||||
## Development Environment Setup
|
## 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
|
### Building The Mock Development Server
|
||||||
|
|
||||||
@@ -16,9 +24,7 @@
|
|||||||
|
|
||||||
### Building Embassy UI
|
### Building Embassy UI
|
||||||
|
|
||||||
**In a new terminal window:**
|
**In a new terminal window, from `embassy-os/ui` run:**
|
||||||
|
|
||||||
`npm i -g @ionic/cli`
|
|
||||||
|
|
||||||
`git clone https://github.com/Start9Labs/embassy-os.git`
|
`git clone https://github.com/Start9Labs/embassy-os.git`
|
||||||
|
|
||||||
@@ -28,9 +34,11 @@
|
|||||||
|
|
||||||
`cd ui/`
|
`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`
|
Copy `config-sample.json` to new file `config.json`
|
||||||
In `config.json`, edit the "mocks" section to look like the following:
|
In `config.json`, edit the "mocks" section to look like the following:
|
||||||
|
|||||||
Reference in New Issue
Block a user