diff --git a/.github/dev-requirements.txt b/.github/dev-requirements.txt index 6116de3..c08ad92 100644 --- a/.github/dev-requirements.txt +++ b/.github/dev-requirements.txt @@ -1,4 +1,4 @@ pre-commit -black==23.3.0 +black==25.1.0 isort flake8 diff --git a/.github/workflows/generate.yaml b/.github/workflows/generate.yaml index 2b3e8e0..b546b1a 100644 --- a/.github/workflows/generate.yaml +++ b/.github/workflows/generate.yaml @@ -24,12 +24,12 @@ jobs: - name: Test Basic Guts uses: ./action/manifest with: - image: centos + image: ubuntu - name: Filesystem Include uses: ./action/manifest with: - image: centos + image: ubuntu include: fs generate-recipes: @@ -37,7 +37,7 @@ jobs: strategy: fail-fast: false matrix: - image: ["ubuntu", "centos", "rockylinux:9.0", "alpine", "busybox"] + image: ["ubuntu", "rockylinux:9.0", "alpine", "busybox"] name: Generate Matrix steps: diff --git a/container_guts/main/client.py b/container_guts/main/client.py index 8fc4608..d5a1556 100644 --- a/container_guts/main/client.py +++ b/container_guts/main/client.py @@ -109,6 +109,39 @@ def run(self, image, includes=None): shutil.rmtree(tmpdir, ignore_errors=True) return {image.uri: self.manifests[image.uri]} + @ensure_container + def trace(self, image, paths, cleanup=True): + """ + Find and trace a binary in the container + + Paths must be provided, either the full path or a basename. + """ + print(f"Looking for {len(paths)} path(s) in image") + tmpdir = self.container.export(image, cleanup=False) + + # Results will be lookup with binary path and links + results = {} + for path in paths: + + # We rely on the user to provide something on the path OR a fullpath + links = self.container.execute(image, ["ldd", path]) + if links["return_code"] != 0: + print(links["message"]) + return + links = [ + x.replace("\t", "") for x in links["message"].split("\n") if x.strip() + ] + results[path] = [ + x.split("(")[0].split("=> ")[-1] for x in links if "=>" in x + ] + + if cleanup: + self.container.cleanup(image) + + # Assume that something that isn't linked won't be mapped + shutil.rmtree(tmpdir, ignore_errors=True) + return results + @ensure_container def get_environment_paths(self, image): """ diff --git a/container_guts/version.py b/container_guts/version.py index 94c8e98..4baa54e 100644 --- a/container_guts/version.py +++ b/container_guts/version.py @@ -2,7 +2,7 @@ __copyright__ = "Copyright 2021-2024, Vanessa Sochat" __license__ = "MPL 2.0" -__version__ = "0.0.16" +__version__ = "0.0.17" AUTHOR = "Vanessa Sochat" NAME = "container-guts" EMAIL = "vsoch@users.noreply.github.com"