mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 20:43:41 +00:00
switch to managers: wip
This commit is contained in:
@@ -7,7 +7,6 @@ use serde::{Deserialize, Serialize};
|
||||
use super::{Config, ConfigSpec};
|
||||
use crate::action::ActionImplementation;
|
||||
use crate::dependencies::Dependencies;
|
||||
use crate::net::host::Hosts;
|
||||
use crate::s9pk::manifest::PackageId;
|
||||
use crate::status::health_check::HealthCheckId;
|
||||
use crate::util::Version;
|
||||
@@ -32,10 +31,16 @@ impl ConfigActions {
|
||||
pkg_id: &PackageId,
|
||||
pkg_version: &Version,
|
||||
volumes: &Volumes,
|
||||
hosts: &Hosts,
|
||||
) -> Result<ConfigRes, Error> {
|
||||
self.get
|
||||
.execute(pkg_id, pkg_version, volumes, hosts, None::<()>, false)
|
||||
.execute(
|
||||
pkg_id,
|
||||
pkg_version,
|
||||
Some("GetConfig"),
|
||||
volumes,
|
||||
None::<()>,
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.and_then(|res| {
|
||||
res.map_err(|e| Error::new(anyhow!("{}", e.1), crate::ErrorKind::ConfigGen))
|
||||
@@ -48,12 +53,18 @@ impl ConfigActions {
|
||||
pkg_version: &Version,
|
||||
dependencies: &Dependencies,
|
||||
volumes: &Volumes,
|
||||
hosts: &Hosts,
|
||||
input: &Config,
|
||||
) -> Result<SetResult, Error> {
|
||||
let res: SetResult = self
|
||||
.set
|
||||
.execute(pkg_id, pkg_version, volumes, hosts, Some(input), false)
|
||||
.execute(
|
||||
pkg_id,
|
||||
pkg_version,
|
||||
Some("SetConfig"),
|
||||
volumes,
|
||||
Some(input),
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.and_then(|res| {
|
||||
res.map_err(|e| {
|
||||
|
||||
@@ -18,7 +18,6 @@ use crate::context::{EitherContext, ExtendedContext};
|
||||
use crate::db::model::{CurrentDependencyInfo, InstalledPackageDataEntryModel};
|
||||
use crate::db::util::WithRevision;
|
||||
use crate::dependencies::{BreakageRes, DependencyError, TaggedDependencyError};
|
||||
use crate::net::host::Hosts;
|
||||
use crate::s9pk::manifest::PackageId;
|
||||
use crate::util::{
|
||||
display_none, display_serializable, parse_duration, parse_stdin_deserializable, IoFormat,
|
||||
@@ -173,14 +172,7 @@ pub async fn get(
|
||||
})?;
|
||||
let version = pkg_model.clone().manifest().version().get(&mut db).await?;
|
||||
let volumes = pkg_model.manifest().volumes().get(&mut db).await?;
|
||||
let hosts = crate::db::DatabaseModel::new()
|
||||
.network()
|
||||
.hosts()
|
||||
.get(&mut db)
|
||||
.await?;
|
||||
action
|
||||
.get(ctx.extension(), &*version, &*volumes, &*hosts)
|
||||
.await
|
||||
action.get(ctx.extension(), &*version, &*volumes).await
|
||||
}
|
||||
|
||||
#[command(subcommands(self(set_impl(async)), set_dry), display(display_none))]
|
||||
@@ -209,17 +201,11 @@ pub async fn set_dry(
|
||||
let (ctx, (id, config, timeout, _)) = ctx.split();
|
||||
let rpc_ctx = ctx.as_rpc().unwrap();
|
||||
let mut db = rpc_ctx.db.handle();
|
||||
let hosts = crate::db::DatabaseModel::new()
|
||||
.network()
|
||||
.hosts()
|
||||
.get(&mut db)
|
||||
.await?;
|
||||
let mut tx = db.begin().await?;
|
||||
let mut breakages = IndexMap::new();
|
||||
configure(
|
||||
&mut tx,
|
||||
&rpc_ctx.docker,
|
||||
&*hosts,
|
||||
&id,
|
||||
config,
|
||||
&timeout,
|
||||
@@ -255,17 +241,11 @@ pub async fn set_impl(
|
||||
let (ctx, (id, config, timeout, expire_id)) = ctx.split();
|
||||
let rpc_ctx = ctx.as_rpc().unwrap();
|
||||
let mut db = rpc_ctx.db.handle();
|
||||
let hosts = crate::db::DatabaseModel::new()
|
||||
.network()
|
||||
.hosts()
|
||||
.get(&mut db)
|
||||
.await?;
|
||||
let mut tx = db.begin().await?;
|
||||
let mut breakages = IndexMap::new();
|
||||
configure(
|
||||
&mut tx,
|
||||
&rpc_ctx.docker,
|
||||
&*hosts,
|
||||
&id,
|
||||
config,
|
||||
&timeout,
|
||||
@@ -295,7 +275,6 @@ pub async fn set_impl(
|
||||
pub fn configure<'a, Db: DbHandle>(
|
||||
db: &'a mut Db,
|
||||
docker: &'a Docker,
|
||||
hosts: &'a Hosts,
|
||||
id: &'a PackageId,
|
||||
config: Option<Config>,
|
||||
timeout: &'a Option<Duration>,
|
||||
@@ -330,7 +309,7 @@ pub fn configure<'a, Db: DbHandle>(
|
||||
let ConfigRes {
|
||||
config: old_config,
|
||||
spec,
|
||||
} = action.get(id, &*version, &*volumes, &*hosts).await?;
|
||||
} = action.get(id, &*version, &*volumes).await?;
|
||||
|
||||
// determine new config to use
|
||||
let mut config = if let Some(config) = config.or_else(|| old_config.clone()) {
|
||||
@@ -379,7 +358,7 @@ pub fn configure<'a, Db: DbHandle>(
|
||||
let signal = if !dry_run {
|
||||
// run config action
|
||||
let res = action
|
||||
.set(id, &*version, &*dependencies, &*volumes, hosts, &config)
|
||||
.set(id, &*version, &*dependencies, &*volumes, &config)
|
||||
.await?;
|
||||
|
||||
// track dependencies with no pointers
|
||||
@@ -539,8 +518,7 @@ pub fn configure<'a, Db: DbHandle>(
|
||||
if let PackagePointerSpecVariant::Config { selector, multi } = ptr {
|
||||
if selector.select(*multi, &next) != selector.select(*multi, &prev) {
|
||||
if let Err(e) = configure(
|
||||
db, docker, hosts, dependent, None, timeout, dry_run, overrides,
|
||||
breakages,
|
||||
db, docker, dependent, None, timeout, dry_run, overrides, breakages,
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -575,7 +553,7 @@ pub fn configure<'a, Db: DbHandle>(
|
||||
if let Some(signal) = signal {
|
||||
docker
|
||||
.kill_container(
|
||||
&DockerAction::container_name(id, &*version),
|
||||
&DockerAction::container_name(id, None),
|
||||
Some(KillContainerOptions {
|
||||
signal: signal.to_string(),
|
||||
}),
|
||||
@@ -586,6 +564,7 @@ pub fn configure<'a, Db: DbHandle>(
|
||||
if matches!(
|
||||
e,
|
||||
bollard::errors::Error::DockerResponseConflictError { .. }
|
||||
| bollard::errors::Error::DockerResponseNotFoundError { .. }
|
||||
) {
|
||||
Ok(())
|
||||
} else {
|
||||
|
||||
@@ -1562,9 +1562,7 @@ impl PackagePointerSpec {
|
||||
.package_data()
|
||||
.idx_model(&self.package_id)
|
||||
.and_then(|pde| pde.installed())
|
||||
.and_then(|installed| {
|
||||
installed.interface_info().addresses().idx_model(interface)
|
||||
})
|
||||
.and_then(|installed| installed.interface_addresses().idx_model(interface))
|
||||
.and_then(|addresses| addresses.tor_address())
|
||||
.get(db)
|
||||
.await
|
||||
@@ -1576,9 +1574,7 @@ impl PackagePointerSpec {
|
||||
.package_data()
|
||||
.idx_model(&self.package_id)
|
||||
.and_then(|pde| pde.installed())
|
||||
.and_then(|installed| {
|
||||
installed.interface_info().addresses().idx_model(interface)
|
||||
})
|
||||
.and_then(|installed| installed.interface_addresses().idx_model(interface))
|
||||
.and_then(|addresses| addresses.lan_address())
|
||||
.get(db)
|
||||
.await
|
||||
@@ -1612,17 +1608,11 @@ impl PackagePointerSpec {
|
||||
.get(db)
|
||||
.await
|
||||
.map_err(|e| ConfigurationError::SystemError(Error::from(e)))?;
|
||||
let hosts = crate::db::DatabaseModel::new()
|
||||
.network()
|
||||
.hosts()
|
||||
.get(db)
|
||||
.await
|
||||
.map_err(|e| ConfigurationError::SystemError(Error::from(e)))?;
|
||||
if let (Some(version), Some(cfg_actions), Some(volumes)) =
|
||||
(&*version, &*cfg_actions, &*volumes)
|
||||
{
|
||||
let cfg_res = cfg_actions
|
||||
.get(&self.package_id, version, volumes, &*hosts)
|
||||
.get(&self.package_id, version, volumes)
|
||||
.await
|
||||
.map_err(|e| ConfigurationError::SystemError(Error::from(e)))?;
|
||||
if let Some(cfg) = cfg_res.config {
|
||||
|
||||
Reference in New Issue
Block a user