mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
move cloud list into struct
This commit is contained in:
parent
a30d1c9d64
commit
6041587c05
2 changed files with 89 additions and 89 deletions
52
src/cloud.rs
52
src/cloud.rs
|
|
@ -290,32 +290,12 @@ impl Cloud {
|
||||||
pub async fn exec(&self, docker: &mut Docker, cmd: Vec<String>) -> Result<()> {
|
pub async fn exec(&self, docker: &mut Docker, cmd: Vec<String>) -> Result<()> {
|
||||||
exec_tty(docker, &self.id, "haze", cmd, vec![]).await
|
exec_tty(docker, &self.id, "haze", cmd, vec![]).await
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async fn setup_workdir(base: &Utf8Path, id: &str) -> Result<Utf8PathBuf> {
|
pub async fn list(
|
||||||
let workdir = base.join(id);
|
|
||||||
create_dir_all(workdir.join("data")).await?;
|
|
||||||
create_dir_all(workdir.join("config")).await?;
|
|
||||||
create_dir_all(workdir.join("data-autotest")).await?;
|
|
||||||
create_dir_all(workdir.join("skeleton")).await?;
|
|
||||||
create_dir_all(workdir.join("integration/output")).await?;
|
|
||||||
create_dir_all(workdir.join("integration/work")).await?;
|
|
||||||
create_dir_all(workdir.join("integration/vendor")).await?;
|
|
||||||
|
|
||||||
write(workdir.join("integration/composer.lock"), "").await?;
|
|
||||||
write(workdir.join("config/CAN_INSTALL"), "").await?;
|
|
||||||
write(workdir.join("phpunit-cache"), "").await?;
|
|
||||||
|
|
||||||
create_dir_all(base.join("composer/cache")).await?;
|
|
||||||
|
|
||||||
Ok(workdir)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn list(
|
|
||||||
docker: &mut Docker,
|
docker: &mut Docker,
|
||||||
filter: Option<String>,
|
filter: Option<String>,
|
||||||
config: &HazeConfig,
|
config: &HazeConfig,
|
||||||
) -> Result<Vec<Cloud>> {
|
) -> Result<Vec<Cloud>> {
|
||||||
let containers = docker
|
let containers = docker
|
||||||
.list_containers::<String>(Some(ListContainersOptions {
|
.list_containers::<String>(Some(ListContainersOptions {
|
||||||
all: true,
|
all: true,
|
||||||
|
|
@ -377,16 +357,36 @@ pub async fn list(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(_created, cloud)| cloud)
|
.map(|(_created, cloud)| cloud)
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_by_filter(
|
pub async fn get_by_filter(
|
||||||
docker: &mut Docker,
|
docker: &mut Docker,
|
||||||
filter: Option<String>,
|
filter: Option<String>,
|
||||||
config: &HazeConfig,
|
config: &HazeConfig,
|
||||||
) -> Result<Cloud> {
|
) -> Result<Cloud> {
|
||||||
list(docker, filter, config)
|
Cloud::list(docker, filter, config)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
.ok_or(Report::msg("No clouds running matching filter"))
|
.ok_or(Report::msg("No clouds running matching filter"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn setup_workdir(base: &Utf8Path, id: &str) -> Result<Utf8PathBuf> {
|
||||||
|
let workdir = base.join(id);
|
||||||
|
create_dir_all(workdir.join("data")).await?;
|
||||||
|
create_dir_all(workdir.join("config")).await?;
|
||||||
|
create_dir_all(workdir.join("data-autotest")).await?;
|
||||||
|
create_dir_all(workdir.join("skeleton")).await?;
|
||||||
|
create_dir_all(workdir.join("integration/output")).await?;
|
||||||
|
create_dir_all(workdir.join("integration/work")).await?;
|
||||||
|
create_dir_all(workdir.join("integration/vendor")).await?;
|
||||||
|
|
||||||
|
write(workdir.join("integration/composer.lock"), "").await?;
|
||||||
|
write(workdir.join("config/CAN_INSTALL"), "").await?;
|
||||||
|
write(workdir.join("phpunit-cache"), "").await?;
|
||||||
|
|
||||||
|
create_dir_all(base.join("composer/cache")).await?;
|
||||||
|
|
||||||
|
Ok(workdir)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
src/main.rs
18
src/main.rs
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::args::{HazeArgs, HazeCommand};
|
use crate::args::{HazeArgs, HazeCommand};
|
||||||
use crate::cloud::{get_by_filter, list, Cloud, CloudOptions};
|
use crate::cloud::{Cloud, CloudOptions};
|
||||||
use crate::config::HazeConfig;
|
use crate::config::HazeConfig;
|
||||||
use bollard::Docker;
|
use bollard::Docker;
|
||||||
use color_eyre::{eyre::WrapErr, Report, Result};
|
use color_eyre::{eyre::WrapErr, Report, Result};
|
||||||
|
|
@ -22,7 +22,7 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
match args.command {
|
match args.command {
|
||||||
HazeCommand::Clean => {
|
HazeCommand::Clean => {
|
||||||
let list = list(&mut docker, None, &config).await?;
|
let list = Cloud::list(&mut docker, None, &config).await?;
|
||||||
for cloud in list {
|
for cloud in list {
|
||||||
if let Err(e) = cloud.destroy(&mut docker).await {
|
if let Err(e) = cloud.destroy(&mut docker).await {
|
||||||
eprintln!("Error while removing cloud: {:#}", e);
|
eprintln!("Error while removing cloud: {:#}", e);
|
||||||
|
|
@ -30,7 +30,7 @@ async fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HazeCommand::List => {
|
HazeCommand::List => {
|
||||||
let list = list(&mut docker, args.options.first().cloned(), &config).await?;
|
let list = Cloud::list(&mut docker, args.options.first().cloned(), &config).await?;
|
||||||
for cloud in list {
|
for cloud in list {
|
||||||
if let Some(filter) = &args.id {
|
if let Some(filter) = &args.id {
|
||||||
if !cloud.id.contains(filter.as_str()) {
|
if !cloud.id.contains(filter.as_str()) {
|
||||||
|
|
@ -63,18 +63,18 @@ async fn main() -> Result<()> {
|
||||||
println!("http://{}", cloud.ip.unwrap());
|
println!("http://{}", cloud.ip.unwrap());
|
||||||
}
|
}
|
||||||
HazeCommand::Stop => {
|
HazeCommand::Stop => {
|
||||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
let cloud = Cloud::get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
cloud.destroy(&mut docker).await?;
|
cloud.destroy(&mut docker).await?;
|
||||||
}
|
}
|
||||||
HazeCommand::Logs => {
|
HazeCommand::Logs => {
|
||||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
let cloud = Cloud::get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
let logs = cloud.logs(&mut docker).await?;
|
let logs = cloud.logs(&mut docker).await?;
|
||||||
for log in logs {
|
for log in logs {
|
||||||
print!("{}", log);
|
print!("{}", log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HazeCommand::Exec => {
|
HazeCommand::Exec => {
|
||||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
let cloud = Cloud::get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
cloud
|
cloud
|
||||||
.exec(
|
.exec(
|
||||||
&mut docker,
|
&mut docker,
|
||||||
|
|
@ -87,17 +87,17 @@ async fn main() -> Result<()> {
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
HazeCommand::Occ => {
|
HazeCommand::Occ => {
|
||||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
let cloud = Cloud::get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
let mut options = args.options;
|
let mut options = args.options;
|
||||||
options.insert(0, "occ".to_string());
|
options.insert(0, "occ".to_string());
|
||||||
cloud.exec(&mut docker, options).await?;
|
cloud.exec(&mut docker, options).await?;
|
||||||
}
|
}
|
||||||
HazeCommand::Db => {
|
HazeCommand::Db => {
|
||||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
let cloud = Cloud::get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
cloud.db.exec(&mut docker, &cloud.id).await?;
|
cloud.db.exec(&mut docker, &cloud.id).await?;
|
||||||
}
|
}
|
||||||
HazeCommand::Open => {
|
HazeCommand::Open => {
|
||||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
let cloud = Cloud::get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
match cloud.ip {
|
match cloud.ip {
|
||||||
Some(ip) => opener::open(format!("http://{}", ip))?,
|
Some(ip) => opener::open(format!("http://{}", ip))?,
|
||||||
None => eprintln!("{} is not running", cloud.id),
|
None => eprintln!("{} is not running", cloud.id),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue