#![warn(missing_docs)]
use docker_types::DockerError;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Serialize, Deserialize)]
pub struct Container {
pub id: String,
pub name: Option<String>,
pub image: String,
pub status: ContainerStatus,
pub ports: Vec<String>,
pub environment: Vec<String>,
pub volumes: Vec<String>,
pub secrets: Vec<String>,
pub cap_add: Vec<String>,
pub cap_drop: Vec<String>,
pub privileged: bool,
pub read_only: bool,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum ContainerStatus {
Created,
Running,
Paused,
Stopped,
Exited,
Dead,
}
pub type Result<T> = std::result::Result<T, DockerError>;
pub trait ContainerManager {
fn create(
&mut self,
image: String,
name: Option<String>,
ports: Vec<String>,
environment: Vec<String>,
volumes: Vec<String>,
restart_policy: Option<String>,
healthcheck: Option<String>,
deploy: Option<String>,
secrets: Vec<String>,
cap_add: Vec<String>,
cap_drop: Vec<String>,
privileged: bool,
read_only: bool,
) -> Result<Container>;
fn start(&mut self, container_id: &str) -> Result<()>;
fn stop(&mut self, container_id: &str) -> Result<()>;
fn delete(&mut self, container_id: &str) -> Result<()>;
fn list(&mut self, all: bool) -> Result<Vec<Container>>;
fn inspect(&mut self, container_id: &str) -> Result<Container>;
fn get_logs(&mut self, container_id: &str, lines: Option<u32>, follow: bool) -> Result<String>;
fn exec_command(&mut self, container_id: &str, command: &str, shell: bool) -> Result<String>;
}
pub trait RuntimeManager {
fn initialize(&mut self) -> Result<()>;
fn shutdown(&mut self) -> Result<()>;
fn status(&mut self) -> Result<String>;
fn version(&mut self) -> Result<String>;
}
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "windows")]
mod windows;
#[cfg(target_os = "linux")]
pub use linux::LinuxContainerManager;
#[cfg(target_os = "macos")]
pub use macos::MacOSContainerManager;
#[cfg(target_os = "windows")]
pub use windows::WindowsContainerManager;
pub fn get_container_manager() -> Box<dyn ContainerManager> {
#[cfg(target_os = "linux")]
{
Box::new(LinuxContainerManager::new())
}
#[cfg(target_os = "macos")]
{
Box::new(MacOSContainerManager::new())
}
#[cfg(target_os = "windows")]
{
Box::new(WindowsContainerManager::new())
}
}
pub fn get_runtime_manager() -> Box<dyn RuntimeManager> {
#[cfg(target_os = "linux")]
{
Box::new(LinuxContainerManager::new())
}
#[cfg(target_os = "macos")]
{
Box::new(MacOSContainerManager::new())
}
#[cfg(target_os = "windows")]
{
Box::new(WindowsContainerManager::new())
}
}