A tool for generating a number of docker compose files based on some configuration taking into account dependency resolution and deduplication.
The following documentation may be outdated and is very much developer focused. User focused documentation will be added soon.
- Add a file to
src/servicesand add it to themod.rs. - Create a struct with all parameters for the service.
- Implement the
Servicetrait for your struct. The trait expects two associated types.Dependenciesis always a tuple of things that implementService(()for no deps or(Service1,)for a single dependency).ServiceConfigis can be a&'static Configif your service does not need any specific configuration but you can set it to your custom type. You will get mutable references to your dependencies in thefrom_configmethod which you can use to construct your service. For theservice_namemethod it is important to generate a unique name especially if your service is generic! You need to make sure it generates different service names for different generic parameters in order to prevent name collisions in the generated docker compose files. See service example. - Derive the
Templatetrait and add a template totemplates/. See the example for more details. - For your service to be loaded it needs to be installed by a
Moduleas described here.
src/services/my_service.rs:
#[derive(Template)]
#[template("my_service.yml")]
struct MyService {
some_prop: String,
}
impl Service for MyService {
type Dependencies = (Traefik,);
type ServiceConfig = &'static Config;
fn from_config(_conf: Self::ServiceConfig, _deps: super::Deps<Self>) -> Self {
Self { some_prop: "foo".into() }
}
fn service_name() -> String {
"my-service".into()
}
}tepmplates/my_serive.yml:
services:
{{ Self::service_name() }}:
image: my_image
environment:
A: { some_prop }- Add a file to
src/modulesand add it to themod.rs. - Create a struct (must be constructable in const context (most likely a unit struct is enough)) and implement
Modulefor it. - In the
installmethod you can use theservice_maps install method to add a service. This will return you a mutable reference to the service for further modification if necessary. See the Example. - Add the services to the
MODULESconst insrc/modules/mod.rs.
src/services/my_serive.rs:
pub struct MyModule;
impl Module for MyModule {
fn enabled(&self, conf: &crate::Config) -> bool {
conf.ccp.is_some()
}
fn install(&self, service_map: &mut crate::dep_map::ServiceMap, conf: &crate::Config) {
service_map.install::<MyService>(conf);
}
}