Skip to content

Commit e18dfff

Browse files
committed
Add list command to ddiff
1 parent 8e65d27 commit e18dfff

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

ddiff.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ def pull_images(tags):
163163
# print_debug("Done.")
164164

165165
def diff_image(base_tag, target_tag):
166+
push_images([base_tag, target_tag])
167+
166168
base_tag = _prepare_tag(base_tag)
167169
target_tag = _prepare_tag(target_tag)
168170
target_repo = target_tag.split(":")[0]
169171

170-
push_images([base_tag, target_tag])
171-
172172
user_dir = os.getcwd()
173173
output_dir = os.path.join(user_dir, ".ddiff-image")
174174
shutil.rmtree(output_dir, ignore_errors=True)
@@ -208,6 +208,7 @@ def diff_image(base_tag, target_tag):
208208

209209
shutil.rmtree(output_dir)
210210
print_debug(f"Done. Load the output image archive {archive_name} in the offline (ddiff load {archive_name})")
211+
print_debug(f"{archive_name}")
211212

212213
def load_image(image_tarball):
213214
input_dir = ".ddiff-image"
@@ -268,8 +269,23 @@ def build_image(build_args):
268269
print_debug(f"Diff image blobs of {target_tag} from {base_tag}")
269270
diff_image(base_tag, target_tag)
270271

272+
def list_blobs(tag):
273+
push_images([tag])
274+
275+
tag = _prepare_tag(tag)
276+
277+
# Download manifest
278+
manifest = _request_manifest(tag)
279+
280+
281+
# Check blobs
282+
blobs = _parse_blob_list(manifest)
283+
print("=== blobs ===")
284+
for blob in blobs:
285+
print(blob.replace("sha256:", ""))
286+
271287
if __name__ == '__main__':
272-
if len(sys.argv) < 2 or not sys.argv[1] in ["server", "push", "pull", "diff", "load", "build"]:
288+
if len(sys.argv) < 2 or not sys.argv[1] in ["server", "push", "pull", "diff", "load", "build", "list"]:
273289
print("Usage: ddiff [command] [args...]")
274290
print("Commands:")
275291
print(" server - Run the registry server")
@@ -278,6 +294,7 @@ def build_image(build_args):
278294
print(" diff <base> <target> - Diff the target image from the base image")
279295
print(" load <tar file> - Load the target image from diff file")
280296
print(" build <args> - Build the image and diff from base (FROM ...)")
297+
print(" list <tag> - List up blobs of the given image")
281298
sys.exit(1)
282299

283300
command = sys.argv[1]
@@ -313,5 +330,9 @@ def build_image(build_args):
313330
print("Usage: python3 ddiff.py build <docker build args>")
314331
sys.exit(1)
315332
build_image(args)
316-
333+
elif command == "list":
334+
if len(args) != 1:
335+
print("Usage: python3 ddiff.py list <tag>")
336+
sys.exit(1)
337+
list_blobs(args[0])
317338

0 commit comments

Comments
 (0)