diff --git a/docs/codebase-architecture.md b/docs/codebase-architecture.md index df075de1..fdb7f760 100644 --- a/docs/codebase-architecture.md +++ b/docs/codebase-architecture.md @@ -189,11 +189,19 @@ All modules include comprehensive `//!` documentation with: ### Core Infrastructure +**Bootstrap Module:** + +Application initialization and lifecycle management: + +- ✅ `src/bootstrap/mod.rs` - Bootstrap module root with re-exports +- ✅ `src/bootstrap/app.rs` - Main application bootstrap and entry point logic +- ✅ `src/bootstrap/container.rs` - Dependency injection container (Services) +- ✅ `src/bootstrap/help.rs` - Help and usage information display +- ✅ `src/bootstrap/logging.rs` - Logging configuration and utilities + **Root Level Files:** - ✅ `src/main.rs` - Main binary entry point -- ✅ `src/container.rs` - Dependency injection container -- ✅ `src/logging.rs` - Logging configuration and utilities - ✅ `src/lib.rs` - Library root module **Binary Files:** @@ -359,20 +367,28 @@ Generic utilities used across all layers: - ✅ `src/shared/command/mod.rs` - Command execution utilities (used by all adapters) - ✅ `src/shared/clock.rs` - Time abstraction for deterministic testing - ✅ `src/shared/error/mod.rs` - Shared error types -- ✅ `src/shared/port_checker.rs` - Network port checking -- ✅ `src/shared/port_usage_checker.rs` - Port usage validation - ✅ `src/shared/username.rs` - Username value object -Note: SSH and Docker adapters have been moved to `src/adapters/` +Note: SSH and Docker adapters have been moved to `src/adapters/`. Network testing utilities (port_checker, port_usage_checker) have been moved to `src/testing/network/`. ### Testing Infrastructure **E2E Testing Framework:** -- ✅ `src/e2e/mod.rs` - E2E testing framework coordination -- ✅ `src/e2e/containers/mod.rs` - Container-based testing infrastructure -- ✅ `src/e2e/containers/actions/` - E2E test actions -- ✅ `src/e2e/containers/provisioned.rs` - Provisioned container management +- ✅ `src/testing/mod.rs` - Testing framework root module +- ✅ `src/testing/e2e/mod.rs` - E2E testing framework coordination +- ✅ `src/testing/e2e/containers/mod.rs` - Container-based testing infrastructure +- ✅ `src/testing/e2e/containers/actions/` - E2E test actions +- ✅ `src/testing/e2e/containers/provisioned.rs` - Provisioned container management +- ✅ `src/testing/integration/` - Integration testing utilities +- ✅ `src/testing/fixtures.rs` - Reusable test fixtures +- ✅ `src/testing/mock_clock.rs` - Mock clock implementation for deterministic testing + +**Network Testing Utilities:** + +- ✅ `src/testing/network/mod.rs` - Network testing utilities root +- ✅ `src/testing/network/port_checker.rs` - TCP port connectivity checking +- ✅ `src/testing/network/port_usage_checker.rs` - Port usage validation and process identification **Configuration:** diff --git a/src/bin/e2e_config_tests.rs b/src/bin/e2e_config_tests.rs index 9e8b0d37..48885754 100644 --- a/src/bin/e2e_config_tests.rs +++ b/src/bin/e2e_config_tests.rs @@ -65,8 +65,8 @@ use torrust_tracker_deployer_lib::testing::e2e::tasks::run_configure_command::ru use tracing::{error, info}; use torrust_tracker_deployer_lib::adapters::ssh::{SshCredentials, DEFAULT_SSH_PORT}; +use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder}; use torrust_tracker_deployer_lib::domain::{Environment, EnvironmentName}; -use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder}; use torrust_tracker_deployer_lib::shared::Username; use torrust_tracker_deployer_lib::testing::e2e::context::{TestContext, TestContextType}; use torrust_tracker_deployer_lib::testing::e2e::tasks::{ diff --git a/src/bin/e2e_provision_and_destroy_tests.rs b/src/bin/e2e_provision_and_destroy_tests.rs index 6be2e2b7..d5ce2b9b 100644 --- a/src/bin/e2e_provision_and_destroy_tests.rs +++ b/src/bin/e2e_provision_and_destroy_tests.rs @@ -54,8 +54,8 @@ use tracing::{error, info}; // Import E2E testing infrastructure use torrust_tracker_deployer_lib::adapters::ssh::{SshCredentials, DEFAULT_SSH_PORT}; +use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder}; use torrust_tracker_deployer_lib::domain::{Environment, EnvironmentName}; -use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder}; use torrust_tracker_deployer_lib::shared::Username; use torrust_tracker_deployer_lib::testing::e2e::context::{TestContext, TestContextType}; use torrust_tracker_deployer_lib::testing::e2e::tasks::virtual_machine::{ diff --git a/src/bin/e2e_tests_full.rs b/src/bin/e2e_tests_full.rs index 43185404..5b98d434 100644 --- a/src/bin/e2e_tests_full.rs +++ b/src/bin/e2e_tests_full.rs @@ -61,8 +61,8 @@ use tracing::{error, info}; // Import E2E testing infrastructure use torrust_tracker_deployer_lib::adapters::ssh::DEFAULT_SSH_PORT; +use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder}; use torrust_tracker_deployer_lib::infrastructure::persistence::repository_factory::RepositoryFactory; -use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder}; use torrust_tracker_deployer_lib::shared::{Clock, SystemClock}; use torrust_tracker_deployer_lib::testing::e2e::context::{TestContext, TestContextType}; use torrust_tracker_deployer_lib::testing::e2e::tasks::{ diff --git a/src/bin/test_logging.rs b/src/bin/test_logging.rs index 86900fa1..0b1d95a9 100644 --- a/src/bin/test_logging.rs +++ b/src/bin/test_logging.rs @@ -31,7 +31,7 @@ use std::path::PathBuf; use clap::Parser; -use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder}; +use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingBuilder}; use tracing::{debug, error, info, trace, warn}; #[derive(Parser)] diff --git a/src/app.rs b/src/bootstrap/app.rs similarity index 93% rename from src/app.rs rename to src/bootstrap/app.rs index 72b7692a..735f3b96 100644 --- a/src/app.rs +++ b/src/bootstrap/app.rs @@ -20,7 +20,7 @@ use clap::Parser; use tracing::info; -use torrust_tracker_deployer_lib::{help, logging, presentation}; +use crate::{bootstrap, presentation}; /// Main application entry point /// @@ -42,7 +42,7 @@ pub fn run() { let logging_config = cli.global.logging_config(); - logging::init_subscriber(logging_config); + bootstrap::logging::init_subscriber(logging_config); info!( app = "torrust-tracker-deployer", @@ -62,7 +62,7 @@ pub fn run() { } } None => { - help::display_getting_started(); + bootstrap::help::display_getting_started(); } } diff --git a/src/container.rs b/src/bootstrap/container.rs similarity index 100% rename from src/container.rs rename to src/bootstrap/container.rs diff --git a/src/help.rs b/src/bootstrap/help.rs similarity index 97% rename from src/help.rs rename to src/bootstrap/help.rs index 29627242..bc7af4f7 100644 --- a/src/help.rs +++ b/src/bootstrap/help.rs @@ -29,7 +29,7 @@ /// # Example /// /// ```rust -/// use torrust_tracker_deployer_lib::help; +/// use torrust_tracker_deployer_lib::bootstrap::help; /// /// // Display help when user runs app without arguments /// help::display_getting_started(); @@ -73,7 +73,7 @@ pub fn display_getting_started() { /// # Example /// /// ```rust -/// use torrust_tracker_deployer_lib::help; +/// use torrust_tracker_deployer_lib::bootstrap::help; /// /// // Display troubleshooting info when user encounters issues /// help::display_troubleshooting(); diff --git a/src/logging.rs b/src/bootstrap/logging.rs similarity index 97% rename from src/logging.rs rename to src/bootstrap/logging.rs index 0970db06..a415a98c 100644 --- a/src/logging.rs +++ b/src/bootstrap/logging.rs @@ -27,7 +27,7 @@ //! //! ```rust,no_run //! use std::path::Path; -//! use torrust_tracker_deployer_lib::logging::{LogOutput, LogFormat, LoggingBuilder}; +//! use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, LogFormat, LoggingBuilder}; //! //! // Flexible builder API //! LoggingBuilder::new(Path::new("./data/logs")) @@ -40,7 +40,7 @@ //! //! ```rust,no_run //! use std::path::Path; -//! use torrust_tracker_deployer_lib::logging::{LogOutput, init_compact}; +//! use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, init_compact}; //! //! // E2E tests - enable stderr visibility with production log location //! init_compact(Path::new("./data/logs"), LogOutput::FileAndStderr); @@ -151,7 +151,7 @@ impl LoggingConfig { /// /// ```rust,no_run /// use std::path::Path; -/// use torrust_tracker_deployer_lib::logging::{LogOutput, LogFormat, LoggingBuilder}; +/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, LogFormat, LoggingBuilder}; /// /// // Basic usage with defaults (Compact file format, Pretty stderr format, FileAndStderr output) /// LoggingBuilder::new(Path::new("./data/logs")).init(); @@ -314,7 +314,7 @@ impl LoggingBuilder { /// /// ```rust,no_run /// use std::path::PathBuf; -/// use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingConfig, init_subscriber}; +/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingConfig, init_subscriber}; /// /// let config = LoggingConfig::new( /// PathBuf::from("./data/logs"), @@ -589,7 +589,7 @@ fn create_log_file_appender(log_dir: &Path) -> tracing_appender::non_blocking::N /// # Example /// ```rust,no_run /// use std::path::Path; -/// use torrust_tracker_deployer_lib::logging::{LogOutput, init}; +/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, init}; /// /// // E2E tests - enable stderr visibility with production location /// init(Path::new("./data/logs"), LogOutput::FileAndStderr); @@ -632,7 +632,7 @@ pub fn init(log_dir: &Path, output: LogOutput) { /// # Example /// ```rust,no_run /// use std::path::Path; -/// use torrust_tracker_deployer_lib::logging::{LogOutput, init_json}; +/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, init_json}; /// /// // E2E tests - enable stderr visibility with production location /// init_json(Path::new("./data/logs"), LogOutput::FileAndStderr); @@ -675,7 +675,7 @@ pub fn init_json(log_dir: &Path, output: LogOutput) { /// # Example /// ```rust,no_run /// use std::path::Path; -/// use torrust_tracker_deployer_lib::logging::{LogOutput, init_compact}; +/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, init_compact}; /// /// // E2E tests - enable stderr visibility with production location /// init_compact(Path::new("./data/logs"), LogOutput::FileAndStderr); @@ -716,7 +716,7 @@ pub fn init_compact(log_dir: &Path, output: LogOutput) { /// # Example /// ```rust,no_run /// use std::path::Path; -/// use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, init_with_format}; +/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, init_with_format}; /// /// // Initialize with JSON format for E2E tests with production location /// init_with_format(Path::new("./data/logs"), LogOutput::FileAndStderr, &LogFormat::Json); diff --git a/src/bootstrap/mod.rs b/src/bootstrap/mod.rs new file mode 100644 index 00000000..fa44fa9a --- /dev/null +++ b/src/bootstrap/mod.rs @@ -0,0 +1,21 @@ +//! Bootstrap Module +//! +//! This module contains application initialization and bootstrap concerns. +//! It handles application lifecycle, dependency injection, logging setup, +//! and help display. +//! +//! ## Modules +//! +//! - `app` - Main application bootstrap and entry point logic +//! - `container` - Service container for dependency injection +//! - `help` - Help and usage information display +//! - `logging` - Logging configuration and initialization + +pub mod app; +pub mod container; +pub mod help; +pub mod logging; + +// Re-export commonly used types for convenience +pub use container::Services; +pub use logging::{LogFormat, LogOutput, LoggingBuilder, LoggingConfig}; diff --git a/src/config/mod.rs b/src/config/mod.rs index 1f90c9bc..673b5332 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -25,7 +25,7 @@ use std::path::PathBuf; /// Centralizes all deployment-related configuration including file paths, /// service connection details, and runtime behavior settings. /// -/// Created once at deployment start and passed to [`Services::new()`](crate::container::Services::new). +/// Created once at deployment start and passed to [`Services::new()`](crate::bootstrap::container::Services::new). pub struct Config { /// Directory containing template files for rendering configurations. /// diff --git a/src/lib.rs b/src/lib.rs index 0b992b1b..9d260835 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,21 +20,17 @@ //! //! ## Other Modules //! - `adapters` - External tool adapters (thin CLI wrappers) +//! - `bootstrap` - Application initialization and bootstrap concerns //! - `config` - Configuration management for deployment environments -//! - `container` - Service container for dependency injection -//! - `help` - Help and usage information display functions -//! - `logging` - Logging configuration and utilities //! - `shared` - Shared modules used across different layers //! - `testing` - Testing utilities (unit, integration, and end-to-end) pub mod adapters; pub mod application; +pub mod bootstrap; pub mod config; -pub mod container; pub mod domain; -pub mod help; pub mod infrastructure; -pub mod logging; pub mod presentation; pub mod shared; pub mod testing; diff --git a/src/main.rs b/src/main.rs index 024d1578..6111ee10 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,10 @@ //! Main binary entry point for Torrust Tracker Deployer. //! //! This binary provides the main CLI interface for the deployment infrastructure. -//! All application logic is contained in the `app` module. +//! All application logic is contained in the `bootstrap::app` module. -mod app; +use torrust_tracker_deployer_lib::bootstrap; fn main() { - app::run(); + bootstrap::app::run(); } diff --git a/src/presentation/cli/args.rs b/src/presentation/cli/args.rs index a3d15b96..24bcc550 100644 --- a/src/presentation/cli/args.rs +++ b/src/presentation/cli/args.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; -use crate::logging::{LogFormat, LogOutput, LoggingConfig}; +use crate::bootstrap::logging::{LogFormat, LogOutput, LoggingConfig}; /// Global CLI arguments for logging configuration /// @@ -87,7 +87,7 @@ impl GlobalArgs { /// /// ```rust /// # use torrust_tracker_deployer_lib::presentation::cli::args::GlobalArgs; - /// # use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingConfig}; + /// # use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingConfig}; /// # use std::path::PathBuf; /// // Create args with log configuration /// let args = GlobalArgs { diff --git a/src/shared/mod.rs b/src/shared/mod.rs index 03c61696..ce56e0a4 100644 --- a/src/shared/mod.rs +++ b/src/shared/mod.rs @@ -7,14 +7,10 @@ pub mod clock; pub mod command; pub mod error; -pub mod port_checker; -pub mod port_usage_checker; pub mod username; // Re-export commonly used types for convenience pub use clock::{Clock, SystemClock}; pub use command::{CommandError, CommandExecutor, CommandResult}; pub use error::{ErrorKind, Traceable}; -pub use port_checker::{PortChecker, PortCheckerError}; -pub use port_usage_checker::{PortUsageChecker, PortUsageError}; pub use username::{Username, UsernameError}; diff --git a/src/testing/e2e/containers/actions/ssh_wait.rs b/src/testing/e2e/containers/actions/ssh_wait.rs index c6680f92..218ded0a 100644 --- a/src/testing/e2e/containers/actions/ssh_wait.rs +++ b/src/testing/e2e/containers/actions/ssh_wait.rs @@ -33,7 +33,7 @@ use std::time::{Duration, Instant}; use tracing::{debug, info, warn}; use crate::adapters::ssh::SshServiceChecker; -use crate::shared::PortChecker; +use crate::testing::network::PortChecker; /// Specific error types for SSH wait operations #[derive(Debug, thiserror::Error)] diff --git a/src/testing/e2e/context.rs b/src/testing/e2e/context.rs index 14c7d3cd..a28fab75 100644 --- a/src/testing/e2e/context.rs +++ b/src/testing/e2e/context.rs @@ -23,8 +23,8 @@ use tempfile::TempDir; use tracing::{info, warn}; +use crate::bootstrap::container::Services; use crate::config::Config; -use crate::container::Services; use crate::domain::environment::state::AnyEnvironmentState; use crate::domain::Environment; use crate::infrastructure::external_tools::tofu::OPENTOFU_SUBFOLDER; diff --git a/src/testing/e2e/tasks/container/run_provision_simulation.rs b/src/testing/e2e/tasks/container/run_provision_simulation.rs index 616e0691..6489d96e 100644 --- a/src/testing/e2e/tasks/container/run_provision_simulation.rs +++ b/src/testing/e2e/tasks/container/run_provision_simulation.rs @@ -25,7 +25,7 @@ use tracing::info; use crate::adapters::ssh::SshCredentials; use crate::application::steps::RenderAnsibleTemplatesStep; -use crate::container::Services; +use crate::bootstrap::container::Services; use crate::infrastructure::external_tools::ansible::AnsibleTemplateRenderer; use crate::testing::e2e::containers::actions::{SshKeySetupAction, SshWaitAction}; use crate::testing::e2e::containers::timeout::ContainerTimeouts; diff --git a/src/testing/integration/ssh_server/debug.rs b/src/testing/integration/ssh_server/debug.rs index fb29e7ca..19ecb9d0 100644 --- a/src/testing/integration/ssh_server/debug.rs +++ b/src/testing/integration/ssh_server/debug.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use crate::adapters::docker::DockerClient; -use crate::shared::port_usage_checker::PortUsageChecker; +use crate::testing::network::PortUsageChecker; // Import constants only for the convenience function use super::constants::{SSH_SERVER_IMAGE_NAME, SSH_SERVER_IMAGE_TAG}; diff --git a/src/testing/mod.rs b/src/testing/mod.rs index 422a4fb1..8b3a074f 100644 --- a/src/testing/mod.rs +++ b/src/testing/mod.rs @@ -9,14 +9,17 @@ //! - `integration` - Integration testing utilities //! - `fixtures` - Reusable test fixtures //! - `mock_clock` - Mock clock implementation for deterministic time testing +//! - `network` - Network testing utilities (port checking, connectivity testing) pub mod e2e; pub mod fixtures; pub mod integration; pub mod mock_clock; +pub mod network; // Re-export commonly used testing types pub use mock_clock::MockClock; +pub use network::{PortChecker, PortCheckerError, PortUsageChecker, PortUsageError}; // Re-export E2E types for convenience pub use e2e::{ diff --git a/src/testing/network/mod.rs b/src/testing/network/mod.rs new file mode 100644 index 00000000..7a5c35b8 --- /dev/null +++ b/src/testing/network/mod.rs @@ -0,0 +1,17 @@ +//! Network Testing Utilities +//! +//! This module provides network-related testing utilities for checking port +//! connectivity and port usage. These utilities are used exclusively in tests +//! to verify network connectivity and diagnose port conflicts. +//! +//! ## Modules +//! +//! - `port_checker` - TCP port connectivity checking +//! - `port_usage_checker` - Port usage and process identification + +pub mod port_checker; +pub mod port_usage_checker; + +// Re-export commonly used types for convenience +pub use port_checker::{PortChecker, PortCheckerError}; +pub use port_usage_checker::{PortUsageChecker, PortUsageError}; diff --git a/src/shared/port_checker.rs b/src/testing/network/port_checker.rs similarity index 99% rename from src/shared/port_checker.rs rename to src/testing/network/port_checker.rs index 330e2e8c..cd8f15a2 100644 --- a/src/shared/port_checker.rs +++ b/src/testing/network/port_checker.rs @@ -16,7 +16,7 @@ //! ```rust,no_run //! use std::net::{SocketAddr, IpAddr, Ipv4Addr}; //! use std::time::Duration; -//! use torrust_tracker_deployer_lib::shared::PortChecker; +//! use torrust_tracker_deployer_lib::testing::network::PortChecker; //! //! # fn main() -> Result<(), Box> { //! let checker = PortChecker::new(); diff --git a/src/shared/port_usage_checker.rs b/src/testing/network/port_usage_checker.rs similarity index 97% rename from src/shared/port_usage_checker.rs rename to src/testing/network/port_usage_checker.rs index c810d029..d92201a6 100644 --- a/src/shared/port_usage_checker.rs +++ b/src/testing/network/port_usage_checker.rs @@ -3,7 +3,7 @@ //! This module provides functionality to check which processes are using specific ports //! on the system. It uses system commands like `netstat` or `ss` to query port usage. //! -//! This is different from [`crate::shared::port_checker`] which checks TCP connectivity +//! This is different from [`crate::testing::network::port_checker`] which checks TCP connectivity //! to a port. This module checks which process is actually bound to a port. use thiserror::Error; @@ -22,7 +22,7 @@ use crate::adapters::network::{NetstatClient, NetworkError, SsClient}; /// # Example /// /// ```rust,no_run -/// use torrust_tracker_deployer_lib::shared::port_usage_checker::PortUsageChecker; +/// use torrust_tracker_deployer_lib::testing::network::PortUsageChecker; /// /// // Check if port 22 is in use /// match PortUsageChecker::check_port(22) { @@ -61,7 +61,7 @@ impl PortUsageChecker { /// # Example /// /// ```rust,no_run - /// use torrust_tracker_deployer_lib::shared::port_usage_checker::PortUsageChecker; + /// use torrust_tracker_deployer_lib::testing::network::PortUsageChecker; /// /// match PortUsageChecker::check_port(8080) { /// Ok(lines) => { @@ -217,7 +217,7 @@ impl PortUsageError { /// # Example /// /// ```rust,no_run - /// use torrust_tracker_deployer_lib::shared::port_usage_checker::PortUsageChecker; + /// use torrust_tracker_deployer_lib::testing::network::PortUsageChecker; /// /// if let Err(e) = PortUsageChecker::check_port(8080) { /// eprintln!("Error: {e}"); diff --git a/tests/logging_integration.rs b/tests/logging_integration.rs index 655af1a7..0aef5389 100644 --- a/tests/logging_integration.rs +++ b/tests/logging_integration.rs @@ -17,7 +17,7 @@ use std::fs; use std::path::PathBuf; use std::process::Command; use tempfile::TempDir; -use torrust_tracker_deployer_lib::logging::LOG_FILE_NAME; +use torrust_tracker_deployer_lib::bootstrap::logging::LOG_FILE_NAME; /// Helper struct to manage test execution and cleanup struct LoggingTest {