mirror of
https://codeberg.org/icewind/haze.git
synced 2026-11-30 12:40:48 +01:00
feat(pin): Support pining stoped instances
Signed-off-by: Louis Chmn <louis@chmn.me>
This commit is contained in:
parent
971148b124
commit
9f1cabf49a
3 changed files with 21 additions and 27 deletions
|
|
@ -11,7 +11,7 @@ pub async fn clean(docker: &Docker, config: &HazeConfig) -> Result<()> {
|
||||||
let mut retain = Vec::new();
|
let mut retain = Vec::new();
|
||||||
let mut remove = Vec::new();
|
let mut remove = Vec::new();
|
||||||
for cloud in list {
|
for cloud in list {
|
||||||
if cloud.is_pinned(&docker).await.unwrap_or(false) {
|
if cloud.is_pinned() {
|
||||||
retain.push(cloud);
|
retain.push(cloud);
|
||||||
} else {
|
} else {
|
||||||
remove.push(cloud);
|
remove.push(cloud);
|
||||||
|
|
|
||||||
36
src/cloud.rs
36
src/cloud.rs
|
|
@ -53,7 +53,7 @@ fn get_max_php_version(base_path: &Utf8Path) -> Option<PhpVersion> {
|
||||||
PhpVersion::from_number(major, minor)
|
PhpVersion::from_number(major, minor)
|
||||||
}
|
}
|
||||||
|
|
||||||
const PINNED_FILE: &str = "/var/www/html/data/.haze-pinned";
|
const PINNED_FILE: &str = ".haze-pinned";
|
||||||
|
|
||||||
fn enabled_apps(config: &HazeConfig, options: &CloudOptions) -> Vec<String> {
|
fn enabled_apps(config: &HazeConfig, options: &CloudOptions) -> Vec<String> {
|
||||||
let mut apps: Vec<String> = config.auto_setup.enable_apps.clone();
|
let mut apps: Vec<String> = config.auto_setup.enable_apps.clone();
|
||||||
|
|
@ -949,28 +949,26 @@ impl Cloud {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_pinned(&self, docker: &Docker) -> Result<bool> {
|
pub fn is_pinned(&self) -> bool {
|
||||||
let mut content = Vec::new();
|
let path = self.workdir.join("data").join(PINNED_FILE);
|
||||||
self.exec_with_output(
|
match read_to_string(&path) {
|
||||||
docker,
|
Ok(content) => content.trim() == "1",
|
||||||
vec!["cat", PINNED_FILE],
|
Err(_) => false,
|
||||||
Some(&mut content),
|
}
|
||||||
Vec::<String>::new(),
|
}
|
||||||
)
|
|
||||||
.await?
|
|
||||||
.to_result()?;
|
|
||||||
|
|
||||||
String::from_utf8(content)
|
pub fn pin(&self) -> Result<()> {
|
||||||
|
let path = self.workdir.join("data").join(PINNED_FILE);
|
||||||
|
write(path.clone(), "1")
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
.map(|content| content.trim() == "1")
|
.wrap_err_with(|| format!("Failed to write {path}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn pin(&self, docker: &Docker) -> Result<()> {
|
pub fn unpin(&self) -> Result<()> {
|
||||||
self.write_file(docker, PINNED_FILE, "1").await
|
let path = self.workdir.join("data").join(PINNED_FILE);
|
||||||
}
|
write(path.clone(), "0")
|
||||||
|
.into_diagnostic()
|
||||||
pub async fn unpin(&self, docker: &Docker) -> Result<()> {
|
.wrap_err_with(|| format!("Failed to write {path}"))
|
||||||
self.write_file(docker, PINNED_FILE, "0").await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn services(&self) -> impl Iterator<Item = &Service> {
|
pub fn services(&self) -> impl Iterator<Item = &Service> {
|
||||||
|
|
|
||||||
10
src/main.rs
10
src/main.rs
|
|
@ -87,11 +87,7 @@ async fn main() -> Result<ExitCode> {
|
||||||
.collect();
|
.collect();
|
||||||
services.push(cloud.db().name());
|
services.push(cloud.db().name());
|
||||||
let services = services.join(", ");
|
let services = services.join(", ");
|
||||||
let pin = if cloud.is_pinned(&docker).await.unwrap_or(false) {
|
let pin = if cloud.is_pinned() { "*" } else { "" };
|
||||||
"*"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
};
|
|
||||||
let version = match cloud.options.version.as_ref() {
|
let version = match cloud.options.version.as_ref() {
|
||||||
Some(version) => format!(", v{version}"),
|
Some(version) => format!(", v{version}"),
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
|
|
@ -368,11 +364,11 @@ async fn main() -> Result<ExitCode> {
|
||||||
}
|
}
|
||||||
HazeArgs::Pin { filter } => {
|
HazeArgs::Pin { filter } => {
|
||||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||||
cloud.pin(&docker).await?;
|
cloud.pin()?;
|
||||||
}
|
}
|
||||||
HazeArgs::Unpin { filter } => {
|
HazeArgs::Unpin { filter } => {
|
||||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||||
cloud.unpin(&docker).await?;
|
cloud.unpin()?;
|
||||||
}
|
}
|
||||||
HazeArgs::Proxy => {
|
HazeArgs::Proxy => {
|
||||||
proxy(docker, config).await?;
|
proxy(docker, config).await?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue