Sign inSign up

kkatfish/pyinstaller

By kkatfish

Updated about 2 years ago

Build portable python binaries using Python 3.10.14, Pyinstaller 6.10, and OpenSSL 1.1.1w

Image
Developer tools
0

866

kkatfish/pyinstaller repository overview

Manylinux/Windows Pyinstaller Docker Image

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.

Usage

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>
...

Environment variables

Some behavior can be changed by changing the environment of the container.

KeyDefault valueDescription
REPRO_BUILDyesCreate a reproducible builds⁠ (ie. same python code will generate same binaries).
PLATFORMSlinuxSelect what kind of binaries to produce.
SRCDIR/srcFolder 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_URLhttps://pypi.python.org/simple⁠URL for the pypi index.
SHELL_CMDSRuns 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.
CODESIGN_KEYFILEIf present, it must be a password-protected PFX keyfile with the Authenticode code signing certificate to use to sign the generated Windows executables. Reminder: It must be reachable from the container.
CODESIGN_PASSPassword for the CODESIGN_KEYFILE.
CODESIGN_EXTRACERTOptional extra file in PEM format with the certificate chain to append to the signature. Useful to make certain tools (like signtool.exe) Verify OK.

Using in a Github Action (CI/CD Workflow)

- 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

Tag summary

Content type

Image

Digest

sha256:09769f562

Size

376.6 MB

Last updated

about 2 years ago

docker pull kkatfish/pyinstaller