docker-assemble 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: docker-assemble
3
+ Version: 0.1.0
4
+ Summary: A CLI tool to extract and analyze Docker images
5
+ Author: Sina Kashipazha
6
+ License: Apache-2.0
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: docker>=6.0.0
10
+
11
+ # docker-assemble
12
+
13
+ A CLI tool to extract and analyze Docker images for research & optimization purposes.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install docker-assemble
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```bash
24
+ docker-assemble -d ubuntu:20.04 output_dir
25
+ ```
@@ -0,0 +1,15 @@
1
+ # docker-assemble
2
+
3
+ A CLI tool to extract and analyze Docker images for research & optimization purposes.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install docker-assemble
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ docker-assemble -d ubuntu:20.04 output_dir
15
+ ```
File without changes
@@ -0,0 +1,5 @@
1
+ import docker
2
+
3
+ def list_docker_images():
4
+ client = docker.from_env()
5
+ return client.images.list()
@@ -0,0 +1,68 @@
1
+ import docker
2
+ import tarfile
3
+ import tempfile
4
+ import os
5
+ import shutil
6
+ from pathlib import Path
7
+ import logging
8
+
9
+ def extract_image(image_name: str, output_dir: str):
10
+ client = docker.from_env()
11
+
12
+ try:
13
+ image = client.images.get(image_name)
14
+ logging.info(f"Image '{image_name}' found locally.")
15
+ except docker.errors.ImageNotFound:
16
+ logging.info(f"Image '{image_name}' not found locally. Pulling...")
17
+ image = client.images.pull(image_name)
18
+
19
+ container = client.containers.run(image=image_name, command="sleep infinity", detach=True)
20
+ logging.debug(f"Created temporary container: {container.id[:12]}")
21
+
22
+ try:
23
+ stream, _ = container.get_archive("/")
24
+ tmp_tar_path = tempfile.mktemp(suffix=".tar")
25
+ with open(tmp_tar_path, "wb") as f:
26
+ for chunk in stream:
27
+ f.write(chunk)
28
+
29
+ logging.debug(f"Filesystem archive saved to: {tmp_tar_path}")
30
+
31
+ output_path = Path(output_dir).resolve()
32
+ output_path.mkdir(parents=True, exist_ok=True)
33
+
34
+ extract_tar_safely(tmp_tar_path, output_path)
35
+
36
+ logging.info(f"Image filesystem extracted to: {output_path}")
37
+
38
+ finally:
39
+ container.remove(force=True)
40
+ if os.path.exists(tmp_tar_path):
41
+ os.remove(tmp_tar_path)
42
+ logging.debug("Cleaned up temporary container and tar file.")
43
+
44
+
45
+ def extract_tar_safely(tar_path: str, output_path: Path):
46
+ # def is_safe_path(base: Path, target: Path) -> bool:
47
+ # try:
48
+ # return target.resolve().is_relative_to(base.resolve())
49
+ # except AttributeError:
50
+ # # For Python < 3.9 fallback
51
+ # return str(target.resolve()).startswith(str(base.resolve()))
52
+
53
+ with tarfile.open(tar_path, "r") as tar:
54
+ for member in tar.getmembers():
55
+ member.name = member.name.lstrip("/")
56
+ member_path = output_path / member.name
57
+
58
+ # if not is_safe_path(output_path, member_path):
59
+ # logging.warning(f"Blocked unsafe path: {member.name}, output_path: {output_path}, member_path: {member_path}")
60
+ # continue
61
+
62
+ tar.extract(member, path=output_path)
63
+ logging.debug(f"Extracted: {member.name}")
64
+
65
+ logging.info(f"Extraction completed to: {output_path}")
66
+
67
+
68
+
@@ -0,0 +1,18 @@
1
+ import argparse
2
+ import logging
3
+ import os
4
+ from docker_assemble.image_exporter import extract_image
5
+
6
+ def run():
7
+ parser = argparse.ArgumentParser(description="Docker Assemble CLI")
8
+ parser.add_argument("-d", action="store_true", help="Disassemble an image")
9
+ parser.add_argument("--debug", action="store_true", help="Enable debug mode")
10
+ parser.add_argument("image", help="Docker image name")
11
+ parser.add_argument("output_dir", nargs="?", default=".", help="Optional output directory")
12
+
13
+ args = parser.parse_args()
14
+
15
+ logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
16
+
17
+ logging.debug(f"Extracting image: {args.image} to directory: {args.output_dir}")
18
+ extract_image(image_name=args.image, output_dir=args.output_dir)
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: docker-assemble
3
+ Version: 0.1.0
4
+ Summary: A CLI tool to extract and analyze Docker images
5
+ Author: Sina Kashipazha
6
+ License: Apache-2.0
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: docker>=6.0.0
10
+
11
+ # docker-assemble
12
+
13
+ A CLI tool to extract and analyze Docker images for research & optimization purposes.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install docker-assemble
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```bash
24
+ docker-assemble -d ubuntu:20.04 output_dir
25
+ ```
@@ -0,0 +1,13 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ docker_assemble/__init__.py
5
+ docker_assemble/docker_utils.py
6
+ docker_assemble/image_exporter.py
7
+ docker_assemble/main.py
8
+ docker_assemble.egg-info/PKG-INFO
9
+ docker_assemble.egg-info/SOURCES.txt
10
+ docker_assemble.egg-info/dependency_links.txt
11
+ docker_assemble.egg-info/entry_points.txt
12
+ docker_assemble.egg-info/requires.txt
13
+ docker_assemble.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ docker-assemble = docker_assemble.main:run
@@ -0,0 +1 @@
1
+ docker>=6.0.0
@@ -0,0 +1 @@
1
+ docker_assemble
@@ -0,0 +1,18 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "docker-assemble"
7
+ version = "0.1.0"
8
+ description = "A CLI tool to extract and analyze Docker images"
9
+ readme = "README.md"
10
+ authors = [{ name = "Sina Kashipazha"}]
11
+ license = { text = "Apache-2.0" }
12
+ requires-python = ">=3.8"
13
+ dependencies = [
14
+ "docker>=6.0.0"
15
+ ]
16
+
17
+ [project.scripts]
18
+ docker-assemble = "docker_assemble.main:run"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,16 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="docker-assemble",
5
+ version="0.1.0",
6
+ packages=find_packages(),
7
+ install_requires=["docker"],
8
+ entry_points={
9
+ "console_scripts": [
10
+ "docker-assemble=docker_assemble.main:run",
11
+ ],
12
+ },
13
+ license="Apache-2.0",
14
+ author="Sina",
15
+ description="A CLI tool to extract and analyze Docker images",
16
+ )