diff --git a/examples/docker-compose.yaml b/examples/docker-compose.yaml index 3e4f522..ba4afbe 100644 --- a/examples/docker-compose.yaml +++ b/examples/docker-compose.yaml @@ -7,3 +7,5 @@ services: - 5432:5432 environment: - POSTGRES_PASSWORD=postgres + cpu_count: 1 + mem_limit: 2gb diff --git a/src/deserializer.rs b/src/deserializer.rs index 495ede2..6d994fa 100644 --- a/src/deserializer.rs +++ b/src/deserializer.rs @@ -16,6 +16,10 @@ pub struct Service { pub volumes: HashMap, #[serde(default, deserialize_with = "deserialize_command")] pub command: Option>, + #[serde(default)] + pub cpu_count: Option, + #[serde(default)] + pub mem_limit: Option, } #[allow(dead_code, unused_variables)] diff --git a/src/runner.rs b/src/runner.rs index 0641c6c..d5aca02 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -55,6 +55,8 @@ struct ServiceContainer { image: String, volumes: HashMap, command: Option>, + cpu_count: Option, + mem_limit: Option, } impl ServiceContainer { @@ -66,6 +68,8 @@ impl ServiceContainer { image: service.image.clone(), volumes: service.volumes.clone(), command: service.command.clone(), + cpu_count: service.cpu_count, + mem_limit: service.mem_limit.clone(), } } @@ -96,6 +100,14 @@ impl ServiceContainer { )); } + // Add CPU and memory limits if specified + if let Some(cpu_count) = self.cpu_count { + output.arg("--cpus").arg(cpu_count.to_string()); + } + if let Some(mem_limit) = &self.mem_limit { + output.arg("--memory").arg(mem_limit); + } + let output = output.arg("-d").arg(self.image.clone()); if let Some(command) = &self.command {