Skip to content

CLI: Add --shm-size and --ulimit to image build; case-insensitive memory parsing#40838

Draft
dkbennett wants to merge 6 commits into
masterfrom
user/dkbennett/buildmemorycpu
Draft

CLI: Add --shm-size and --ulimit to image build; case-insensitive memory parsing#40838
dkbennett wants to merge 6 commits into
masterfrom
user/dkbennett/buildmemorycpu

Conversation

@dkbennett

Copy link
Copy Markdown
Member

Summary of the Pull Request

Add --shm-size and --ulimit to image build; case-insensitive memory parsing.

Why --memory and --cpus are not included for image build

Docker BuildKit, which has been the default builder since Docker 23.0, deprecated and removed support for the --memory and --cpus flags on docker build. These flags only worked with the legacy builder. With BuildKit, per-build memory and CPU limits are only achievable by using docker buildx build with a docker-container driver, which requires creating and managing a separate builder instance — a significantly more complex integration that warrants its own design discussion. The --shm-size and --ulimit flags remain supported by BuildKit and provide build-time resource controls for shared memory and process-level limits.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

  • Case-insensitive ParseMemorySize: Aligns with Docker CLI behavior — accepts both lowercase and uppercase suffixes (e.g., 512m, 1G, 256kb). Benefits --memory and --shm-size for container create/run and image build.
  • --shm-size for image build: Sets the shared memory size for build containers.
  • --ulimit for image build: Sets ulimit constraints (e.g., nofile, nproc, memlock) on build containers. Supports multiple values.
  • Unit tests: Comprehensive coverage for memory size parsing (case variants, edge cases) and CPU/nano-cpus parsing validation.
  • Command line test cases: Validates --shm-size and --ulimit parsing for the build command.

Validation Steps Performed

Copilot AI review requested due to automatic review settings June 17, 2026 23:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the WSL Containers (wslc) image build command to support additional BuildKit-compatible resource controls (--shm-size and --ulimit) and updates shared memory-size parsing to be case-insensitive (aligning with Docker CLI suffix behavior). It also adds unit/e2e/CLI test coverage to validate the new parsing and command-line flows.

Changes:

  • Make ParseMemorySize() suffix handling case-insensitive (e.g., 512m and 512M behave the same).
  • Add --shm-size and --ulimit to image build and plumb them from CLI args → ImageService → COM options → docker invocation.
  • Add unit tests and e2e/command-line test cases covering memory parsing, nano-cpus parsing, and the new build flags.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/windows/wslc/WSLCCLIArgumentUnitTests.cpp Adds unit tests for case-insensitive memory parsing and nano-cpus parsing.
test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp Adds an e2e test ensuring --shm-size/--ulimit are accepted for image build.
test/windows/wslc/CommandLineTestCases.h Adds CLI parsing test cases for image build --shm-size and --ulimit (including multiple --ulimit).
src/windows/wslcsession/WSLCSession.cpp Appends --shm-size/--ulimit to the in-VM docker build command based on new COM options.
src/windows/wslc/tasks/ImageTasks.cpp Parses CLI args for shm-size/ulimit and passes them into the image build service layer.
src/windows/wslc/services/ImageService.h Extends the ImageService::Build API to accept shm-size and ulimits.
src/windows/wslc/services/ImageService.cpp Marshals shm-size and ulimits into WSLCBuildImageOptions for the COM call.
src/windows/wslc/commands/ImageBuildCommand.cpp Adds ArgType::ShmSize and ArgType::Ulimit to the image build command’s supported args.
src/windows/service/inc/wslc.idl Extends WSLCBuildImageOptions with ShmSize and Ulimits fields.
src/shared/inc/stringshared.h Implements case-insensitive unit suffix matching in ParseMemorySize.

Comment on lines +682 to +684
LONGLONG ShmSize; // Shared memory size in bytes passed as --shm-size to docker. 0 = default.
[unique, size_is(UlimitsCount)] const WSLCUlimit* Ulimits;
ULONG UlimitsCount;
Comment on lines +877 to +881
if (Options->ShmSize > 0)
{
buildArgs.push_back("--shm-size");
buildArgs.push_back(std::to_string(Options->ShmSize));
}
Comment on lines +885 to +887
RETURN_HR_IF_NULL(E_INVALIDARG, Options->Ulimits);
RETURN_HR_IF_NULL(E_INVALIDARG, Options->Ulimits[i].Name);
buildArgs.push_back("--ulimit");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants