-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from illa-family/develop
feat!: add mount local dir functionality and add `--data` arg for subcommand `remove`
- Loading branch information
Showing
7 changed files
with
65 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "illa" | ||
version = "1.1.0" | ||
version = "1.2.0" | ||
authors = ["ILLA <[email protected]>"] | ||
edition = "2021" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ pub mod restart; | |
pub mod stop; | ||
pub mod ui; | ||
pub mod update; | ||
pub mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ use bollard::{ | |
RemoveContainerOptions, StartContainerOptions, StatsOptions, | ||
}, | ||
image::CreateImageOptions, | ||
models::HostConfig, | ||
models::{HostConfig, Mount, MountTypeEnum}, | ||
Docker, | ||
}; | ||
use clap::{builder, ArgAction::SetTrue, ArgGroup, Args}; | ||
|
@@ -101,6 +101,14 @@ async fn update_local(progress_style: ProgressStyle) -> Result { | |
builder_env_cp[1].as_str(), | ||
builder_env_cp[2].as_str(), | ||
]; | ||
utils::local_bind_init(); | ||
let mounts = vec![Mount { | ||
target: Some("/var/lib/postgresql/data".to_string()), | ||
source: Some("/tmp/illa-data".to_string()), | ||
typ: Some(MountTypeEnum::BIND), | ||
read_only: Some(false), | ||
..Default::default() | ||
}]; | ||
let mut builder_labels = HashMap::new(); | ||
builder_labels.insert("maintainer", "[email protected]"); | ||
builder_labels.insert("license", "Apache-2.0"); | ||
|
@@ -189,11 +197,7 @@ async fn update_local(progress_style: ProgressStyle) -> Result { | |
labels: Some(builder_labels), | ||
host_config: Some(HostConfig { | ||
port_bindings: builder_port_bindings.clone(), | ||
// TODO: based on different operating system to bind host path and volume | ||
// binds: Some(vec![format!( | ||
// "{}:{}", | ||
// "/tmp/illa-data", "/var/lib/postgresql/data" | ||
// )]), | ||
mounts: Some(mounts), | ||
..Default::default() | ||
}), | ||
..Default::default() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::{command::*, result::Result}; | ||
use anyhow::Ok; | ||
use std::{env, fs}; | ||
|
||
#[cfg(target_os = "macos")] | ||
pub fn local_bind_init() -> Result { | ||
use std::os::unix::fs::PermissionsExt; | ||
fs::create_dir_all("/tmp/illa-data"); | ||
let mut perms = fs::metadata("/tmp/illa-data")?.permissions(); | ||
perms.set_mode(0o777); | ||
fs::set_permissions("/tmp/illa-data", perms); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(target_os = "windows")] | ||
pub fn local_bind_init() -> Result { | ||
Ok(()) | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
pub fn local_bind_init() -> Result { | ||
Ok(()) | ||
} | ||
|
||
pub fn local_bind_delete() -> Result { | ||
fs::remove_dir_all("/tmp/illa-data"); | ||
Ok(()) | ||
} |