-
-
Save arpieb/edb6ea64611baaaaec0a26213e0f1e14 to your computer and use it in GitHub Desktop.
################ | |
# Attempt to run Windows scripts in a Docker container (for K8s deployment) | |
# Inspiration/material from: | |
# https://betterprogramming.pub/how-to-run-any-windows-cli-app-in-a-linux-docker-container-318cd49bdd25 | |
################ | |
FROM ubuntu:22.04 | |
# Core system packages | |
RUN apt -y update | |
RUN apt -y install wget | |
# Install Wine stack (https://wiki.winehq.org/Main_Page) | |
# NOTE these repos are platform-version specific | |
ENV WINEDEBUG=fixme-all | |
RUN dpkg --add-architecture i386 && \ | |
mkdir -pm755 /etc/apt/keyrings && \ | |
wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key && \ | |
wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources && \ | |
apt update && \ | |
apt -y install --install-recommends winehq-stable winbind cabextract | |
# Install "dummy" X Server | |
RUN apt install -y xvfb | |
ENV DEBIAN_FRONTEND=noninteractive | |
ENV DISPLAY :1 | |
# Install Mono framework | |
RUN wget -P /mono https://dl.winehq.org/wine/wine-mono/7.4.0/wine-mono-7.4.0-x86.msi && \ | |
wineboot -u && msiexec /i /mono/wine-mono-7.4.0-x86.msi && \ | |
rm -rf /mono/wine-mono-7.4.0-x86.msi | |
# Install Python | |
RUN wget https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe && \ | |
xvfb-run wine64 python-3.8.10-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0 SimpleInstall=1 /nogui && \ | |
rm -f python-3.8.10-amd64.exe |
Thank you so much, I really appreciate your time and effort on this. Without this guidance, I would still probably have nothing.
This wenv
project I did not find during the search, but tried it today and works really well, probably the easiest and cleanest way to have a Windows python interpreter running in Linux.
Unfortunately, as you said, as I'm a masochist, the project I'm currently working on failed as the package requires a path to run the Windows python interpreter. Might get it working changing the config, but the documentation states that
*"wenv will create a special kind of environment __underneath__ the Unix Python virtual environment"*
Maybe tweaking the paths in config I can access the actual path for the interpreter an get it working. Homework, I guess.
The docker-pyinstaller
repo I did find during my search, but then it kept hanging at one of the .msi downloads, and as it looked far more complicated and cumbersome than yours, I was really trying to make your script work. After not getting anywhere with the errors I was getting, I chose to confirm with you if this would work, especially as I had doubts on the setup I have as well.
After your example getting this docker-pyinstaller
a spin, I gave it a go, changing the wget to retry a couple of times before failing and trying again, and it worked!!
I guess I'll finish setting my project on top of this python install in the container, and eventually get back to the wenv
package, just because it looks very good for these use cases.
Again, at least a week of deep frustration avoided, thank you!
Glad you got some traction and I was able to help in some way! My use case was a Python-based script that used pywin32 to load and analyze Windows-only executables, and I was experimenting to see if I could get that to run in an existing k8s cluster on RHEL hosts. I had limited success before the spike was abandoned.
Good luck!
Also ran across this interesting project leveraging embedded Python builds:
https://github.com/pleiszenburg/wenv
ymmv, but another option.