mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 09:04:12 +02:00
add option for a separate redis container
This commit is contained in:
parent
6a043913fa
commit
54682a06b6
3 changed files with 84 additions and 0 deletions
|
|
@ -95,6 +95,7 @@ Additionally, you can use the following options when starting an instance:
|
|||
generation.
|
||||
- `mail`: start an [smtp4dev](https://github.com/rnwood/smtp4dev) server and
|
||||
configure it the mail server.
|
||||
- `redis`: start a separate container for redis.
|
||||
- `redis-tls`: connect to redis over TLS.
|
||||
- The name of any configured preset.
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ mod onlyoffice;
|
|||
mod push;
|
||||
mod sftp;
|
||||
// mod sharding;
|
||||
mod redis;
|
||||
mod sharded;
|
||||
mod smb;
|
||||
|
||||
|
|
@ -27,6 +28,7 @@ use crate::service::oc::Oc;
|
|||
pub use crate::service::office::Office;
|
||||
pub use crate::service::onlyoffice::OnlyOffice;
|
||||
pub use crate::service::push::NotifyPush;
|
||||
use crate::service::redis::Redis;
|
||||
use crate::service::sftp::Sftp;
|
||||
use crate::service::sharded::{Sharding, ShardingMigrate, ShardingMigrateUnset, SingleShard};
|
||||
use crate::service::smb::Smb;
|
||||
|
|
@ -215,6 +217,7 @@ pub enum Service {
|
|||
Oc(Oc),
|
||||
Imaginary(Imaginary),
|
||||
Mail(Mail),
|
||||
Redis(Redis),
|
||||
RedisTls(RedisTls),
|
||||
Preset(PresetService),
|
||||
}
|
||||
|
|
@ -260,6 +263,7 @@ impl Service {
|
|||
"clam-icap" => Some(vec![Service::ClamIcap(ClamIcap)]),
|
||||
"clam-icap-tls" => Some(vec![Service::ClamIcapTls(ClamIcapTls)]),
|
||||
"mail" => Some(vec![Service::Mail(Mail)]),
|
||||
"redis" => Some(vec![Service::Redis(Redis)]),
|
||||
"redis-tls" => Some(vec![Service::RedisTls(RedisTls)]),
|
||||
_ => presets
|
||||
.iter()
|
||||
|
|
|
|||
79
src/service/redis.rs
Normal file
79
src/service/redis.rs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
use crate::cloud::CloudOptions;
|
||||
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;
|
||||
use miette::IntoDiagnostic;
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Redis;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ServiceTrait for Redis {
|
||||
fn name(&self) -> &str {
|
||||
"redis"
|
||||
}
|
||||
|
||||
async fn spawn(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
_config: &HazeConfig,
|
||||
_options: &CloudOptions,
|
||||
) -> Result<Vec<String>> {
|
||||
let image = "redis:8-alpine";
|
||||
pull_image(docker, image).await?;
|
||||
let options = Some(CreateContainerOptions {
|
||||
name: self.container_name(cloud_id).unwrap(),
|
||||
..CreateContainerOptions::default()
|
||||
});
|
||||
let config = Config {
|
||||
image: Some(image),
|
||||
host_config: Some(HostConfig {
|
||||
network_mode: Some(network.to_string()),
|
||||
..Default::default()
|
||||
}),
|
||||
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
|
||||
.into_diagnostic()?
|
||||
.id;
|
||||
docker
|
||||
.start_container::<String>(&id, None)
|
||||
.await
|
||||
.into_diagnostic()?;
|
||||
Ok(vec![id])
|
||||
}
|
||||
|
||||
fn container_name(&self, cloud_id: &str) -> Option<String> {
|
||||
Some(format!("{}-redis", cloud_id))
|
||||
}
|
||||
|
||||
async fn post_setup(
|
||||
&self,
|
||||
_docker: &Docker,
|
||||
_cloud_id: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<Vec<String>> {
|
||||
Ok(vec!["occ config:system:set redis host --value redis".into()])
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue