Skip to content

Commit

Permalink
Merge pull request #241 from dimagi/cs/SC-3532-windows-exe
Browse files Browse the repository at this point in the history
Generate windows exe and do away with docker pyinstaller image
  • Loading branch information
Charl1996 authored Apr 12, 2024
2 parents f850111 + 6fcbfdd commit 82dde86
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 132 deletions.
41 changes: 34 additions & 7 deletions .github/workflows/release_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,50 @@ on:
types: [published]

jobs:
generate_release_assets:
name: Generate release assets
generate_linux_bin:
name: Generate Linux binary as release asset
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Pull pyinstaller docker image
run: |
docker pull dimagi/commcare-export-pyinstaller-linux
- name: Install pyinstaller
shell: bash
run: python -m pip install pyinstaller

- name: Compile linux binary
- name: Generate exe
shell: bash
run: |
docker run -v "$(pwd):/src/" dimagi/commcare-export-pyinstaller-linux
pip install commcare-export
pip install -r build_exe/requirements.txt
pyinstaller --dist ./dist/linux commcare-export.spec
- name: Upload release assets
uses: AButler/[email protected]
with:
files: "./dist/linux/*"
repo-token: ${{ secrets.GITHUB_TOKEN }}

generate_windows_exe:
name: Generate Windows exe as release asset
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install pyinstaller
shell: pwsh
run: python -m pip install pyinstaller

- name: Generate exe
shell: pwsh
run: |
pip install commcare-export
pip install -r build_exe/requirements.txt
pyinstaller --dist ./dist/windows commcare-export.spec
- name: Upload release assets
uses: AButler/[email protected]
with:
files: "./dist/windows/*"
repo-token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,10 @@ https://pypi.python.org/pypi/commcare-export
https://github.com/dimagi/commcare-export/releases
Once the release is published a GitHub workflow is kicked off that compiles an executable of the DET compatible with
running on a Linux machine (Windows coming soon), adding it as a release asset.
Once the release is published a GitHub workflow is kicked off that compiles executables of the DET compatible with
Linux and Windows machines, adding it to the release as assets.
If you decide to download and use the executable file, please make sure the file has the executable permission enabled,
[For Linux-based users] If you decide to download and use the executable file, please make sure the file has the executable permission enabled,
after which it can be invoked like any other executable though the command line.
Expand Down
62 changes: 13 additions & 49 deletions build_exe/README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,18 @@
# Compiling DET to running executable
This folder contains relevant files needed (dockerfiles and scripts) for compiling the DET into an executable file.
The file structure is segmented into the different operating systems the resultant executable will
be compatible on.
This folder contains relevant files needed for compiling the DET into an executable file.
The executable is generated on after every release of the DET and the resultant files are uploaded
to the release as assets.

(Currently only Linux is supported; Windows coming soon)
## Testing locally
In the event that you want to test the exe compilation locally you can follow the steps below:

Install `pyinstaller`:
> python -m pip install pyinstaller
## How it works
In order to compile the DET script into a working executable we use [pyinstaller](https://github.com/pyinstaller/pyinstaller) in a containerized
environment. The dockerfile is an edited version from [cdrx/docker-pyinstaller](https://github.com/cdrx/docker-pyinstaller)
which is slightly modified to suit our use-case.
Now create the executable (assuming you're running this on a Linux machine):
> pyinstaller --dist ./dist/linux commcare-export.spec
The resultant executable file can be located under `./dist/linux/`.

When a new release of the DET is published, a workflow is triggered which automatically compiles an executable from the latest
code using the custom built docker image, `dimagi/commcare-export-pyinstaller-linux`, then uploads it to the release as an asset.

If you ever have to compile the executable yourself you can follow the section below, *Compiling executable files locally*, on how to compile an executable locally.


Compiling executable files locally
-----------------------------------
The DET executable files are compiled using a tool called [pyinstaller](https://pyinstaller.org/en/stable/).
Pyinstaller is very easy to use, but only works out-of-the-box for Linux as support for cross-compilation was
dropped in earlier releases. Another tool, [wine](https://www.winehq.org/), can be used in conjuction with
pyinstaller to compile the Windows exe files (not yet supported).

Luckily in the world we live containerization is a thing. We use a docker container, `dimagi/commcare-export-pyinstaller-linux`
(based on [docker-pyinstaller](https://github.com/cdrx/docker-pyinstaller)), which allows you to seamlessly compile the Linux binary, so we don't ever have to worry about installing any additional packages ourselves.

To compile a new linux binary, first make sure you have the docker image used to generate the executable:
> docker pull dimagi/commcare-export-pyinstaller-linux:latest
Now it's really as simple as running
> docker run -v "$(pwd):/src/" dimagi/commcare-export-pyinstaller-linux
Once you're done, the compiled file can be located at `./dist/linux/commcare-export`.

The tool needs two files to make the process work:
1. `commcare-export.spec`: this file is used by `pyinstaller` and is already defined and sits at the top of this project.
It shouldn't be necessary for you to change any parameters in the file.
2. `requirements.txt`: this file lists all the necessary packages needed for running commcare-export.


## Updating the docker image
Are you sure you need to update the image?

Just checking...


If it's needed to make any changes (for whatever reason) to the docker image you can rebuild the image as follows:
> docker build -f ./build_exe/linux/Dockerfile-py3-amd64 -t dimagi/commcare-export-pyinstaller-linux:latest .
Now upload the new image to dockerhub (remember to log in to the account first!):
> docker image push dimagi/commcare-export-pyinstaller-linux:latest
The argument, `commcare-export.spec`, is a simple configuration file used by
pyinstaller which you ideally shouldn't have to ever change.
59 changes: 0 additions & 59 deletions build_exe/linux/Dockerfile-py3-amd64

This file was deleted.

14 changes: 0 additions & 14 deletions build_exe/linux/entrypoint-linux.sh

This file was deleted.

0 comments on commit 82dde86

Please sign in to comment.