Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to prevent any output from docker-compose up, build etc? #292

Open
lodif opened this issue Dec 28, 2021 · 10 comments · Fixed by #364
Open

Is there a way to prevent any output from docker-compose up, build etc? #292

lodif opened this issue Dec 28, 2021 · 10 comments · Fixed by #364
Labels
enhancement New feature or request

Comments

@lodif
Copy link

lodif commented Dec 28, 2021

As the title suggests, I would like to prevent any output from python-on-whales.
Is there a way to do it?

Thanks!

@gabrieldemarmiesse
Copy link
Owner

Currently it's only available on some commands. For exemple docker.buildx.build. I'll work on improving this area :)

@gabrieldemarmiesse
Copy link
Owner

Just for my personal curiosity and also to better satisfy the request, could you tell me what's your use case? What you use python-on-whales for and why you want to supress the output?

@gabrieldemarmiesse gabrieldemarmiesse added the enhancement New feature or request label Jan 6, 2022
@lodif
Copy link
Author

lodif commented Jan 22, 2022

Sorry for the delay.
It was for a univeristy project where I had to trigger many times different docker-compose files.
The CLI had a custom progress bar to show the status of the application and for this reason was better to prevent any other log.
Anyway we were able to use subprocess to do that.
Feel free to close this issue and thanks for your great work!

@gabrieldemarmiesse
Copy link
Owner

Thanks! I believe your use case is valid and should be in the scope of python-on-whales. I'll see what's the best way to implement it, so that the interface is intuitive!

@sj-lt
Copy link

sj-lt commented Aug 17, 2022

Hi,
Dunno if should open another issue but problem is related somehow.
For my use case there is on contrary no enough output for docker compose commands.
For example when i use docker.compose.up() or pull() there is no output at all while building or downloading images.
Got some digging and it looks like docker compose is directing this output to stderr related compose issue .
I am using your library for some startup script and like it a lot.
But at first run is little sad to see nothing while 10 images are being pulled, looks kinda stuck.
Maybe there should be some flag to prevent piping/capturing std/stderr or some more control over it.
Cheers.

@gabrieldemarmiesse
Copy link
Owner

Thank you, this is great feedback, I'll look into it :)

@gabrieldemarmiesse
Copy link
Owner

After this last PR is merged, docker.compose up, build and pull will all have a quiet flag, off by default, and I ensured everything was displayed on the screen when the flag is off. With this I think we can close this issue :)

@sj-lt
Copy link

sj-lt commented Aug 23, 2022

Thanks for implementation that works great now for starting but there is still no output when using down command. Forgot to mention it in previous comment ;/

@gabrieldemarmiesse
Copy link
Owner

Thanks for the report! I'll fix it

@baptistecolle
Copy link

baptistecolle commented Nov 14, 2023

It seems that it is not possible to capture the stdout of the methods. Indeed, the stdout or stderr is not inherited from the main thread. Is there a way to capture the output of the commands?

Code:

sys.stdout = open(os.devnull, "w")
sys.stderr = open(os.devnull, "w")

print("This will not be printed")

self.docker_old.login(registry=server, username=username, password=password)

sys.stdout = old_stdout
sys.stderr = old_stderr

print("This will be printed")

Expected Behaviour:

This will be printed

Actual Behaviour

Login Succeeded
This will be printed

The only solution to this issue that I found is this, but this seems more like a hack. Indeed, exceptions that are raised in the subprocess are not propagated to the main thread with this hack.

import subprocess

proc = subprocess.Popen(["python", "-c", f"from python_on_whales import DockerClient; docker = DockerClient(); docker.login(server='{server}', username='{username}', password='{password}')"], stdout=subprocess.PIPE)
out = proc.communicate()[0]

I also tested the behaviour of docker-py package and they do not output "Login Succeeded"

I was wondering if there was a better way to capture the output of python_on_whales methods or silence them if needed (--quiet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
4 participants