1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

add azure support

This commit is contained in:
Robin Appelman 2022-09-15 17:16:02 +02:00
commit cae6acc488
2 changed files with 40 additions and 13 deletions

View file

@ -89,6 +89,7 @@ impl Service {
match ty { match ty {
"s3" => Some(&[Service::ObjectStore(ObjectStore::S3)]), "s3" => Some(&[Service::ObjectStore(ObjectStore::S3)]),
"s3mb" => Some(&[Service::ObjectStore(ObjectStore::S3mb)]), "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)]), "onlyoffice" => Some(&[Service::OnlyOffice(OnlyOffice)]),
"office" => Some(&[Service::Office(Office)]), "office" => Some(&[Service::Office(Office)]),

View file

@ -4,7 +4,7 @@ use crate::image::pull_image;
use crate::service::ServiceTrait; use crate::service::ServiceTrait;
use crate::Result; use crate::Result;
use bollard::container::{Config, CreateContainerOptions, NetworkingConfig}; use bollard::container::{Config, CreateContainerOptions, NetworkingConfig};
use bollard::models::{EndpointSettings, HostConfig}; use bollard::models::{ContainerState, EndpointSettings, HostConfig};
use bollard::Docker; use bollard::Docker;
use maplit::hashmap; use maplit::hashmap;
use miette::IntoDiagnostic; use miette::IntoDiagnostic;
@ -13,6 +13,7 @@ use miette::IntoDiagnostic;
pub enum ObjectStore { pub enum ObjectStore {
S3, S3,
S3mb, S3mb,
Azure,
} }
impl ObjectStore { impl ObjectStore {
@ -20,6 +21,7 @@ impl ObjectStore {
match self { match self {
ObjectStore::S3 => "localstack/localstack:0.14.3", ObjectStore::S3 => "localstack/localstack:0.14.3",
ObjectStore::S3mb => "localstack/localstack:0.14.3", ObjectStore::S3mb => "localstack/localstack:0.14.3",
ObjectStore::Azure => "arafato/azurite:2.6.5",
} }
} }
@ -27,12 +29,14 @@ impl ObjectStore {
match self { match self {
ObjectStore::S3 => vec!["DEBUG=1", "SERVICES=s3"], ObjectStore::S3 => vec!["DEBUG=1", "SERVICES=s3"],
ObjectStore::S3mb => vec!["DEBUG=1", "SERVICES=s3"], ObjectStore::S3mb => vec!["DEBUG=1", "SERVICES=s3"],
ObjectStore::Azure => vec![],
} }
} }
fn host_name(&self) -> &str { fn host_name(&self) -> &str {
match self { match self {
ObjectStore::S3 => "s3", ObjectStore::S3 => "s3",
ObjectStore::S3mb => "s3", ObjectStore::S3mb => "s3",
ObjectStore::Azure => "azure",
} }
} }
} }
@ -43,6 +47,7 @@ impl ServiceTrait for ObjectStore {
match self { match self {
ObjectStore::S3 => "s3", ObjectStore::S3 => "s3",
ObjectStore::S3mb => "s3mb", ObjectStore::S3mb => "s3mb",
ObjectStore::Azure => "azure",
} }
} }
@ -50,6 +55,7 @@ impl ServiceTrait for ObjectStore {
match self { match self {
ObjectStore::S3 => &["S3=1"], ObjectStore::S3 => &["S3=1"],
ObjectStore::S3mb => &["S3MB=1"], ObjectStore::S3mb => &["S3MB=1"],
ObjectStore::Azure => &["AZURE=1"],
} }
} }
@ -98,18 +104,38 @@ impl ServiceTrait for ObjectStore {
} }
async fn is_healthy(&self, docker: &Docker, cloud_id: &str) -> Result<bool> { async fn is_healthy(&self, docker: &Docker, cloud_id: &str) -> Result<bool> {
let mut output = Vec::new(); match self {
exec( ObjectStore::S3 | ObjectStore::S3mb => {
docker, let mut output = Vec::new();
format!("{}-object", cloud_id), exec(
"root", docker,
vec!["curl", "localhost:4566/health"], format!("{}-object", cloud_id),
vec![], "root",
Some(&mut output), vec!["curl", "localhost:4566/health"],
) vec![],
.await?; Some(&mut output),
let output = String::from_utf8(output).into_diagnostic()?; )
Ok(output.contains(r#""s3": "running""#) || output.contains(r#""s3": "available""#)) .await?;
let output = String::from_utf8(output).into_diagnostic()?;
Ok(
output.contains(r#""s3": "running""#)
|| output.contains(r#""s3": "available""#),
)
}
_ => {
let info = docker
.inspect_container(&self.container_name(cloud_id), None)
.await
.into_diagnostic()?;
Ok(matches!(
info.state,
Some(ContainerState {
running: Some(true),
..
})
))
}
}
} }
fn container_name(&self, cloud_id: &str) -> String { fn container_name(&self, cloud_id: &str) -> String {