Skip to main content

Module rendering

Module rendering 

Source
Expand description

Template Rendering Services

This module contains application-layer services for rendering infrastructure templates. Each service encapsulates the logic for rendering a specific type of template (Ansible, OpenTofu, Docker Compose, etc.) and is designed to be shared across multiple command handlers and steps.

§Architecture

Rendering services follow the DDD application layer pattern:

  • Orchestrate: Bridge multiple domain types into infrastructure generator calls
  • Transform: Map domain types to template-specific context types
  • Decide: Apply conditional logic (e.g., “if Prometheus is configured, include it”)

§Services

  • AnsibleTemplateRenderingService - Renders Ansible inventory and playbook templates
  • OpenTofuTemplateRenderingService - Renders OpenTofu infrastructure templates
  • TrackerTemplateRenderingService - Renders Tracker configuration templates
  • PrometheusTemplateRenderingService - Renders Prometheus configuration templates
  • GrafanaTemplateRenderingService - Renders Grafana provisioning templates
  • DockerComposeTemplateRenderingService - Renders Docker Compose configuration templates
  • CaddyTemplateRenderingService - Renders Caddy TLS proxy configuration templates
  • BackupTemplateRenderingService - Renders backup configuration templates

§Design Principles

All rendering services follow these principles:

  1. Explicit Inputs: Services take explicit domain config types (e.g., &TrackerConfig) rather than Environment<S>. This makes dependencies clear and allows both the render command handler and the release steps to call them.

  2. Factory Pattern: Services use from_paths() or from_params() factory methods that accept templates_dir, build_dir, and clock as construction parameters.

  3. Single Responsibility: Each service handles exactly one template type and its associated context building logic.

  4. Error Wrapping: Services define thin error types that wrap infrastructure generator errors while preserving context.

§Usage Example

use std::sync::Arc;
use torrust_tracker_deployer_lib::application::services::rendering::AnsibleTemplateRenderingService;
use torrust_tracker_deployer_lib::shared::clock::SystemClock;

let service = AnsibleTemplateRenderingService::from_paths(
    templates_dir,
    build_dir,
    Arc::new(SystemClock),
);

service.render_templates(&user_inputs, instance_ip, None).await?;

Structs§

AnsibleTemplateRenderingService
Service for rendering Ansible templates with runtime configuration
BackupTemplateRenderingService
Service for rendering backup configuration templates
CaddyTemplateRenderingService
Service for rendering Caddy TLS proxy templates
DockerComposeTemplateRenderingService
Service for rendering Docker Compose templates
GrafanaTemplateRenderingService
Service for rendering Grafana provisioning templates
OpenTofuTemplateRenderingService
Service for rendering OpenTofu infrastructure templates
PrometheusTemplateRenderingService
Service for rendering Prometheus configuration templates
TrackerTemplateRenderingService
Service for rendering Tracker configuration templates

Enums§

AnsibleTemplateRenderingServiceError
Errors that can occur during Ansible template rendering
BackupTemplateRenderingServiceError
Errors that can occur during backup template rendering
CaddyTemplateRenderingServiceError
Errors that can occur during Caddy template rendering
DockerComposeTemplateRenderingServiceError
Errors that can occur during Docker Compose template rendering
GrafanaTemplateRenderingServiceError
Errors that can occur during Grafana template rendering
OpenTofuTemplateRenderingServiceError
Errors that can occur during OpenTofu template rendering
PrometheusTemplateRenderingServiceError
Errors that can occur during Prometheus template rendering
TrackerTemplateRenderingServiceError
Errors that can occur during Tracker template rendering