Build portable python binaries using Python 3.10.14, Pyinstaller 6.10, and OpenSSL 1.1.1w
866
This container is based on the fydeinc/pyinstaller docker image, which sets an entire build environment based on a very old linux version in a way such that when you build a python binary module on it, it is assured to work on any modern (glibc based) Linux and also Alpine (musl libc based) Linux.
Total props to the Barracuda (fydeinc) team, fantastic image, but the binaries it produces use OpenSSL 1.0.2-fips. For my particular use case, I needed OpenSSL 1.1.1+, so that urllib3 >= 2 won't fail to import. So I built on their work and added support for OpenSSL 1.1.1+ in Python 3.10.
The goal of this project then is to be able to produce single-file binaries for Linux x68-64 that only depend on a very basic (read old) libc.
To build the binary, you need to mount your source code folder into the container in the /src folder and any extra command line argument will be sent to Pyinstaller.
The resulting binaries will be located in dist/linux, dist/alpine, and dist/windows respectively, and a .spec file as used by Pyinstaller will be created. Also, you can provide such .spec file to Pyinstaller instead of a python module and it will follow the instructions from it. Please refer to the Pyinstaller documentation for more information.
If there is a requirements.txt file present at the root of the source code folder it will be installed using pip install before running Pyinstaller. Minimal example
$ echo 'print("Hello World")' > helloworld.py
$ docker run \
-v "$(pwd):/src" \
fydeinc/pyinstaller \
helloworld.py
$ docker run -it -v "$(pwd):/mnt" centos /mnt/dist/linux/helloworld
Hello World
Bit more convoluted
$ echo 'requests' > requirements.txt
$ cat > example.py <<EOF
import requests
print(requests.get("http://example.org").text)
EOF
$ docker run \
-v "$(pwd):/src" \
-e "PLATFORMS=linux" \
fydeinc/pyinstaller \
--name you-can-send-opts-to-pyinstaller \
example.py
$ docker run -it -v "$(pwd):/mnt" centos /mnt/dist/linux/you-can-send-opts-to-pyinstaller
<!doctype html>
<html>
<head>
<title>Example Domain</title>
...
Some behavior can be changed by changing the environment of the container.
| Key | Default value | Description |
|---|---|---|
| REPRO_BUILD | yes | Create a reproducible builds (ie. same python code will generate same binaries). |
| linux | Select what kind of binaries to produce. | |
| SRCDIR | /src | Folder inside the container where the source code is mounted. CI runners might need to change this. (SEE BELOW) |
| PYPI_URL | <pypi.python.org/> | URL for the pypi package repositories, useful if you're using internal package caches. |
| PYPI_INDEX_URL | https://pypi.python.org/simple | URL for the pypi index. |
| SHELL_CMDS | Runs the given shell commands before calling pyinstaller. Useful if you need to change the build environment in some way before building the binaries. You can also use a .spec file for that, since it is a Python script afterall. | |
- name: Compile program with kkatfish/pyinstaller
uses: addnab/docker-run-action@v3
with:
image: kkatfish/pyinstaller:1.0.0
options: --volumes-from=${{ env.JOB_CONTAINER_NAME }}
run: |
export PLATFORMS=linux
export SRCDIR=/workspace/<gh user>/<gh repo>
export SHELL_CMDS="<your commands here>"
/entrypoint.sh "script.py" -n myscript
Content type
Image
Digest
sha256:09769f562…
Size
376.6 MB
Last updated
about 2 years ago
docker pull kkatfish/pyinstaller