Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

options to limit the cpu and mem of the build #948

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct Args {
}

/// The valid subcommands passed to `nixpacks`, and their arguments.
#[allow(clippy::large_enum_variant)]
#[derive(Subcommand)]
enum Commands {
/// Generate a build plan for an app
Expand Down Expand Up @@ -148,6 +149,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 +247,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 +275,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
Loading