mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
smb service
This commit is contained in:
parent
fd8f1451ff
commit
ef1141d125
2 changed files with 80 additions and 0 deletions
|
|
@ -2,12 +2,14 @@ mod ldap;
|
||||||
mod objectstore;
|
mod objectstore;
|
||||||
mod onlyoffice;
|
mod onlyoffice;
|
||||||
mod push;
|
mod push;
|
||||||
|
mod smb;
|
||||||
|
|
||||||
use crate::config::HazeConfig;
|
use crate::config::HazeConfig;
|
||||||
pub use crate::service::ldap::{LDAPAdmin, LDAP};
|
pub use crate::service::ldap::{LDAPAdmin, LDAP};
|
||||||
pub use crate::service::objectstore::ObjectStore;
|
pub use crate::service::objectstore::ObjectStore;
|
||||||
pub use crate::service::onlyoffice::OnlyOffice;
|
pub use crate::service::onlyoffice::OnlyOffice;
|
||||||
pub use crate::service::push::NotifyPush;
|
pub use crate::service::push::NotifyPush;
|
||||||
|
use crate::service::smb::Smb;
|
||||||
use bollard::models::ContainerState;
|
use bollard::models::ContainerState;
|
||||||
use bollard::Docker;
|
use bollard::Docker;
|
||||||
use color_eyre::{eyre::WrapErr, Result};
|
use color_eyre::{eyre::WrapErr, Result};
|
||||||
|
|
@ -66,6 +68,7 @@ pub enum Service {
|
||||||
LDAPAdmin(LDAPAdmin),
|
LDAPAdmin(LDAPAdmin),
|
||||||
OnlyOffice(OnlyOffice),
|
OnlyOffice(OnlyOffice),
|
||||||
Push(NotifyPush),
|
Push(NotifyPush),
|
||||||
|
Smb(Smb),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
|
|
@ -75,6 +78,7 @@ impl Service {
|
||||||
"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)]),
|
||||||
"push" => Some(&[Service::Push(NotifyPush)]),
|
"push" => Some(&[Service::Push(NotifyPush)]),
|
||||||
|
"smb" => Some(&[Service::Smb(Smb)]),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
76
src/service/smb.rs
Normal file
76
src/service/smb.rs
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
use crate::config::HazeConfig;
|
||||||
|
use crate::image::pull_image;
|
||||||
|
use crate::service::ServiceTrait;
|
||||||
|
use crate::Result;
|
||||||
|
use bollard::container::{Config, CreateContainerOptions, NetworkingConfig};
|
||||||
|
use bollard::models::{EndpointSettings, HostConfig};
|
||||||
|
use bollard::Docker;
|
||||||
|
use maplit::hashmap;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
|
pub struct Smb;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl ServiceTrait for Smb {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"smb"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn env(&self) -> &[&str] {
|
||||||
|
&[]
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn spawn(
|
||||||
|
&self,
|
||||||
|
docker: &Docker,
|
||||||
|
cloud_id: &str,
|
||||||
|
network: &str,
|
||||||
|
_config: &HazeConfig,
|
||||||
|
) -> Result<String> {
|
||||||
|
let image = "servercontainers/samba";
|
||||||
|
pull_image(docker, image).await?;
|
||||||
|
let options = Some(CreateContainerOptions {
|
||||||
|
name: self.container_name(cloud_id),
|
||||||
|
});
|
||||||
|
let config = Config {
|
||||||
|
image: Some(image),
|
||||||
|
host_config: Some(HostConfig {
|
||||||
|
network_mode: Some(network.to_string()),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
env: Some(vec![
|
||||||
|
"ACCOUNT_test=test",
|
||||||
|
"UID_test=1000",
|
||||||
|
"SAMBA_VOLUME_CONFIG_test=[test]; path=/tmp; valid users = test; guest ok = no; read only = no; browseable = yes",
|
||||||
|
]),
|
||||||
|
labels: Some(hashmap! {
|
||||||
|
"haze-type" => self.name(),
|
||||||
|
"haze-cloud-id" => cloud_id
|
||||||
|
}),
|
||||||
|
networking_config: Some(NetworkingConfig {
|
||||||
|
endpoints_config: hashmap! {
|
||||||
|
network => EndpointSettings {
|
||||||
|
aliases: Some(vec![self.name().to_string()]),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let id = docker.create_container(options, config).await?.id;
|
||||||
|
docker.start_container::<String>(&id, None).await?;
|
||||||
|
Ok(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn container_name(&self, cloud_id: &str) -> String {
|
||||||
|
format!("{}-smb", cloud_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apps(&self) -> &'static [&'static str] {
|
||||||
|
&["files_external"]
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn is_healthy(&self, _docker: &Docker, _cloud_id: &str) -> Result<bool> {
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue