save build options
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1011,6 +1011,7 @@ dependencies = [
|
||||
"log",
|
||||
"rusqlite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ env_logger = "*"
|
||||
derive_more = "*"
|
||||
log = "*"
|
||||
serde = "*"
|
||||
serde_json = "*"
|
||||
fallible-iterator = "*"
|
||||
|
||||
[target.x86_64-unknown-linux-gnu]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use rusqlite::{Connection, Result};
|
||||
use fallible_iterator::FallibleIterator;
|
||||
use crate::database::instance::Instance;
|
||||
use crate::deploy::container_options::Options;
|
||||
|
||||
const PATH: &str = "mdeploy.db";
|
||||
|
||||
@@ -35,6 +36,7 @@ impl InstanceStorage {
|
||||
docker_id TEXT,
|
||||
ip TEXT,
|
||||
domain TEXT,
|
||||
options TEXT,
|
||||
image INTEGER,
|
||||
FOREIGN KEY(image) REFERENCES images(id));
|
||||
COMMIT;"
|
||||
@@ -48,14 +50,15 @@ impl InstanceStorage {
|
||||
}
|
||||
|
||||
pub fn load_instances(&mut self) -> Result<Vec<Instance>> {
|
||||
let mut stmt = self.con.prepare("select id, docker_id, ip, domain, image from l_instances")?;
|
||||
let mut stmt = self.con.prepare("select id, docker_id, ip, domain, options, image from l_instances")?;
|
||||
let mut rows = stmt.query([])?;
|
||||
rows.map(|r| Ok(Instance{
|
||||
id: r.get::<_, i64>(0)?,
|
||||
docker_id: r.get::<_, String>(1)?,
|
||||
ip: r.get::<_, String>(2)?,
|
||||
domain: r.get::<_, String>(3)?,
|
||||
image: r.get::<_, i64>(4)?,
|
||||
ops: Options::new_from_json(r.get::<_, String>(4)?),
|
||||
image: r.get::<_, i64>(5)?,
|
||||
})).collect()
|
||||
}
|
||||
|
||||
@@ -89,18 +92,20 @@ impl InstanceStorage {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_instance(&mut self, docker_id: String, ip: String, domain: String, image: i64) -> Result<Instance>{
|
||||
pub fn new_instance(&mut self, docker_id: String, ip: String, domain: String, ops: Options, image: i64) -> Result<Instance>{
|
||||
//let image_id = self.create_or_get_image_id(image.clone(), 0)?;
|
||||
let mut stmt = self.con.prepare("INSERT INTO l_instances(docker_id, ip, domain, image) values(?1, ?2, ?3, ?4)")?;
|
||||
let mut stmt = self.con.prepare("INSERT INTO l_instances(docker_id, ip, domain, options, image) values(?1, ?2, ?3, ?4, ?5)")?;
|
||||
stmt.execute([docker_id.clone(),
|
||||
ip.clone(),
|
||||
domain.clone(),
|
||||
ops.to_json(),
|
||||
image.to_string()])?;
|
||||
Ok(Instance {
|
||||
id: image,
|
||||
docker_id: docker_id,
|
||||
ip: ip,
|
||||
domain: domain,
|
||||
ops: ops,
|
||||
image: image,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ impl MemStorage {
|
||||
container.get_id(),
|
||||
container.ip.clone(),
|
||||
container.name.clone(),
|
||||
container.ops.clone(),
|
||||
image_id)?;
|
||||
self.containers.push((ins, Some(container)));
|
||||
Ok(())
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use crate::deploy::container_options::Options;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Instance {
|
||||
pub id: i64,
|
||||
@@ -5,4 +7,5 @@ pub struct Instance {
|
||||
pub ip: String,
|
||||
pub domain: String,
|
||||
pub image: i64,
|
||||
pub ops: Options,
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct Container {
|
||||
pub net: String,
|
||||
pub docker_id: Option<String>,
|
||||
pub database_id: Option<i64>,
|
||||
ops: Options,
|
||||
pub ops: Options,
|
||||
}
|
||||
|
||||
impl Container {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#[derive(Clone)]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Result;
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct Options {
|
||||
memory: Option<String>,
|
||||
rolling_logs: bool,
|
||||
@@ -14,6 +17,21 @@ impl Options {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_from_json(json: String) -> Self {
|
||||
match serde_json::from_str(&json) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
log::warn!("Error deserialicing:{}",e);
|
||||
log::warn!("insert default values");
|
||||
Self {
|
||||
memory: None,
|
||||
msg: None,
|
||||
rolling_logs: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_config(&self) -> Vec<String> {
|
||||
let mut ret = Vec::new();
|
||||
if self.rolling_logs {
|
||||
@@ -33,5 +51,15 @@ impl Options {
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_json(&self) -> String {
|
||||
match serde_json::to_string(self) {
|
||||
Ok(j) => j,
|
||||
Err(e) => {
|
||||
log::warn!("Error serialicing:{}",e);
|
||||
String::from("")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user