Commit 617a433a authored by Chris Rose's avatar Chris Rose
Browse files

Add Dockerfiles

parent 9312bcfa
Loading
Loading
Loading
Loading

README.md

0 → 100644
+62 −0
Original line number Diff line number Diff line
# PyInstaller Docker Images

**cdrx/pyinstaller-linux** and **cdrx/pyinstaller-windows** are a pair of Docker containers to ease compiling Python applications to binaries / exe files.

Current PyInstaller version used: 3.2.

## Tags

`cdrx/pyinstaller-linux` has two tags, `:python2` and `:python3` which you can use depending on the requirements of your Project. `:latest` points to `:python3`

`cdrx/pyinstaller-windows` currently only has a `:python2` tag because the Python 3.5 Windows installer doesn't work under Wine (yet).

## Usage

There are two containers, one for Linux and one for Windows builds. The Windows builder runs Wine inside Ubuntu to emulate Windows in Docker.

To build your application, you need to mount your source code into the `/src/` volume.

The source code directory should have your `.spec` file that PyInstaller generates. If you don't have one, you'll need to run PyInstaller once locally to generate it.

If the `src` folder has a `requirements.txt` file, the packages will be installed into the environment before PyInstaller runs.

For example, in the folder that has your source code, `.spec` file and `requirements.txt`:

```
docker run -v "$(pwd):/src/" cdrx/pyinstaller-windows
```

will build your PyInstaller project into `dist/windows/`. The `.exe` file will have the same name as your `.spec` file.

```
docker run -v "$(pwd):/src/" cdrx/pyinstaller-linux
```

will build your PyInstaller project into `dist/linux/`. The binary will have the same name as your `.spec` file.

##### How do I install system libraries or dependencies that my Python packages need?

You'll need to supply a custom command to Docker to install system pacakges. Something like:

```
docker run -v "$(pwd):/src/" cdrx/pyinstaller-linux sh -c "apt-get update -y && apt-get install -y wget && pip install -r requirements.txt && pyinstaller --clean -y --dist ./dist/linux --workpath /tmp *.spec"
```

Replace `wget` with the dependencies / package(s) you need to install.

##### How do I change the PyInstaller version used?

Add `pyinstaller=3.1.1` to your `requirements.txt`.

## Known Issues

There is currently no `cdrx/pyinstaller-windows:python3` image because the Python 3.5 installer doesn't work under Wine. The `cdrx/pyinstaller-windows:python2` tag works.

## History

#### [1.0] - 2016-08-26
First release, works.

## License

MIT

build.sh

0 → 100755
+17 −0
Original line number Diff line number Diff line
#!/bin/bash
set -x

docker build -t cdrx/pyinstaller-windows:python2 -f ./windows/py2/Dockerfile ./windows/py2
#docker build -t cdrx/pyinstaller-windows:python3 -f ./windows/py3/Dockerfile ./windows/py3

docker build -t cdrx/pyinstaller-linux:python2 -f ./linux/py2/Dockerfile ./linux/py2
docker build -t cdrx/pyinstaller-linux:python3 -f ./linux/py3/Dockerfile ./linux/py3

docker push cdrx/pyinstaller-windows
docker push cdrx/pyinstaller-linux

docker tag cdrx/pyinstaller-linux:python3 cdrx/pyinstaller-linux:latest
docker push cdrx/pyinstaller-linux:latest

docker tag cdrx/pyinstaller-windows:python2 cdrx/pyinstaller-windows:latest
docker push cdrx/pyinstaller-windows:latest

linux/py2/Dockerfile

0 → 100644
+20 −0
Original line number Diff line number Diff line
FROM ubuntu:14.04

ENV DEBIAN_FRONTEND noninteractive

ARG PYINSTALLER_VERSION=3.2

# install python
RUN set -x \
    && apt-get update -qy \
    && apt-get install --no-install-recommends -qfy python python-dev python-pip python-setuptools build-essential libmysqlclient-dev \
    && apt-get clean

