-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add ability to pass docker build params in template #8913
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
base: develop
Are you sure you want to change the base?
Changes from all commits
b39a050
77a3e2e
7c1a4e5
0ca443e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ def build_image( | |
| platform: Optional[str] = None, | ||
| target: Optional[str] = None, | ||
| rm: bool = True, | ||
| extra_params: Optional[list[str]] = None, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [BUG] The This breaks the interface contract: type checkers (mypy) will flag the subclass signatures as incompatible with the abstract method, and developers reading the base class won't know The fix is to add the parameter to the abstract method signature: @abstractmethod
def build_image(
self,
path: str,
dockerfile: str,
tag: str,
buildargs: Optional[Dict[str, str]] = None,
platform: Optional[str] = None,
target: Optional[str] = None,
rm: bool = True,
extra_params: Optional[list[str]] = None,
) -> Generator[Dict[str, Any], None, None]:The docstring for the abstract method (lines 44-67) should also be updated to document the new parameter. |
||
| ) -> Generator[Dict[str, Any], None, None]: | ||
| """ | ||
| Build a container image from a Dockerfile. | ||
|
|
@@ -59,6 +60,8 @@ def build_image( | |
| Build target stage in multi-stage Dockerfile | ||
| rm : bool | ||
| Remove intermediate containers after build (default: True) | ||
| extra_params : list of str, optional | ||
| Extra CLI flags (e.g., ["--ssh", "default"]). Only supported by CLIBuildClient | ||
|
|
||
| Yields | ||
| ------ | ||
|
|
@@ -119,6 +122,7 @@ def build_image( | |
| platform: Optional[str] = None, | ||
| target: Optional[str] = None, | ||
| rm: bool = True, | ||
| extra_params: Optional[list[str]] = None, | ||
| ) -> Generator[Dict[str, Any], None, None]: | ||
| """Build image using docker-py SDK""" | ||
| build_kwargs = { | ||
|
|
@@ -135,6 +139,12 @@ def build_image( | |
| if target is not None: | ||
| build_kwargs["target"] = target | ||
|
|
||
| if extra_params: | ||
| LOG.warning( | ||
| "DockerBuildExtraParams are not supported with the SDK build client and will be ignored. " | ||
| "Use --use-buildkit to enable CLI-based builds." | ||
| ) | ||
|
|
||
| _, build_logs = self.container_client.images.build(**build_kwargs) | ||
| return build_logs # type: ignore[no-any-return] | ||
|
|
||
|
|
@@ -159,6 +169,7 @@ def build_image( | |
| platform: Optional[str] = None, | ||
| target: Optional[str] = None, | ||
| rm: bool = True, | ||
| extra_params: Optional[list[str]] = None, | ||
| ) -> Generator[Dict[str, Any], None, None]: | ||
| # Make dockerfile path relative to context if not absolute | ||
| if not os.path.isabs(dockerfile): | ||
|
|
@@ -187,6 +198,9 @@ def build_image( | |
| if rm: | ||
| cmd.append("--rm") | ||
|
|
||
| if extra_params: | ||
| cmd.extend(extra_params) | ||
|
|
||
| cmd.append(path) | ||
|
|
||
| LOG.debug(f"Executing build command: {' '.join(cmd)}") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[INPUT_VALIDATION]
DockerBuildExtraParamsis read from metadata with no type validation, unlikeDockerBuildArgswhich has an explicitisinstance(docker_build_args, dict)check. If a user provides a non-list value (e.g., a string like"--ssh default"),cmd.extend(extra_params)inCLIBuildClientwould iterate over individual characters, producing broken flags. InSDKBuildClient, the truthiness check would pass and the warning would fire, but the inconsistency would be silently ignored.Add a type check consistent with the existing
DockerBuildArgsvalidation: