CLI: Add --shm-size and --ulimit to image build; case-insensitive memory parsing#40838
Draft
dkbennett wants to merge 6 commits into
Draft
CLI: Add --shm-size and --ulimit to image build; case-insensitive memory parsing#40838dkbennett wants to merge 6 commits into
dkbennett wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
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.,512mand512Mbehave the same). - Add
--shm-sizeand--ulimittoimage buildand 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"); |
…crosoft/WSL into user/dkbennett/buildmemorycpu # Conflicts: # test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed