Crates.io | docktopus |
lib.rs | docktopus |
version | 0.4.0-alpha.2 |
created_at | 2025-04-08 18:19:34.437172+00 |
updated_at | 2025-04-30 16:04:39.103782+00 |
description | TBD |
homepage | https://tangle.tools |
repository | https://github.com/tangle-network/docktopus |
max_upload_size | |
id | 1625791 |
size | 18,756,990 |
A high-performance Rust library for programmatic container orchestration, offering type-safe Docker and Docker Compose operations with advanced deployment capabilities.
Docktopus bridges the gap between static container configurations and dynamic runtime orchestration. It provides a robust, type-safe interface for programmatically managing containers, with first-class support for both Dockerfile and Docker Compose workflows.
tokio
for high-performance async I/OAdd to your Cargo.toml
:
[dependencies]
# For parsing only (no deployment features)
docktopus = { version = "0.1.0" }
# For full functionality including deployment (default)
docktopus = "0.1.0"
# Or explicitly with all features
docktopus = { version = "0.1.0", features = ["docker"] }
parser
- Enables Dockerfile and Docker Compose parsing functionality (minimal dependencies)deploy
- Enables deployment features using Bollard (includes parser features)use docktopus::{DockerfileConfig, DockerfileParser, ComposeParser};
// Parse a Dockerfile
let dockerfile_content = std::fs::read_to_string("Dockerfile")?;
let config = DockerfileParser::parse(&dockerfile_content)?;
// Parse a Docker Compose file
let compose_content = std::fs::read_to_string("docker-compose.yml")?;
let compose_config = ComposeParser::parse(&compose_content)?;
When the deploy
feature is enabled:
use docktopus::DockerBuilder;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let builder = DockerBuilder::new()?;
// ... deployment functionality available
Ok(())
}
use docktopus::{DockerBuilder, DockerfileConfig, DockerCommand};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let builder = DockerBuilder::new()?;
// Parse existing Dockerfile
let config = builder.from_dockerfile("path/to/Dockerfile").await?;
// Or create programmatically
let config = DockerfileConfig {
base_image: "rust:1.70".to_string(),
commands: vec![
DockerCommand::Run {
command: "cargo build".to_string()
},
DockerCommand::Copy {
source: "./target".to_string(),
dest: "/app".to_string(),
chown: None,
},
],
};
// Deploy container
let container_id = builder.deploy_dockerfile(&config, "my-app:latest").await?;
Ok(())
}
use docktopus::{DockerBuilder, ComposeConfig};
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let builder = DockerBuilder::new()?;
// Parse compose file
let config = builder.from_compose("docker-compose.yml").await?;
// Deploy services
let container_ids: HashMap<String, String> = builder.deploy_compose(&config).await?;
Ok(())
}
use docktopus::{Service, ResourceLimits};
let service = Service {
image: Some("nginx:latest".to_string()),
requirements: Some(ResourceLimits {
cpu_limit: Some(0.5), // Half a CPU
memory_limit: Some("512M".to_string()), // 512MB memory limit
memory_swap: Some("1G".to_string()), // 1GB swap limit
memory_reservation: Some("256M".to_string()), // 256MB soft limit
cpus_shares: Some(512), // CPU shares (relative weight)
cpuset_cpus: Some("0,1".to_string()), // Run on CPUs 0 and 1
}),
..Default::default()
};
use docktopus::{Service, config::compose::HealthCheck};
let service = Service {
image: Some("nginx:latest".to_string()),
healthcheck: Some(HealthCheck {
test: vec![
"CMD-SHELL".to_string(),
"curl -f http://localhost/ || exit 1".to_string()
],
interval: Some(1_000_000_000), // 1 second
timeout: Some(3_000_000_000), // 3 seconds
retries: Some(3),
start_period: Some(2_000_000_000), // 2 seconds
start_interval: None,
}),
..Default::default()
};
use docktopus::DockerBuilder;
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let builder = DockerBuilder::new()?;
// Get container logs
let logs = builder.get_container_logs("container_id").await?;
// Execute command in container
let output = builder.exec_in_container(
"container_id",
vec!["ls", "-la"],
Some(HashMap::new()),
).await?;
// Create and manage volumes
builder.create_volume("my_volume").await?;
let volumes = builder.list_volumes().await?;
Ok(())
}
The library provides detailed error types for proper error handling:
use docktopus::DockerError;
match result {
Err(DockerError::FileError(e)) => println!("File error: {}", e),
Err(DockerError::YamlError(e)) => println!("YAML parsing error: {}", e),
Err(DockerError::DockerfileError(e)) => println!("Dockerfile parsing error: {}", e),
Err(DockerError::BollardError(e)) => println!("Docker API error: {}", e),
Err(DockerError::InvalidIpamConfig) => println!("Invalid network configuration"),
Err(DockerError::ContainerNotRunning(id)) => println!("Container {} not running", id),
Err(DockerError::NetworkCreationError(e)) => println!("Network creation failed: {}", e),
Err(DockerError::InvalidResourceLimit(e)) => println!("Invalid resource limit: {}", e),
Ok(_) => println!("Operation succeeded"),
}
This library is in active development. Current focus areas:
This project is licensed under either of
at your discretion.
Contributions are welcome! Please feel free to submit a Pull Request. When contributing:
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.