Add cross-platform support for running commands in Docker
See original GitHub issueProblem to be solved
testinfra
docker backend should support the Windows Docker container platform testing in addition to the existing Linux functionality.
Currently, only Linux containers can be executed as a backend. This issues the lack of support for running Windows container backends.
Suggested Approach
Currently, if we look at backend/docker.py the implementation of the docker exec
command is fixed using /bin/sh. This needs to be extendable for other platforms as e.g. powershell or others.
The suggested approach would be encapsulating the docker command as function, similar as this:
def docker_command(self, terminal, command):
command_items = []
if self.user is None:
command_items = ["docker exec", "-u", self.name, terminal, "-c", command]
else:
command_items = ["docker exec", "-u", user, "-u", name, terminal, "-c", command]
return " ".join(command_items)
def run(self, command, *args, **kwargs):
cmd = self.get_command(command, *args)
out = self.run_local(
docker_command(self.user, self.name, terminal, cmd))
out.command = self.encode(cmd)
return out
This also requires updating the implementation of backend/base.py to be extendable in a similar fashion.
@philpep Let me know what you think, if this makes sense to you. I will add the PR introducing the suggested functionality.
See following Issues to similar problems:
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
I would not oppose adding support for Windows as github allows testing with Windows hosts but keep in mind: as far as I know none of the core developers is using Windows so you will be on your own.
I would personally not mind helping with reviews. Start by enabling one windows target on github pipeline and start adding fixes there.
Feel free to add Windows support but don’t bother creating bugs for it, at least until we get the same level of coverage on CI.
In case it is of use to anyone, we’re just using this to use
bash
as the shell, instead of the hardcodedsh
on thehost.run
for docker backend:https://github.com/pi-hole/pi-hole/commit/79c3de0d576e80257fca3649f39cc2d86a5ea70f
Not Ideal, but the scripts we’re testing require
bash
(until we get around to converting them to remove bashisms… one day maybe)