mirror of
https://codeberg.org/icewind/haze.git
synced 2026-11-30 20:50:49 +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 remove = Vec::new();
|
||||
for cloud in list {
|
||||
if cloud.is_pinned(&docker).await.unwrap_or(false) {
|
||||
if cloud.is_pinned() {
|
||||
retain.push(cloud);
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
|
||||
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> {
|
||||
let mut apps: Vec<String> = config.auto_setup.enable_apps.clone();
|
||||
|
|
@ -949,28 +949,26 @@ impl Cloud {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn is_pinned(&self, docker: &Docker) -> Result<bool> {
|
||||
let mut content = Vec::new();
|
||||
self.exec_with_output(
|
||||
docker,
|
||||
vec!["cat", PINNED_FILE],
|
||||
Some(&mut content),
|
||||
Vec::<String>::new(),
|
||||
)
|
||||
.await?
|
||||
.to_result()?;
|
||||
pub fn is_pinned(&self) -> bool {
|
||||
let path = self.workdir.join("data").join(PINNED_FILE);
|
||||
match read_to_string(&path) {
|
||||
Ok(content) => content.trim() == "1",
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
String::from_utf8(content)
|
||||
pub fn pin(&self) -> Result<()> {
|
||||
let path = self.workdir.join("data").join(PINNED_FILE);
|
||||
write(path.clone(), "1")
|
||||
.into_diagnostic()
|
||||
.map(|content| content.trim() == "1")
|
||||
.wrap_err_with(|| format!("Failed to write {path}"))
|
||||
}
|
||||
|
||||
pub async fn pin(&self, docker: &Docker) -> Result<()> {
|
||||
self.write_file(docker, PINNED_FILE, "1").await
|
||||
}
|
||||
|
||||
pub async fn unpin(&self, docker: &Docker) -> Result<()> {
|
||||
self.write_file(docker, PINNED_FILE, "0").await
|
||||
pub fn unpin(&self) -> Result<()> {
|
||||
let path = self.workdir.join("data").join(PINNED_FILE);
|
||||
write(path.clone(), "0")
|
||||
.into_diagnostic()
|
||||
.wrap_err_with(|| format!("Failed to write {path}"))
|
||||
}
|
||||
|
||||
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();
|
||||
services.push(cloud.db().name());
|
||||
let services = services.join(", ");
|
||||
let pin = if cloud.is_pinned(&docker).await.unwrap_or(false) {
|
||||
"*"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let pin = if cloud.is_pinned() { "*" } else { "" };
|
||||
let version = match cloud.options.version.as_ref() {
|
||||
Some(version) => format!(", v{version}"),
|
||||
None => String::new(),
|
||||
|
|
@ -368,11 +364,11 @@ async fn main() -> Result<ExitCode> {
|
|||
}
|
||||
HazeArgs::Pin { filter } => {
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
cloud.pin(&docker).await?;
|
||||
cloud.pin()?;
|
||||
}
|
||||
HazeArgs::Unpin { filter } => {
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
cloud.unpin(&docker).await?;
|
||||
cloud.unpin()?;
|
||||
}
|
||||
HazeArgs::Proxy => {
|
||||
proxy(docker, config).await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue