torrust_tracker_deployer_lib/config/mod.rs
1//! Configuration management for deployment settings
2//!
3//! This module provides the `Config` struct which manages essential file system
4//! paths for the deployment process including template sources and build outputs.
5//!
6//! ## Current Configuration Areas
7//!
8//! - File system paths for templates and build outputs
9//! - Project root directory for resolving relative paths
10//!
11//! ## Path Relationships
12//!
13//! Typically, the paths have this relationship:
14//! - `project_root`: `/path/to/torrust-tracker-deploy`
15//! - `templates_dir`: `{project_root}/templates`
16//! - `build_dir`: `{project_root}/build`
17//!
18//! The configuration is typically created once at deployment start and passed
19//! throughout the system to ensure consistent path resolution across all components.
20
21use std::path::PathBuf;
22
23/// Configuration parameters for deployment environments.
24///
25/// Centralizes all deployment-related configuration including file paths,
26/// service connection details, and runtime behavior settings.
27///
28/// Created once at deployment start and passed to [`Services::new()`](crate::testing::e2e::container::Services::new).
29pub struct Config {
30 /// Directory containing template files for rendering configurations.
31 ///
32 /// This directory should contain subdirectories for different template
33 /// types (e.g., "ansible/", "tofu/") with template files that will be
34 /// processed and rendered to the build directory.
35 pub templates_dir: PathBuf,
36
37 /// Root directory of the project.
38 ///
39 /// Used for resolving relative paths and locating project resources
40 /// such as SSH key fixtures and project-specific configuration files.
41 pub project_root: PathBuf,
42
43 /// Directory where rendered configuration files will be written.
44 ///
45 /// All processed templates and generated configuration files are written
46 /// to subdirectories within this build directory. This directory is
47 /// typically git-ignored to avoid committing generated files.
48 pub build_dir: PathBuf,
49}
50
51impl Config {
52 /// Creates a new configuration with the provided parameters.
53 ///
54 /// ```rust
55 /// # use std::path::PathBuf;
56 /// # use torrust_tracker_deployer_lib::config::Config;
57 /// let config = Config::new(
58 /// PathBuf::from("/home/user/project/templates"),
59 /// PathBuf::from("/home/user/project"),
60 /// PathBuf::from("/home/user/project/build"),
61 /// );
62 /// ```
63 #[must_use]
64 pub fn new(templates_dir: PathBuf, project_root: PathBuf, build_dir: PathBuf) -> Self {
65 Self {
66 templates_dir,
67 project_root,
68 build_dir,
69 }
70 }
71}