question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add cross-platform support for running commands in Docker

See original GitHub issue

Problem 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:open
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ssbarneacommented, Nov 19, 2020

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.

0reactions
PromoFauxcommented, Nov 12, 2021

In case it is of use to anyone, we’re just using this to use bash as the shell, instead of the hardcoded sh on the host.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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Faster Multi-Platform Builds: Dockerfile Cross-Compilation ...
In order to add cross-compilation to our Dockerfile, we will use multi-stage builds. The most common pattern to use in multi-stage builds is...
Read more >
Building Multiplatform Container Images the Easy Way
This post will show how with just a little work we were able to create Trow images for both ARM and Intel platforms....
Read more >
How to make docker-compose cross-platform (Mac, Windows ...
I develop using Docker containers on MacOS. While it certainly has its challenges (e.g. performance issues when sharing volumes), it does work.
Read more >
BretFisher/multi-platform-docker-build: Using BuildKit ... - GitHub
First, you'll need to know what platforms your Docker Engine can build. Docker can support multi-platform builds with the buildx command. The README...
Read more >
Customize the Docker extension - Visual Studio Code
The docker-build task builds Docker images using the Docker command line (CLI). The task can be used by itself, or as part of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found