Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 63dec20

Browse files
authored
feat: support cpu_count and mem_limit (#20)
* feat: support cpu_count and mem_limit * chore: remove alias
1 parent 51f8089 commit 63dec20

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

examples/docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ services:
77
- 5432:5432
88
environment:
99
- POSTGRES_PASSWORD=postgres
10+
cpu_count: 1
11+
mem_limit: 2gb

src/deserializer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ pub struct Service {
1616
pub volumes: HashMap<String, String>,
1717
#[serde(default, deserialize_with = "deserialize_command")]
1818
pub command: Option<Vec<String>>,
19+
#[serde(default)]
20+
pub cpu_count: Option<u32>,
21+
#[serde(default)]
22+
pub mem_limit: Option<String>,
1923
}
2024

2125
#[allow(dead_code, unused_variables)]

src/runner.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ struct ServiceContainer {
5555
image: String,
5656
volumes: HashMap<String, String>,
5757
command: Option<Vec<String>>,
58+
cpu_count: Option<u32>,
59+
mem_limit: Option<String>,
5860
}
5961

6062
impl ServiceContainer {
@@ -66,6 +68,8 @@ impl ServiceContainer {
6668
image: service.image.clone(),
6769
volumes: service.volumes.clone(),
6870
command: service.command.clone(),
71+
cpu_count: service.cpu_count,
72+
mem_limit: service.mem_limit.clone(),
6973
}
7074
}
7175

@@ -96,6 +100,14 @@ impl ServiceContainer {
96100
));
97101
}
98102

103+
// Add CPU and memory limits if specified
104+
if let Some(cpu_count) = self.cpu_count {
105+
output.arg("--cpus").arg(cpu_count.to_string());
106+
}
107+
if let Some(mem_limit) = &self.mem_limit {
108+
output.arg("--memory").arg(mem_limit);
109+
}
110+
99111
let output = output.arg("-d").arg(self.image.clone());
100112

101113
if let Some(command) = &self.command {

0 commit comments

Comments
 (0)