# install pyinstaller
RUN pip install pyinstaller==$PYINSTALLER_VERSION

RUN mkdir /src/
VOLUME /src/
WORKDIR /src/

CMD pip install -r requirements.txt && pyinstaller --clean -y --dist ./dist/linux --workpath /tmp *.spec

linux/py3/Dockerfile

0 → 100644
+21 −0
Original line number Diff line number Diff line
FROM ubuntu:16.04

ENV DEBIAN_FRONTEND noninteractive

ARG PYINSTALLER_VERSION=3.2

# install python
RUN set -x \
    && apt-get update -qy \
    && apt-get install --no-install-recommends -qfy python3 python3-dev python3-pip python3-setuptools python3-wheel build-essential libmysqlclient-dev \
    && apt-get clean

# install pyinstaller
RUN pip3 install pyinstaller==$PYINSTALLER_VERSION
RUN ln -s /usr/bin/pip3 /usr/bin/pip

RUN mkdir /src/
VOLUME /src/
WORKDIR /src/

CMD pip install -r requirements.txt && pyinstaller --clean -y --dist ./dist/linux --workpath /tmp *.spec

windows/py2/Dockerfile

0 → 100644
+48 −0
Original line number Diff line number Diff line
FROM ubuntu:14.04

ENV DEBIAN_FRONTEND noninteractive

ARG WINE_VERSION=winehq-devel
ARG PYTHON_VERSION=2.7.12
ARG PYINSTALLER_VERSION=3.2

# we need wine for this all to work, so we'll use the PPA
RUN set -x \
    && dpkg --add-architecture i386 \
    && apt-get update -qy \
    && apt-get install --no-install-recommends -qfy software-properties-common \
    && add-apt-repository ppa:wine/wine-builds \
    && apt-get update -qy \
    && apt-get install --no-install-recommends -qfy $WINE_VERSION winetricks wget \
    && apt-get clean

# wine settings
ENV WINEARCH win32
ENV WINEDEBUG fixme-all
ENV WINEPREFIX /wine

# install python inside wine
RUN set -x \
    && wget -nv https://www.python.org/ftp/python/$PYTHON_VERSION/python-$PYTHON_VERSION.msi \
    && wine msiexec /qn /a python-$PYTHON_VERSION.msi \
    && rm python-2.7.12.msi \
    && sed -i 's/_windows_cert_stores = .*/_windows_cert_stores = ("ROOT",)/' "/wine/drive_c/Python27/Lib/ssl.py" \
    && echo 'wine '\''C:\Python27\python.exe'\'' "$@"' > /usr/bin/python \
    && echo 'wine '\''C:\Python27\Scripts\easy_install.exe'\'' "$@"' > /usr/bin/easy_install \
    && echo 'wine '\''C:\Python27\Scripts\pip.exe'\'' "$@"' > /usr/bin/pip \
    && echo 'wine '\''C:\Python27\Scripts\pyinstaller.exe'\'' "$@"' > /usr/bin/pyinstaller \
    && chmod +x /usr/bin/* \
    && wget https://bootstrap.pypa.io/ez_setup.py -O - | /usr/bin/python \
    && /usr/bin/easy_install pip \
    && echo 'assoc .py=PythonScript' | wine cmd \
    && echo 'ftype PythonScript=c:\Python27\python.exe "%1" %*' | wine cmd \
    && while pgrep wineserver >/dev/null; do echo "Waiting for wineserver"; sleep 1; done \
    && rm -rf /tmp/.wine-*

# install pyinstaller
RUN /usr/bin/pip install pyinstaller==$PYINSTALLER_VERSION

VOLUME /wine/drive_c/src/
WORKDIR /wine/drive_c/src/

CMD pip install -r requirements.txt && pyinstaller --clean -y --dist ./dist/windows --workpath /tmp *.spec
Loading