mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 09:04:12 +02:00
clippy fixes
This commit is contained in:
parent
f8253fb68e
commit
abe04b52d0
12 changed files with 101 additions and 104 deletions
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
# `nix develop`
|
||||
devShell = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [ rustc cargo bacon cargo-edit cargo-outdated ];
|
||||
nativeBuildInputs = with pkgs; [ rustc cargo bacon cargo-edit cargo-outdated clippy ];
|
||||
};
|
||||
}
|
||||
) // {
|
||||
|
|
|
|||
34
src/cloud.rs
34
src/cloud.rs
|
|
@ -82,7 +82,7 @@ impl CloudOptions {
|
|||
|
||||
#[test]
|
||||
fn test_option_parse() {
|
||||
use crate::service::{LDAPAdmin, LDAP};
|
||||
use crate::service::{Ldap, LdapAdmin};
|
||||
|
||||
let mut args = vec![].into_iter().peekable();
|
||||
assert_eq!(
|
||||
|
|
@ -127,7 +127,7 @@ fn test_option_parse() {
|
|||
CloudOptions {
|
||||
php: PhpVersion::Php74,
|
||||
db: Database::Postgres,
|
||||
services: vec![Service::LDAP(LDAP), Service::LDAPAdmin(LDAPAdmin)],
|
||||
services: vec![Service::Ldap(Ldap), Service::LdapAdmin(LdapAdmin)],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
|
|
@ -137,7 +137,7 @@ fn test_option_parse() {
|
|||
CloudOptions {
|
||||
php: PhpVersion::Php74,
|
||||
db: Database::Postgres,
|
||||
services: vec![Service::LDAP(LDAP), Service::LDAPAdmin(LDAPAdmin)],
|
||||
services: vec![Service::Ldap(Ldap), Service::LdapAdmin(LdapAdmin)],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
|
|
@ -159,7 +159,7 @@ pub struct Cloud {
|
|||
|
||||
impl Cloud {
|
||||
pub async fn create(
|
||||
docker: &mut Docker,
|
||||
docker: &Docker,
|
||||
options: CloudOptions,
|
||||
config: &HazeConfig,
|
||||
) -> Result<Self> {
|
||||
|
|
@ -227,7 +227,7 @@ impl Cloud {
|
|||
.await
|
||||
.into_diagnostic()?
|
||||
.id
|
||||
.ok_or(Report::msg("No network id in response"))
|
||||
.ok_or_else(|| Report::msg("No network id in response"))
|
||||
.wrap_err("Failed to create network")?;
|
||||
|
||||
let network_info = docker
|
||||
|
|
@ -237,15 +237,15 @@ impl Cloud {
|
|||
let gateway = network_info
|
||||
.ipam
|
||||
.as_ref()
|
||||
.ok_or(Report::msg("Network has no ip info"))?
|
||||
.ok_or_else(|| Report::msg("Network has no ip info"))?
|
||||
.config
|
||||
.as_deref()
|
||||
.ok_or(Report::msg("Network has no ip info"))?
|
||||
.ok_or_else(|| Report::msg("Network has no ip info"))?
|
||||
.first()
|
||||
.ok_or(Report::msg("Network has no ip info"))?
|
||||
.ok_or_else(|| Report::msg("Network has no ip info"))?
|
||||
.gateway
|
||||
.as_deref()
|
||||
.ok_or(Report::msg("Network has no ip info"))?;
|
||||
.ok_or_else(|| Report::msg("Network has no ip info"))?;
|
||||
|
||||
let mut containers = Vec::new();
|
||||
|
||||
|
|
@ -343,7 +343,7 @@ impl Cloud {
|
|||
.networks
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter_map(|(name, network)| name.eq("haze").then(|| network))
|
||||
.filter_map(|(name, network)| name.eq("haze").then_some(network))
|
||||
.next()
|
||||
.unwrap()
|
||||
.ip_address
|
||||
|
|
@ -404,7 +404,7 @@ impl Cloud {
|
|||
})
|
||||
}
|
||||
|
||||
pub async fn destroy(self, docker: &mut Docker) -> Result<()> {
|
||||
pub async fn destroy(self, docker: &Docker) -> Result<()> {
|
||||
for container in self.containers {
|
||||
docker
|
||||
.remove_container(
|
||||
|
|
@ -438,7 +438,7 @@ impl Cloud {
|
|||
|
||||
pub async fn exec<S: Into<String>>(
|
||||
&self,
|
||||
docker: &mut Docker,
|
||||
docker: &Docker,
|
||||
cmd: Vec<S>,
|
||||
tty: bool,
|
||||
) -> Result<ExitCode> {
|
||||
|
|
@ -575,10 +575,10 @@ impl Cloud {
|
|||
.await?
|
||||
.into_iter()
|
||||
.next()
|
||||
.ok_or(Report::msg("No clouds running matching filter"))
|
||||
.ok_or_else(|| Report::msg("No clouds running matching filter"))
|
||||
}
|
||||
|
||||
pub async fn wait_for_start(&self, docker: &mut Docker) -> Result<()> {
|
||||
pub async fn wait_for_start(&self, docker: &Docker) -> Result<()> {
|
||||
self.php
|
||||
.wait_for_start(self.ip)
|
||||
.await
|
||||
|
|
@ -597,7 +597,7 @@ impl Cloud {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn enable_app<S: Into<String>>(&self, docker: &mut Docker, app: S) -> Result<()> {
|
||||
pub async fn enable_app<S: Into<String>>(&self, docker: &Docker, app: S) -> Result<()> {
|
||||
self.exec(
|
||||
docker,
|
||||
vec![
|
||||
|
|
@ -612,7 +612,7 @@ impl Cloud {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn pin(&self, docker: &mut Docker) -> Result<()> {
|
||||
pub async fn pin(&self, docker: &Docker) -> Result<()> {
|
||||
// abuse memory limits as editable label
|
||||
docker
|
||||
.update_container(
|
||||
|
|
@ -626,7 +626,7 @@ impl Cloud {
|
|||
.into_diagnostic()
|
||||
}
|
||||
|
||||
pub async fn unpin(&self, docker: &mut Docker) -> Result<()> {
|
||||
pub async fn unpin(&self, docker: &Docker) -> Result<()> {
|
||||
// abuse memory limits as editable label
|
||||
docker
|
||||
.update_container(
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ pub struct ProxyConfig {
|
|||
impl ProxyConfig {
|
||||
/// Get a public address for a service, either with direct ip or through the proxy
|
||||
pub fn addr(&self, id: &str, ip: IpAddr) -> String {
|
||||
let clean_id = id.strip_prefix("haze-").unwrap_or(&id);
|
||||
let clean_id = id.strip_prefix("haze-").unwrap_or(id);
|
||||
match (&self.address, self.https) {
|
||||
(public, true) if !public.is_empty() => format!("https://{clean_id}.{public}"),
|
||||
(public, false) if !public.is_empty() => format!("http://{clean_id}.{public}"),
|
||||
|
|
@ -173,7 +173,7 @@ impl ProxyConfig {
|
|||
}
|
||||
|
||||
pub fn addr_with_port(&self, id: &str, ip: IpAddr, port: u16) -> String {
|
||||
let clean_id = id.strip_prefix("haze-").unwrap_or(&id);
|
||||
let clean_id = id.strip_prefix("haze-").unwrap_or(id);
|
||||
match (&self.address, self.https) {
|
||||
(public, true) if !public.is_empty() => format!("https://{clean_id}.{public}"),
|
||||
(public, false) if !public.is_empty() => format!("http://{clean_id}.{public}"),
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ impl Database {
|
|||
|
||||
pub async fn spawn(
|
||||
&self,
|
||||
docker: &mut Docker,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
) -> Result<Option<String>> {
|
||||
|
|
@ -242,14 +242,14 @@ impl Database {
|
|||
|
||||
pub async fn exec_sh<S: Into<String>>(
|
||||
&self,
|
||||
docker: &mut Docker,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
cmd: Vec<S>,
|
||||
tty: bool,
|
||||
) -> Result<ExitCode> {
|
||||
let container = match self.family() {
|
||||
DatabaseFamily::Sqlite => cloud_id.to_string(),
|
||||
_ => format!("{}-db", cloud_id.to_string()),
|
||||
_ => format!("{}-db", cloud_id),
|
||||
};
|
||||
if tty {
|
||||
exec_tty(docker, &container, "root", cmd, vec![]).await
|
||||
|
|
@ -258,7 +258,7 @@ impl Database {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn exec(&self, docker: &mut Docker, cloud_id: &str, root: bool) -> Result<ExitCode> {
|
||||
pub async fn exec(&self, docker: &Docker, cloud_id: &str, root: bool) -> Result<ExitCode> {
|
||||
match self.family() {
|
||||
DatabaseFamily::Sqlite => {
|
||||
exec_tty(
|
||||
|
|
@ -309,7 +309,7 @@ impl Database {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn wait_for_start(&self, docker: &mut Docker, cloud_id: &str) -> Result<()> {
|
||||
pub async fn wait_for_start(&self, docker: &Docker, cloud_id: &str) -> Result<()> {
|
||||
let time = if self.family() == DatabaseFamily::Oracle {
|
||||
45
|
||||
} else {
|
||||
|
|
@ -327,9 +327,9 @@ impl Database {
|
|||
.wrap_err(format!("Timeout after {time} seconds"))?
|
||||
}
|
||||
|
||||
pub async fn ip(&self, docker: &mut Docker, cloud_id: &str) -> Option<IpAddr> {
|
||||
pub async fn ip(&self, docker: &Docker, cloud_id: &str) -> Option<IpAddr> {
|
||||
match self.family() {
|
||||
DatabaseFamily::Sqlite => return None,
|
||||
DatabaseFamily::Sqlite => None,
|
||||
_ => docker
|
||||
.inspect_container(&format!("{}-db", cloud_id), None)
|
||||
.await
|
||||
|
|
@ -345,7 +345,7 @@ impl Database {
|
|||
}
|
||||
}
|
||||
|
||||
async fn is_healthy(&self, docker: &mut Docker, cloud_id: &str) -> Result<bool> {
|
||||
async fn is_healthy(&self, docker: &Docker, cloud_id: &str) -> Result<bool> {
|
||||
match self.family() {
|
||||
DatabaseFamily::Sqlite => Ok(true),
|
||||
DatabaseFamily::Mysql | DatabaseFamily::MariaDB => {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use tokio::task::spawn;
|
|||
use tokio::time::sleep;
|
||||
|
||||
pub async fn exec_tty<S1: AsRef<str>, S2: Into<String>>(
|
||||
docker: &mut Docker,
|
||||
docker: &Docker,
|
||||
container: S1,
|
||||
user: &str,
|
||||
cmd: Vec<S2>,
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ pub fn checkout_all<P: AsRef<Path>>(sources_root: P, branch: &str) -> Result<()>
|
|||
let app = app.into_diagnostic()?;
|
||||
if app.metadata().into_diagnostic()?.is_dir() {
|
||||
let app_dir = app.path();
|
||||
if has_branch(&app_dir, &branch).unwrap_or_default()
|
||||
if has_branch(&app_dir, branch).unwrap_or_default()
|
||||
&& get_branch(&app_dir).unwrap_or_default().trim() != branch
|
||||
{
|
||||
print!("{}", app.file_name().to_string_lossy());
|
||||
if let Err(e) = checkout(&app_dir, &branch) {
|
||||
if let Err(e) = checkout(&app_dir, branch) {
|
||||
println!(": {} ❌", e);
|
||||
} else {
|
||||
println!(" ✓");
|
||||
|
|
@ -39,7 +39,7 @@ fn has_branch<P: AsRef<Path>>(repo: P, branch: &str) -> Result<bool> {
|
|||
error!(stdout = stdout, stderr = stderr, "git command failed");
|
||||
}
|
||||
|
||||
for line in stdout.split("\n") {
|
||||
for line in stdout.split('\n') {
|
||||
let line = line.trim();
|
||||
if line == branch {
|
||||
return Ok(true);
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@ pub async fn image_exists(docker: &Docker, image: &str) -> bool {
|
|||
}
|
||||
|
||||
pub async fn pull_image(docker: &Docker, image: &str) -> Result<()> {
|
||||
if let Err(_) = docker.inspect_image(image).await {
|
||||
if docker.inspect_image(image).await.is_err() {
|
||||
println!("Pulling image {}", image);
|
||||
|
||||
let mut info_stream = docker.create_image(
|
||||
Some(CreateImageOptions {
|
||||
from_image: if image.contains(":") {
|
||||
from_image: if image.contains(':') {
|
||||
image.to_string()
|
||||
} else {
|
||||
format!("{}:latest", image)
|
||||
|
|
|
|||
112
src/main.rs
112
src/main.rs
|
|
@ -34,7 +34,7 @@ async fn main() -> Result<()> {
|
|||
miette::set_panic_hook();
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let mut docker = Docker::connect_with_local_defaults()
|
||||
let docker = Docker::connect_with_local_defaults()
|
||||
.into_diagnostic()
|
||||
.wrap_err("Failed to connect to docker")?;
|
||||
let config = HazeConfig::load().wrap_err("Failed to load config")?;
|
||||
|
|
@ -43,16 +43,16 @@ async fn main() -> Result<()> {
|
|||
|
||||
match args {
|
||||
HazeArgs::Clean => {
|
||||
let list = Cloud::list(&mut docker, None, &config).await?;
|
||||
let list = Cloud::list(&docker, None, &config).await?;
|
||||
for cloud in list.into_iter().filter(|cloud| !cloud.pinned) {
|
||||
if let Err(e) = cloud.destroy(&mut docker).await {
|
||||
if let Err(e) = cloud.destroy(&docker).await {
|
||||
eprintln!("Error while removing cloud: {:#}", e);
|
||||
}
|
||||
}
|
||||
clear_networks(&docker).await?;
|
||||
}
|
||||
HazeArgs::List { filter } => {
|
||||
let list = Cloud::list(&mut docker, filter, &config).await?;
|
||||
let list = Cloud::list(&docker, filter, &config).await?;
|
||||
for cloud in list {
|
||||
let mut services: Vec<_> = cloud.services.iter().map(Service::name).collect();
|
||||
services.push(cloud.db.name());
|
||||
|
|
@ -69,11 +69,11 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
HazeArgs::Start { options } => {
|
||||
setup(&mut docker, options, &config).await?;
|
||||
setup(&docker, options, &config).await?;
|
||||
}
|
||||
HazeArgs::Stop { filter } => {
|
||||
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?;
|
||||
cloud.destroy(&mut docker).await?;
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
cloud.destroy(&docker).await?;
|
||||
}
|
||||
HazeArgs::Logs {
|
||||
filter,
|
||||
|
|
@ -81,7 +81,7 @@ async fn main() -> Result<()> {
|
|||
count,
|
||||
service,
|
||||
} => {
|
||||
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?;
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
let container = if let Some(service) = service {
|
||||
service.container_name(&cloud.id)
|
||||
} else {
|
||||
|
|
@ -94,12 +94,12 @@ async fn main() -> Result<()> {
|
|||
service,
|
||||
command,
|
||||
} => {
|
||||
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?;
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
match service {
|
||||
None => {
|
||||
cloud
|
||||
.exec(
|
||||
&mut docker,
|
||||
&docker,
|
||||
if command.is_empty() {
|
||||
vec!["bash".to_string()]
|
||||
} else {
|
||||
|
|
@ -113,7 +113,7 @@ async fn main() -> Result<()> {
|
|||
cloud
|
||||
.db
|
||||
.exec_sh(
|
||||
&mut docker,
|
||||
&docker,
|
||||
&cloud.id,
|
||||
if command.is_empty() {
|
||||
vec!["bash".to_string()]
|
||||
|
|
@ -130,31 +130,31 @@ async fn main() -> Result<()> {
|
|||
filter,
|
||||
mut command,
|
||||
} => {
|
||||
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?;
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
command.insert(0, "occ".to_string());
|
||||
cloud
|
||||
.exec(&mut docker, command, atty::is(atty::Stream::Stdout))
|
||||
.exec(&docker, command, atty::is(atty::Stream::Stdout))
|
||||
.await?;
|
||||
}
|
||||
HazeArgs::Db { filter, root } => {
|
||||
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?;
|
||||
cloud.db.exec(&mut docker, &cloud.id, root).await?;
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
cloud.db.exec(&docker, &cloud.id, root).await?;
|
||||
}
|
||||
HazeArgs::Open { filter } => {
|
||||
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?;
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
match cloud.ip {
|
||||
Some(_) => opener::open(cloud.address).into_diagnostic()?,
|
||||
None => eprintln!("{} is not running", cloud.id),
|
||||
}
|
||||
}
|
||||
HazeArgs::Test { options, mut args } => {
|
||||
let cloud = Cloud::create(&mut docker, options, &config).await?;
|
||||
let cloud = Cloud::create(&docker, options, &config).await?;
|
||||
println!("Waiting for servers to start");
|
||||
cloud.wait_for_start(&mut docker).await?;
|
||||
cloud.wait_for_start(&docker).await?;
|
||||
println!("Installing");
|
||||
if let Err(e) = cloud
|
||||
.exec(
|
||||
&mut docker,
|
||||
&docker,
|
||||
vec![
|
||||
"install",
|
||||
&config.auto_setup.username,
|
||||
|
|
@ -164,7 +164,7 @@ async fn main() -> Result<()> {
|
|||
)
|
||||
.await
|
||||
{
|
||||
cloud.destroy(&mut docker).await?;
|
||||
cloud.destroy(&docker).await?;
|
||||
return Err(e);
|
||||
}
|
||||
if let Some(app) = args
|
||||
|
|
@ -174,23 +174,23 @@ async fn main() -> Result<()> {
|
|||
.map(|path| &path[0..path.find('/').unwrap_or(path.len())])
|
||||
{
|
||||
if app.starts_with("files_") {
|
||||
cloud.enable_app(&mut docker, "files_external").await?;
|
||||
cloud.enable_app(&docker, "files_external").await?;
|
||||
}
|
||||
println!("Enabling {}", app);
|
||||
cloud.enable_app(&mut docker, app).await?;
|
||||
cloud.enable_app(&docker, app).await?;
|
||||
}
|
||||
args.insert(0, "tests".to_string());
|
||||
cloud.exec(&mut docker, args, false).await?;
|
||||
cloud.destroy(&mut docker).await?;
|
||||
cloud.exec(&docker, args, false).await?;
|
||||
cloud.destroy(&docker).await?;
|
||||
}
|
||||
HazeArgs::Integration { options, mut args } => {
|
||||
let cloud = Cloud::create(&mut docker, options, &config).await?;
|
||||
let cloud = Cloud::create(&docker, options, &config).await?;
|
||||
println!("Waiting for servers to start");
|
||||
cloud.wait_for_start(&mut docker).await?;
|
||||
cloud.wait_for_start(&docker).await?;
|
||||
println!("Installing");
|
||||
if let Err(e) = cloud
|
||||
.exec(
|
||||
&mut docker,
|
||||
&docker,
|
||||
vec![
|
||||
"install",
|
||||
&config.auto_setup.username,
|
||||
|
|
@ -200,49 +200,45 @@ async fn main() -> Result<()> {
|
|||
)
|
||||
.await
|
||||
{
|
||||
cloud.destroy(&mut docker).await?;
|
||||
cloud.destroy(&docker).await?;
|
||||
return Err(e);
|
||||
}
|
||||
args.insert(0, "integration".to_string());
|
||||
cloud.exec(&mut docker, args, false).await?;
|
||||
cloud.destroy(&mut docker).await?;
|
||||
cloud.exec(&docker, args, false).await?;
|
||||
cloud.destroy(&docker).await?;
|
||||
}
|
||||
HazeArgs::Fmt { path } => {
|
||||
let cloud = Cloud::create(&mut docker, CloudOptions::default(), &config).await?;
|
||||
let cloud = Cloud::create(&docker, CloudOptions::default(), &config).await?;
|
||||
let mut out_buffer = Vec::<u8>::with_capacity(1024);
|
||||
println!("Waiting for servers to start");
|
||||
cloud.wait_for_start(&mut docker).await?;
|
||||
cloud.wait_for_start(&docker).await?;
|
||||
println!("Installing composer");
|
||||
if let Err(e) = cloud
|
||||
.exec_with_output(
|
||||
&mut docker,
|
||||
vec!["composer", "install"],
|
||||
Some(&mut out_buffer),
|
||||
)
|
||||
.exec_with_output(&docker, vec!["composer", "install"], Some(&mut out_buffer))
|
||||
.await
|
||||
.and_then(|c| c.to_result())
|
||||
{
|
||||
eprintln!("{}", String::from_utf8_lossy(&out_buffer));
|
||||
cloud.destroy(&mut docker).await?;
|
||||
cloud.destroy(&docker).await?;
|
||||
return Err(e);
|
||||
}
|
||||
out_buffer.clear();
|
||||
println!("Formatting");
|
||||
if let Err(e) = cloud
|
||||
.exec(
|
||||
&mut docker,
|
||||
&docker,
|
||||
vec!["composer", "run", "cs:fix", path.as_str()],
|
||||
false,
|
||||
)
|
||||
.await
|
||||
{
|
||||
cloud.destroy(&mut docker).await?;
|
||||
cloud.destroy(&docker).await?;
|
||||
return Err(e);
|
||||
}
|
||||
println!("Cleanup");
|
||||
if let Err(e) = cloud
|
||||
.exec_with_output(
|
||||
&mut docker,
|
||||
&docker,
|
||||
vec!["git", "clean", "-fd", "lib/composer"],
|
||||
Some(&mut out_buffer),
|
||||
)
|
||||
|
|
@ -250,12 +246,12 @@ async fn main() -> Result<()> {
|
|||
.and_then(|c| c.to_result())
|
||||
{
|
||||
eprintln!("{}", String::from_utf8_lossy(&out_buffer));
|
||||
cloud.destroy(&mut docker).await?;
|
||||
cloud.destroy(&docker).await?;
|
||||
return Err(e);
|
||||
}
|
||||
if let Err(e) = cloud
|
||||
.exec_with_output(
|
||||
&mut docker,
|
||||
&docker,
|
||||
vec!["git", "checkout", "lib/composer"],
|
||||
Some(&mut out_buffer),
|
||||
)
|
||||
|
|
@ -263,16 +259,16 @@ async fn main() -> Result<()> {
|
|||
.and_then(|c| c.to_result())
|
||||
{
|
||||
eprintln!("{}", String::from_utf8_lossy(&out_buffer));
|
||||
cloud.destroy(&mut docker).await?;
|
||||
cloud.destroy(&docker).await?;
|
||||
return Err(e);
|
||||
}
|
||||
cloud.destroy(&mut docker).await?;
|
||||
cloud.destroy(&docker).await?;
|
||||
}
|
||||
HazeArgs::Shell { command, options } => {
|
||||
let cloud = setup(&mut docker, options, &config).await?;
|
||||
let cloud = setup(&docker, options, &config).await?;
|
||||
cloud
|
||||
.exec(
|
||||
&mut docker,
|
||||
&docker,
|
||||
if command.is_empty() {
|
||||
vec!["bash".to_string()]
|
||||
} else {
|
||||
|
|
@ -281,15 +277,15 @@ async fn main() -> Result<()> {
|
|||
true,
|
||||
)
|
||||
.await?;
|
||||
cloud.destroy(&mut docker).await?;
|
||||
cloud.destroy(&docker).await?;
|
||||
}
|
||||
HazeArgs::Pin { filter } => {
|
||||
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?;
|
||||
cloud.pin(&mut docker).await?;
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
cloud.pin(&docker).await?;
|
||||
}
|
||||
HazeArgs::Unpin { filter } => {
|
||||
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?;
|
||||
cloud.unpin(&mut docker).await?;
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
cloud.unpin(&docker).await?;
|
||||
}
|
||||
HazeArgs::Proxy => {
|
||||
proxy(docker, config).await?;
|
||||
|
|
@ -302,7 +298,7 @@ async fn main() -> Result<()> {
|
|||
command,
|
||||
args,
|
||||
} => {
|
||||
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?;
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
let ip = cloud
|
||||
.ip
|
||||
.ok_or_else(|| Report::msg(format!("{} is not running", cloud.id)))?;
|
||||
|
|
@ -318,7 +314,7 @@ async fn main() -> Result<()> {
|
|||
};
|
||||
let db_ip = cloud
|
||||
.db
|
||||
.ip(&mut docker, &cloud.id)
|
||||
.ip(&docker, &cloud.id)
|
||||
.await
|
||||
.ok_or_else(|| Report::msg(format!("{}-db is not running", cloud.id)))?;
|
||||
|
||||
|
|
@ -338,8 +334,8 @@ async fn main() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn setup(docker: &mut Docker, options: CloudOptions, config: &HazeConfig) -> Result<Cloud> {
|
||||
let cloud = Cloud::create(docker, options, &config).await?;
|
||||
async fn setup(docker: &Docker, options: CloudOptions, config: &HazeConfig) -> Result<Cloud> {
|
||||
let cloud = Cloud::create(docker, options, config).await?;
|
||||
println!("{}", cloud.address);
|
||||
let host = cloud.address.split_once("://").expect("no address?").1;
|
||||
if config.auto_setup.enabled {
|
||||
|
|
@ -415,7 +411,7 @@ async fn setup(docker: &mut Docker, options: CloudOptions, config: &HazeConfig)
|
|||
}
|
||||
}
|
||||
for service in &cloud.services {
|
||||
for cmd in service.post_setup(&docker, &cloud.id, config).await? {
|
||||
for cmd in service.post_setup(docker, &cloud.id, config).await? {
|
||||
cloud
|
||||
.exec(docker, shell_words::split(&cmd).into_diagnostic()?, false)
|
||||
.await?;
|
||||
|
|
@ -423,7 +419,7 @@ async fn setup(docker: &mut Docker, options: CloudOptions, config: &HazeConfig)
|
|||
}
|
||||
for cmd in &config.auto_setup.post_setup {
|
||||
cloud
|
||||
.exec(docker, shell_words::split(&cmd).into_diagnostic()?, false)
|
||||
.exec(docker, shell_words::split(cmd).into_diagnostic()?, false)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,9 +86,10 @@ impl PhpVersion {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn spawn(
|
||||
&self,
|
||||
docker: &mut Docker,
|
||||
docker: &Docker,
|
||||
id: &str,
|
||||
env: Vec<String>,
|
||||
db: &Database,
|
||||
|
|
@ -170,11 +171,11 @@ impl PhpVersion {
|
|||
let client = Client::new();
|
||||
let url = Url::parse(&format!(
|
||||
"http://{}/status.php",
|
||||
ip.ok_or(Report::msg("Container not running"))?
|
||||
ip.ok_or_else(|| Report::msg("Container not running"))?
|
||||
))
|
||||
.into_diagnostic()?;
|
||||
timeout(Duration::from_secs(15), async {
|
||||
while !client.get(url.clone()).send().await.is_ok() {
|
||||
while client.get(url.clone()).send().await.is_err() {
|
||||
sleep(Duration::from_millis(100)).await
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ impl ActiveInstances {
|
|||
}
|
||||
|
||||
pub fn last(&self) -> Option<SocketAddr> {
|
||||
self.last.lock().unwrap().clone()
|
||||
*self.last.lock().unwrap()
|
||||
}
|
||||
|
||||
async fn update_last(&self) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ mod smb;
|
|||
use crate::config::HazeConfig;
|
||||
pub use crate::service::clam::ClamIcap;
|
||||
use crate::service::kaspersky::{Kaspersky, KasperskyIcap};
|
||||
pub use crate::service::ldap::{LDAPAdmin, LDAP};
|
||||
pub use crate::service::ldap::{Ldap, LdapAdmin};
|
||||
pub use crate::service::objectstore::ObjectStore;
|
||||
pub use crate::service::office::Office;
|
||||
pub use crate::service::onlyoffice::OnlyOffice;
|
||||
|
|
@ -143,8 +143,8 @@ pub trait ServiceTrait {
|
|||
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||
pub enum Service {
|
||||
ObjectStore(ObjectStore),
|
||||
LDAP(LDAP),
|
||||
LDAPAdmin(LDAPAdmin),
|
||||
Ldap(Ldap),
|
||||
LdapAdmin(LdapAdmin),
|
||||
OnlyOffice(OnlyOffice),
|
||||
Office(Office),
|
||||
Push(NotifyPush),
|
||||
|
|
@ -161,7 +161,7 @@ impl Service {
|
|||
"s3m" => Some(&[Service::ObjectStore(ObjectStore::S3m)]),
|
||||
"s3mb" => Some(&[Service::ObjectStore(ObjectStore::S3mb)]),
|
||||
"azure" => Some(&[Service::ObjectStore(ObjectStore::Azure)]),
|
||||
"ldap" => Some(&[Service::LDAP(LDAP), Service::LDAPAdmin(LDAPAdmin)]),
|
||||
"ldap" => Some(&[Service::Ldap(Ldap), Service::LdapAdmin(LdapAdmin)]),
|
||||
"onlyoffice" => Some(&[Service::OnlyOffice(OnlyOffice)]),
|
||||
"office" => Some(&[Service::Office(Office)]),
|
||||
"push" => Some(&[Service::Push(NotifyPush)]),
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ use maplit::hashmap;
|
|||
use miette::{IntoDiagnostic, Report};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct LDAP;
|
||||
pub struct Ldap;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ServiceTrait for LDAP {
|
||||
impl ServiceTrait for Ldap {
|
||||
fn name(&self) -> &str {
|
||||
"ldap"
|
||||
}
|
||||
|
|
@ -78,10 +78,10 @@ impl ServiceTrait for LDAP {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct LDAPAdmin;
|
||||
pub struct LdapAdmin;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ServiceTrait for LDAPAdmin {
|
||||
impl ServiceTrait for LdapAdmin {
|
||||
fn name(&self) -> &str {
|
||||
"ldap-admin"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue