Skip to content

Commit

Permalink
options to limit the cpu and mem of the build
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-cup committed Aug 18, 2023
1 parent b0b8cd4 commit cc70fd4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ enum Commands {
#[arg(long)]
no_error_without_start: bool,

/// Limit the CPU CFS (Completely Fair Scheduler) quota.
/// Passed directly to the docker build command
#[arg(long)]
cpu_quota: Option<String>,

/// Memory limit.
/// Passed directly to the docker build command
#[arg(long)]
memory: Option<String>,

/// Display more info during build
#[arg(long, short)]
verbose: bool,
Expand Down Expand Up @@ -236,6 +246,8 @@ async fn main() -> Result<()> {
cache_from,
inline_cache,
no_error_without_start,
cpu_quota,
memory,
verbose,
} => {
let verbose = verbose || args.env.contains(&"NIXPACKS_VERBOSE=1".to_string());
Expand All @@ -262,6 +274,8 @@ async fn main() -> Result<()> {
cache_from,
no_error_without_start,
incremental_cache_image,
cpu_quota,
memory,
verbose,
};
create_docker_image(&path, env, &options, build_options).await?;
Expand Down
7 changes: 7 additions & 0 deletions src/nixpacks/builder/docker/docker_image_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ impl DockerImageBuilder {
docker_build_cmd.arg("--platform").arg(l);
}

if let Some(cpu_quota) = self.options.cpu_quota.clone() {
docker_build_cmd.arg("--cpu-quota").arg(cpu_quota);
}
if let Some(memory) = self.options.memory.clone() {
docker_build_cmd.arg("--memory").arg(memory);
}

Ok(docker_build_cmd)
}

Expand Down
2 changes: 2 additions & 0 deletions src/nixpacks/builder/docker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub struct DockerBuilderOptions {
pub current_dir: bool,
pub no_error_without_start: bool,
pub incremental_cache_image: Option<String>,
pub cpu_quota: Option<String>,
pub memory: Option<String>,
pub verbose: bool,
}

Expand Down

0 comments on commit cc70fd4

Please sign in to comment.