Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7ad6e4

Browse files
authored
feat: Add --no-cache option. (#5)
Forces all layers to be pulled regardless of them being already cached in the file system. Also prevents the layer from being saved into cache when pulling the image (for CI jobs, for example).
1 parent ff02d71 commit f7ad6e4

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

crpy/cmd.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async def _pull(args):
2323
if not filename:
2424
# make file name compatible
2525
filename = ri.repository.replace(":", "_").replace("/", "_")
26-
await ri.pull(filename, args.architecture[0] if args.architecture else None)
26+
await ri.pull(filename, args.architecture[0] if args.architecture else None, not args.no_cache)
2727

2828

2929
async def _push(args):
@@ -173,6 +173,12 @@ def main(*args):
173173
help="Architecture for the to be pulled.",
174174
default=None,
175175
)
176+
pull.add_argument(
177+
"--no-cache",
178+
action="store_true",
179+
help="If should not use the cache when pulling the image.",
180+
default=False,
181+
)
176182
pull.add_argument("url", nargs=1, help="Remote repository to pull from.")
177183
pull.add_argument("filename", nargs="?", help="Output file for the compressed image.")
178184

crpy/registry.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,10 @@ async def get_response_content(self, layer: str, file_obj: Optional[io.BytesIO])
362362
return file_obj.getvalue()
363363

364364
async def pull(
365-
self, output_file: Union[str, pathlib.Path, io.BytesIO], architecture: Union[str, Platform, None] = None
365+
self,
366+
output_file: Union[str, pathlib.Path, io.BytesIO],
367+
architecture: Union[str, Platform, None] = None,
368+
use_cache: bool = True,
366369
):
367370
"""
368371
Pulls an image from a remote repository. The image will be packed into a tar-file and saved to disk (or to a
@@ -372,6 +375,7 @@ async def pull(
372375
:param output_file: path or file-like object to save the binary data.
373376
:param architecture: architecture to pull the image. If not set, the default registry architecture will be
374377
used.
378+
:param use_cache: enables the local cache, saving layers to ~/.crpy/ folder.
375379
:return:
376380
"""
377381
print(f"{self.tag}: Pulling from {self.registry}/{self.repository}")
@@ -382,7 +386,7 @@ async def pull(
382386
for layer in await self.get_layers(architecture):
383387
layer_without_prefix = layer.split(":")[1]
384388
image.layers.append(
385-
Blob.from_any(await self.pull_layer(layer, use_cache=True), digest=layer_without_prefix)
389+
Blob.from_any(await self.pull_layer(layer, use_cache=use_cache), digest=layer_without_prefix)
386390
)
387391
print(f"{layer_without_prefix[0:12]}: Pull complete")
388392
image.to_disk(output_file, tags=[str(self)])

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ authors = [
1111
]
1212
requires-python = ">=3.9.0"
1313
dependencies = [
14-
"requests>=2",
1514
"async-lru>=2",
1615
"aiohttp>=3",
1716
"async-lru>=2",

0 commit comments

Comments
 (0)