mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
84 lines
2.6 KiB
Rust
84 lines
2.6 KiB
Rust
use crate::cloud::CloudOptions;
|
|
use crate::config::HazeConfig;
|
|
use crate::image::pull_image;
|
|
use crate::service::{split_cmnd, ServiceTrait};
|
|
use crate::Result;
|
|
use bollard::config::NetworkingConfig;
|
|
use bollard::models::{ContainerCreateBody, EndpointSettings, HostConfig};
|
|
use bollard::query_parameters::CreateContainerOptions;
|
|
use bollard::Docker;
|
|
use maplit::hashmap;
|
|
use miette::IntoDiagnostic;
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
pub struct Imaginary;
|
|
|
|
#[async_trait::async_trait]
|
|
impl ServiceTrait for Imaginary {
|
|
fn name(&self) -> &str {
|
|
"imaginary"
|
|
}
|
|
|
|
async fn spawn(
|
|
&self,
|
|
docker: &Docker,
|
|
cloud_id: &str,
|
|
network: &str,
|
|
_config: &HazeConfig,
|
|
_options: &CloudOptions,
|
|
) -> Result<Vec<String>> {
|
|
let image = "nextcloud/aio-imaginary:latest";
|
|
pull_image(docker, image).await?;
|
|
let options = Some(CreateContainerOptions {
|
|
name: self.container_name(cloud_id),
|
|
..CreateContainerOptions::default()
|
|
});
|
|
let config = ContainerCreateBody {
|
|
image: Some(image.into()),
|
|
host_config: Some(HostConfig {
|
|
network_mode: Some(network.to_string()),
|
|
..Default::default()
|
|
}),
|
|
labels: Some(hashmap! {
|
|
"haze-type".into() => self.name().into(),
|
|
"haze-cloud-id".into() => cloud_id.into()
|
|
}),
|
|
networking_config: Some(NetworkingConfig {
|
|
endpoints_config: Some(hashmap! {
|
|
network.into() => EndpointSettings {
|
|
aliases: Some(vec![self.name().to_string()]),
|
|
..Default::default()
|
|
}
|
|
}),
|
|
}),
|
|
..Default::default()
|
|
};
|
|
let id = docker
|
|
.create_container(options, config)
|
|
.await
|
|
.into_diagnostic()?
|
|
.id;
|
|
docker.start_container(&id, None).await.into_diagnostic()?;
|
|
Ok(vec![id])
|
|
}
|
|
|
|
fn container_name(&self, cloud_id: &str) -> Option<String> {
|
|
Some(format!("{}-imaginary", cloud_id))
|
|
}
|
|
|
|
async fn post_setup(
|
|
&self,
|
|
_docker: &Docker,
|
|
_cloud_id: &str,
|
|
_config: &HazeConfig,
|
|
) -> Result<Vec<Vec<String>>> {
|
|
Ok(vec![
|
|
split_cmnd(
|
|
"occ config:system:set enabledPreviewProviders 0 --value='OC\\Preview\\Imaginary'",
|
|
),
|
|
split_cmnd(
|
|
"occ config:system:set preview_imaginary_url --value='http://imaginary:9000'",
|
|
),
|
|
])
|
|
}
|
|
}
|