I have a docker container where I need to run some commands. Usually, I do this manually by running the following commands:
host> docker exec -it my-container bash
container> eval $(ssh-agent)
container> ssh-add ~/.ssh/my-key
<TYPE PASSPHRASE!!!>
container> pytest
I've tried to call docker exec -it from the subprocess, but I couldn't mimic the same behavior as the manual workflow. I can't send commands one by one, as the ssh key is loaded only for the current session, if I run it non-interactively I can't use the key.
I have two problems - I need to type passphrase via stdin (I don't see a way to provide it together with ssh-add), and I want to know when pytest will exit and the return code.
What is the most seamless way to achieve that? I'd prefer to avoid installing additional dependencies, but if it's necessary then I can use something.