start to implement the configuration file and mrproxy integration
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
use crate::config::{DockerConnectionConfig, MrproxyConnectionData};
|
||||
use crate::database::exposer::MemStorage;
|
||||
use crate::database::instance::Instance;
|
||||
use crate::deploy;
|
||||
use crate::deploy::container::Container;
|
||||
use crate::deploy::container_options::Options;
|
||||
use crate::mcproxy_client::client;
|
||||
use crate::{deploy, mcproxy_client};
|
||||
use bollard::errors::Error;
|
||||
use bollard::Docker;
|
||||
use log::error;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::sync::Mutex;
|
||||
|
||||
pub struct Controller {
|
||||
@@ -13,6 +16,8 @@ pub struct Controller {
|
||||
network: String,
|
||||
storage: Mutex<MemStorage>,
|
||||
started: bool,
|
||||
docker_config: DockerConnectionConfig,
|
||||
mrproxy_config: MrproxyConnectionData,
|
||||
}
|
||||
|
||||
impl Controller {
|
||||
@@ -20,6 +25,8 @@ impl Controller {
|
||||
driver: Docker,
|
||||
network: String,
|
||||
range: String,
|
||||
docker_config: DockerConnectionConfig,
|
||||
mrproxy_config: MrproxyConnectionData,
|
||||
) -> Result<Self, bollard::errors::Error> {
|
||||
deploy::network::Network::new(driver.clone(), network.clone(), range).await?;
|
||||
let cont = Self {
|
||||
@@ -27,6 +34,8 @@ impl Controller {
|
||||
network: network,
|
||||
storage: Mutex::new(MemStorage::new().unwrap()),
|
||||
started: false,
|
||||
docker_config,
|
||||
mrproxy_config,
|
||||
};
|
||||
Ok(cont)
|
||||
}
|
||||
@@ -40,16 +49,31 @@ impl Controller {
|
||||
) -> String {
|
||||
let is_stored = self.storage.lock().unwrap().search_instance(domain.clone());
|
||||
match is_stored {
|
||||
Some(c) => match c.docker_id {
|
||||
Some(id) => id,
|
||||
None => "Container without docker_id".to_string(),
|
||||
},
|
||||
Some(c) => {
|
||||
let mut mrcp_controller =
|
||||
mcproxy_client::controller::Controller::new(&self.mrproxy_config).unwrap();
|
||||
_ = mrcp_controller.insert_new_domain(
|
||||
&domain,
|
||||
&ip.unwrap_or(c.get_ip(&self.driver).await.unwrap()),
|
||||
);
|
||||
match c.docker_id {
|
||||
Some(id) => id,
|
||||
None => "Container without docker_id".to_string(),
|
||||
}
|
||||
}
|
||||
None => {
|
||||
match self
|
||||
.load_container(None, domain.clone(), ip.clone(), image.clone(), ops)
|
||||
.await
|
||||
{
|
||||
Ok(c) => {
|
||||
let mut mrcp_controller =
|
||||
mcproxy_client::controller::Controller::new(&self.mrproxy_config)
|
||||
.unwrap();
|
||||
_ = mrcp_controller.insert_new_domain(
|
||||
&domain,
|
||||
&ip.unwrap_or(c.get_ip(&self.driver).await.unwrap()),
|
||||
);
|
||||
self.storage
|
||||
.try_lock()
|
||||
.unwrap()
|
||||
|
||||
Reference in New Issue
Block a user