Created
February 21, 2024 22:11
-
-
Save WillEngler/75fcf1d1756887c878d2ac2c364dfbb3 to your computer and use it in GitHub Desktop.
Garden debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import docker | |
import json | |
import tarfile | |
import io | |
client = docker.from_env() | |
# PUT YOUR IMAGE HERE | |
my_image_id = "" | |
# Trying to do this without going through stdout | |
file_path = "/garden/metadata.json" | |
container = client.containers.create(my_image_id, command="tail -f /dev/null") | |
container.start() | |
stream, _ = container.get_archive(file_path) | |
# Open the stream as a tar file | |
file_obj = io.BytesIO() | |
for i in stream: | |
file_obj.write(i) | |
file_obj.seek(0) | |
tar = tarfile.open(fileobj=file_obj) | |
member = tar.getmembers()[0] # This is a single file | |
file_contents = tar.extractfile(member).read() | |
print(file_contents) | |
container.stop() | |
container.remove() | |
#return json.loads(file_contents) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment