-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker_compose.rs
More file actions
99 lines (87 loc) · 2.96 KB
/
docker_compose.rs
File metadata and controls
99 lines (87 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! Docker Compose installation step
//!
//! This module provides the `InstallDockerComposeStep` which handles Docker Compose
//! installation on remote hosts via Ansible playbooks. This step ensures that
//! the container orchestration tool is properly installed and configured.
//!
//! ## Key Features
//!
//! - Docker Compose installation via Ansible playbook execution
//! - Version management and compatibility checking
//! - Integration with existing Docker installations
//! - Integration with the step-based deployment architecture
//!
//! ## Installation Process
//!
//! The step executes the "install-docker-compose" Ansible playbook which handles:
//! - Docker Compose binary download and installation
//! - Executable permissions and path configuration
//! - Version verification and compatibility checking
//!
//! This step typically runs after Docker engine installation to provide
//! complete container orchestration capabilities.
use std::sync::Arc;
use tracing::{info, instrument};
use crate::adapters::ansible::AnsibleClient;
use crate::shared::command::CommandError;
/// Step that installs Docker Compose on a remote host via Ansible
pub struct InstallDockerComposeStep {
ansible_client: Arc<AnsibleClient>,
}
impl InstallDockerComposeStep {
#[must_use]
pub fn new(ansible_client: Arc<AnsibleClient>) -> Self {
Self { ansible_client }
}
/// Execute the Docker Compose installation step
///
/// This will run the "install-docker-compose" Ansible playbook to install
/// Docker Compose on the remote host.
///
/// # Errors
///
/// Returns an error if:
/// * The Ansible client fails to execute the playbook
/// * Docker Compose installation fails
/// * The playbook execution fails for any other reason
#[instrument(
name = "install_docker_compose",
skip_all,
fields(
step_type = "software",
component = "docker_compose",
method = "ansible"
)
)]
pub fn execute(&self) -> Result<(), CommandError> {
info!(
step = "install_docker_compose",
action = "install_docker_compose",
"Installing Docker Compose via Ansible"
);
self.ansible_client
.run_playbook("install-docker-compose", &[])?;
info!(
step = "install_docker_compose",
status = "success",
"Docker Compose installation completed"
);
Ok(())
}
}
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use std::sync::Arc;
use super::*;
#[test]
fn it_should_create_install_docker_compose_step() {
let ansible_client = Arc::new(AnsibleClient::new(PathBuf::from("test_inventory.yml")));
let step = InstallDockerComposeStep::new(ansible_client);
// Test that the step can be created successfully
assert_eq!(
std::mem::size_of_val(&step),
std::mem::size_of::<Arc<AnsibleClient>>()
);
}
}