mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +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.
|
generation.
|
||||||
- `mail`: start an [smtp4dev](https://github.com/rnwood/smtp4dev) server and
|
- `mail`: start an [smtp4dev](https://github.com/rnwood/smtp4dev) server and
|
||||||
configure it the mail server.
|
configure it the mail server.
|
||||||
|
- `redis`: start a separate container for redis.
|
||||||
- `redis-tls`: connect to redis over TLS.
|
- `redis-tls`: connect to redis over TLS.
|
||||||
- The name of any configured preset.
|
- The name of any configured preset.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ mod onlyoffice;
|
||||||
mod push;
|
mod push;
|
||||||
mod sftp;
|
mod sftp;
|
||||||
// mod sharding;
|
// mod sharding;
|
||||||
|
mod redis;
|
||||||
mod sharded;
|
mod sharded;
|
||||||
mod smb;
|
mod smb;
|
||||||
|
|
||||||
|
|
@ -27,6 +28,7 @@ use crate::service::oc::Oc;
|
||||||
pub use crate::service::office::Office;
|
pub use crate::service::office::Office;
|
||||||
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::redis::Redis;
|
||||||
use crate::service::sftp::Sftp;
|
use crate::service::sftp::Sftp;
|
||||||
use crate::service::sharded::{Sharding, ShardingMigrate, ShardingMigrateUnset, SingleShard};
|
use crate::service::sharded::{Sharding, ShardingMigrate, ShardingMigrateUnset, SingleShard};
|
||||||
use crate::service::smb::Smb;
|
use crate::service::smb::Smb;
|
||||||
|
|
@ -215,6 +217,7 @@ pub enum Service {
|
||||||
Oc(Oc),
|
Oc(Oc),
|
||||||
Imaginary(Imaginary),
|
Imaginary(Imaginary),
|
||||||
Mail(Mail),
|
Mail(Mail),
|
||||||
|
Redis(Redis),
|
||||||
RedisTls(RedisTls),
|
RedisTls(RedisTls),
|
||||||
Preset(PresetService),
|
Preset(PresetService),
|
||||||
}
|
}
|
||||||
|
|
@ -260,6 +263,7 @@ impl Service {
|
||||||
"clam-icap" => Some(vec![Service::ClamIcap(ClamIcap)]),
|
"clam-icap" => Some(vec![Service::ClamIcap(ClamIcap)]),
|
||||||
"clam-icap-tls" => Some(vec![Service::ClamIcapTls(ClamIcapTls)]),
|
"clam-icap-tls" => Some(vec![Service::ClamIcapTls(ClamIcapTls)]),
|
||||||
"mail" => Some(vec![Service::Mail(Mail)]),
|
"mail" => Some(vec![Service::Mail(Mail)]),
|
||||||
|
"redis" => Some(vec![Service::Redis(Redis)]),
|
||||||
"redis-tls" => Some(vec![Service::RedisTls(RedisTls)]),
|
"redis-tls" => Some(vec![Service::RedisTls(RedisTls)]),
|
||||||
_ => presets
|
_ => presets
|
||||||
.iter()
|
.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