Skip to content

Commit 5bb9f61

Browse files
authored
feat: add support for trace with ldd (#9)
* feat: add support for trace with ldd * dev: bump black version requirements * remove centos Signed-off-by: vsoch <[email protected]> --------- Signed-off-by: vsoch <[email protected]> Co-authored-by: vsoch <[email protected]>
1 parent 2739d08 commit 5bb9f61

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

.github/dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pre-commit
2-
black==23.3.0
2+
black==25.1.0
33
isort
44
flake8

.github/workflows/generate.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ jobs:
2424
- name: Test Basic Guts
2525
uses: ./action/manifest
2626
with:
27-
image: centos
27+
image: ubuntu
2828

2929
- name: Filesystem Include
3030
uses: ./action/manifest
3131
with:
32-
image: centos
32+
image: ubuntu
3333
include: fs
3434

3535
generate-recipes:
3636
runs-on: ubuntu-latest
3737
strategy:
3838
fail-fast: false
3939
matrix:
40-
image: ["ubuntu", "centos", "rockylinux:9.0", "alpine", "busybox"]
40+
image: ["ubuntu", "rockylinux:9.0", "alpine", "busybox"]
4141

4242
name: Generate Matrix
4343
steps:

container_guts/main/client.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,39 @@ def run(self, image, includes=None):
109109
shutil.rmtree(tmpdir, ignore_errors=True)
110110
return {image.uri: self.manifests[image.uri]}
111111

112+
@ensure_container
113+
def trace(self, image, paths, cleanup=True):
114+
"""
115+
Find and trace a binary in the container
116+
117+
Paths must be provided, either the full path or a basename.
118+
"""
119+
print(f"Looking for {len(paths)} path(s) in image")
120+
tmpdir = self.container.export(image, cleanup=False)
121+
122+
# Results will be lookup with binary path and links
123+
results = {}
124+
for path in paths:
125+
126+
# We rely on the user to provide something on the path OR a fullpath
127+
links = self.container.execute(image, ["ldd", path])
128+
if links["return_code"] != 0:
129+
print(links["message"])
130+
return
131+
links = [
132+
x.replace("\t", "") for x in links["message"].split("\n") if x.strip()
133+
]
134+
results[path] = [
135+
x.split("(")[0].split("=> ")[-1] for x in links if "=>" in x
136+
]
137+
138+
if cleanup:
139+
self.container.cleanup(image)
140+
141+
# Assume that something that isn't linked won't be mapped
142+
shutil.rmtree(tmpdir, ignore_errors=True)
143+
return results
144+
112145
@ensure_container
113146
def get_environment_paths(self, image):
114147
"""

container_guts/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__copyright__ = "Copyright 2021-2024, Vanessa Sochat"
33
__license__ = "MPL 2.0"
44

5-
__version__ = "0.0.16"
5+
__version__ = "0.0.17"
66
AUTHOR = "Vanessa Sochat"
77
NAME = "container-guts"
88

0 commit comments

Comments
 (0)