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

Allow docker stack deploy from stdin #581

Open
derfl0 opened this issue Apr 25, 2024 · 2 comments
Open

Allow docker stack deploy from stdin #581

derfl0 opened this issue Apr 25, 2024 · 2 comments

Comments

@derfl0
Copy link

derfl0 commented Apr 25, 2024

Hey, thank you for this great project. I am currently trying to replace subprocess calls in my code by your lib. I have some logic in the stack template and therefore need to heavily modify it according to my needs.

Since v1.25 it is possible to read the compose.yml from stdin (See: https://docs.docker.com/reference/cli/docker/stack/deploy/ ) which I use to read from a modified string.

Is it possible to implement this option in the lib as well?

@gabrieldemarmiesse
Copy link
Owner

Hi @derfl0 sorry for the delay, I've been busy with other things.

Currently python-on-whales doesn't support this. I would be happy to support it in the future. Though reading from stdin in python doesn't make much sense (it makes sense in a CLI).

What I would propose is that we find a good name for a new argument to this function: https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/stack/#python_on_whales.components.stack.cli_wrapper.StackCLI.deploy and this argument would take a string as input. Inside the string would be the yaml of your stack. Would that work for you?

@derfl0
Copy link
Author

derfl0 commented May 23, 2024

Hey @gabrieldemarmiesse , no need to apologise as you work free of charge ;)

the proposed solution is exactly what I would need.

Talking about Stdin: Having a communication interface with the subprocess below would be awesome. Currently, in my native approach, I use the communicate method ( https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate )
Background: I use a mysql server and create databases on demand via a separate mysql client container. This involves a lot of very ugly escaping if it must be a one-line start parameter. It is way easier, if you just start the container and then use "communicate" to execute your commands one by one. Of course this does only work for local containers as swarm does not support exec on service/task. I can also open a different issue for this, if it is feature material.

# pseudo example
with docker.run("mysql", detach=True) as mysql_container:
    print(mysql_container.communicate("show databases;"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants