File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -127,6 +127,13 @@ def build(
127127 None ,
128128 help = "Docker build argument in the format 'KEY=VALUE' (can be used multiple times)" ,
129129 ),
130+ cache : bool = typer .Option (
131+ False ,
132+ "--cache/--no-cache" ,
133+ help = "Whether to use the build cache. Defaults to off so a stale cached layer "
134+ "can't silently ship source that no longer matches the checkout (notably when "
135+ "republishing a moving tag like ':latest'). Pass --cache to opt back in." ,
136+ ),
130137):
131138 """
132139 Build an agent image locally from the given manifest.
@@ -155,6 +162,7 @@ def build(
155162 secret = secret or "" , # Provide default empty string
156163 tag = tag or "latest" , # Provide default
157164 build_args = build_arg or [], # Provide default empty list
165+ cache = cache ,
158166 )
159167 if image_url :
160168 typer .echo (f"Successfully built image: { image_url } " )
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ def build_agent(
3939 secret : str | None = None ,
4040 tag : str | None = None ,
4141 build_args : list [str ] | None = None ,
42+ cache : bool = False ,
4243) -> str :
4344 """Build the agent locally and optionally push to registry
4445
@@ -49,6 +50,10 @@ def build_agent(
4950 secret: Docker build secret in format 'id=secret-id,src=path-to-secret-file'
5051 tag: Image tag to use (defaults to 'latest')
5152 build_args: List of Docker build arguments in format 'KEY=VALUE'
53+ cache: Whether to use the build cache. Defaults to False (passes --no-cache to
54+ buildx) so a stale cached layer can't silently ship source that no longer
55+ matches the checkout, notably when republishing a moving tag like ':latest'.
56+ Pass True to opt back in for faster local rebuilds.
5257
5358 Returns:
5459 The image URL
@@ -85,7 +90,10 @@ def build_agent(
8590 "file" : str (build_context .path / build_context .dockerfile_path ), # type: ignore[operator]
8691 "tags" : [image_name ],
8792 "platforms" : platforms ,
93+ "cache" : cache , # cache=False -> `docker buildx build --no-cache`
8894 }
95+ if not cache :
96+ logger .info ("Build cache disabled (--no-cache)" )
8997
9098 # Add Docker build args if provided
9199 if build_args :
You can’t perform that action at this time.
0 commit comments