I’m working on a python agent which I want to run natively on various environments (basically different docker images but not necessarily). But I really have no idea how things work in this low level area.
I compiled the project using pyinstaller and it runs successfully on my machine. On the docs, it is written that I should compile the project on the machine I want to run it on, but I do want to prepare various versions for the executable so it’ll be able to run on them in advance, but I don’t know what are the criteria I need to take into consideration.
If I want to run the agent on various docker images, what are the specs I need to pay attention to? Architecture? OS? GCC version? Base image?
What is the best way to compile as many binaries as possible to support various docker images?
If I compile the project on alpine image, for example, does it mean it will run on all docker images based on alpine?
Any advice is welcomed.
Thanks!
If you just have a Python script, that script on its own is (probably) portable, and can run on any system on any OS on any architecture that has a Python interpreter. This isn't a difficult requirement -- both Linux and MacOS systems generally come with Python preinstalled -- and if portability is important to you, I'd try to stay as close to a pure-Python environment as you can.
Once you've brought Pyinstaller into the picture, you've created a non-portable binary artifact. You'll need to re-run Pyinstaller on each different OS and each different architecture you want to run it on (Linux/x86, Linux/ARM, MacOS/x86, MacOS/ARM, Windows/x86, and probably separate musl [Alpine] vs. glibc [Debian] builds on Linux). There aren't really any shortcuts around this.
In principle Docker looks like it can simplify this by running everything under Linux. You still need to create separate x86 and ARM artifacts. Once it's embedded in a Docker image, you wouldn't need to create separate builds for different Linux distributions, you would just need to run the precompiled image. But, the host would need to have Docker installed (which it almost certainly won't by default), and depending on what exactly your agent is reporting on, it could be hampered by running in an isolated environment (in a Linux VM on non-Linux hosts).