Skip to content

Commit

Permalink
- Build appimage with ubuntu18.04 and python3.11
Browse files Browse the repository at this point in the history
- git/dockerignore appimage-build directory
- Add instruction for creating appimage in COMPILING.md
  • Loading branch information
laggykiller committed Jul 15, 2023
1 parent 23ab5f2 commit 010dfea
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 37 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
AppDir/**
appimage-build/**
build/**
dist/**
magick-src/**
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
- os: ubuntu-20.04
TARGET: linux
CMD_BUILD: |
apt install -y libpng-dev libxft-dev libfontconfig1-dev libfreetype6-dev
wget -O appimage-builder https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.1.0/appimage-builder-1.1.0-x86_64.AppImage
chmod +x ./appimage-builder
./appimage-builder
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ magick-src/**
*.exe
*.dll
AppDir/**
appimage-build/**
creds.json
bzcmp
bzdiff
Expand Down
121 changes: 85 additions & 36 deletions AppImageBuilder.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# appimage-builder recipe see https://appimage-builder.readthedocs.io for details
# Builds on ubuntu20, python3.8
# Builds on ubuntu 18.04
version: 1
script:
# Remove any previous build
Expand All @@ -10,17 +10,53 @@ script:
- mkdir -p AppDir/usr/share/icons/hicolor/256x256/apps/
- mkdir -p AppDir/usr/bin

# Copy the python application code into the AppDir
- rsync -av sticker_convert/ AppDir/usr/src --exclude bin --exclude ImageMagick --exclude __pycache__ --exclude stickers_input --exclude stickers_output --exclude creds.json
# Copy appicon
- cp ./sticker_convert/resources/appicon.png AppDir/usr/share/icons/hicolor/256x256/apps/sticker-convert.png
# Download python appimage
- curl -o python.appimage -L https://github.com/niess/python-appimage/releases/download/python3.11/python3.11.4-cp311-cp311-manylinux2014_x86_64.AppImage
- chmod +x ./python.appimage
- ./python.appimage --appimage-extract
- mv ./squashfs-root/opt/python3.11/* ./AppDir/usr
- mv ./squashfs-root/usr/lib/* ./AppDir/usr/lib
- rm -rf ./squashfs-root/usr/share/icons
- mv ./squashfs-root/usr/share/* ./AppDir/usr/share
- rm -rf ./squashfs-root
- rm ./python.appimage

# Install ttkbootstrap v1.5.1 instead to avoid _tkinter.TclError: invalid command name "::msgcat::mcmset"
- cp requirements.txt requirements-appimage.txt
- sed -i 's/ttkbootstrap.git/ttkbootstrap.git@v1.5.1-patched/g' requirements-appimage.txt
# Install application dependencies
# NOTE: May need to add --system flag
- python3.8 -m pip install --ignore-installed --prefix=/usr --root=AppDir -r ./requirements-appimage.txt
# Create python3 symlink
- cd ./AppDir/usr/bin
- ln -s ./python3.11 ./python3
- ln -s ./python3.11 ./python
- cd ../../../

# appimage's libtk not built against freetype, causing font in ttkbootstrap not work
# Hence need to replace libtk8.6.so that is compiled against freetype
# Run `apt-get install libxft-dev libfontconfig1-dev libfreetype6-dev` before creating appimage!
# libtk version should match the version provided in appimage
# Reference 1: https://stackoverflow.com/a/47787749
# Reference 2: https://github.com/ContinuumIO/anaconda-issues/issues/776#issuecomment-351359489
- curl -o tcl-src.zip -L http://prdownloads.sourceforge.net/tcl/tcl8613-src.zip
- curl -o tk-src.zip -L http://prdownloads.sourceforge.net/tcl/tk8613-src.zip
- mkdir libtcl
- unzip tcl-src.zip
- cd tcl8.6.13/unix
- ./configure --prefix=$(pwd)/../../libtcl
- make
- make install
- cd ../../
- mkdir libtk
- unzip tk-src.zip
- cd tk8.6.13/unix
- ./configure --prefix=$(pwd)/../../libtk --with-tcl=$(pwd)/../../tcl8.6.13/unix
- make
- make install
- cd ../../
- rm AppDir/usr/lib/libtk8.6.so
- cp libtk/lib/libtk8.6.so AppDir/usr/lib
- rm -rf ./libtk
- rm -rf ./libtcl
- rm -rf ./tcl8.6.13
- rm -rf ./tk8.6.13
- rm ./tcl-src.zip
- rm ./tk-src.zip

# Download ImageMagick AppImage
- curl -o magick -L https://github.com/ImageMagick/ImageMagick/releases/latest/download/ImageMagick--gcc-x86_64.AppImage
Expand Down Expand Up @@ -53,6 +89,16 @@ script:
- rm -rf ./pngnq-s9-2.0.2
- rm ./2.0.2.tar.gz

# Compile apngdis
- mkdir apngdis
- cd apngdis
- curl -O -L https://sourceforge.net/projects/apngdis/files/2.9/apngdis-2.9-src.zip
- unzip apngdis-2.9-src.zip
- make
- cd ../
- cp ./apngdis/apngdis AppDir/usr/bin
- rm -rf ./apngdis

# Compile pngquant as current version does not have '--strip' option
- rm -rf pngquant | true
- git clone --recursive --branch 2.17.0 https://github.com/kornelski/pngquant.git
Expand All @@ -62,6 +108,19 @@ script:
- cp ./pngquant/target/release/pngquant AppDir/usr/bin
- rm -rf ./pngquant

# Copy the python application code into the AppDir
- rsync -av sticker_convert/ AppDir/usr/src --exclude bin --exclude ImageMagick --exclude __pycache__ --exclude stickers_input --exclude stickers_output --exclude creds.json
# Copy appicon
- cp ./sticker_convert/resources/appicon.png AppDir/usr/share/icons/hicolor/256x256/apps/sticker-convert.png

# Install ttkbootstrap v1.5.1 instead to avoid _tkinter.TclError: invalid command name "::msgcat::mcmset"
- cp requirements.txt requirements-appimage.txt
- sed -i 's/ttkbootstrap.git/ttkbootstrap.git@v1.5.1-patched/g' requirements-appimage.txt

# Install pip packages
- AppDir/usr/bin/python3 -m pip install --ignore-installed --prefix=/usr --root=AppDir -r ./requirements-appimage.txt
- AppDir/usr/bin/python3 -m pip install --ignore-installed --prefix=/usr --root=AppDir certifi opencv-python

AppDir:
path: ./AppDir

Expand All @@ -77,33 +136,25 @@ AppDir:
arch: amd64
allow_unauthenticated: true
sources:
- sourceline: deb https://ppa.launchpadcontent.net/zero-tsuki/ppa/ubuntu focal main
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal main restricted
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal universe
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal multiverse
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
- sourceline: deb http://security.ubuntu.com/ubuntu focal-security main restricted
- sourceline: deb http://security.ubuntu.com/ubuntu focal-security universe
- sourceline: deb http://security.ubuntu.com/ubuntu focal-security multiverse
- sourceline: deb https://ppa.launchpadcontent.net/zero-tsuki/ppa/ubuntu bionic main
- sourceline: deb http://archive.ubuntu.com/ubuntu/ bionic main restricted
- sourceline: deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted
- sourceline: deb http://archive.ubuntu.com/ubuntu/ bionic universe
- sourceline: deb http://archive.ubuntu.com/ubuntu/ bionic-updates universe
- sourceline: deb http://archive.ubuntu.com/ubuntu/ bionic multiverse
- sourceline: deb http://archive.ubuntu.com/ubuntu/ bionic-updates multiverse
- sourceline: deb http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse
- sourceline: deb http://security.ubuntu.com/ubuntu bionic-security main restricted
- sourceline: deb http://security.ubuntu.com/ubuntu bionic-security universe
- sourceline: deb http://security.ubuntu.com/ubuntu bionic-security multiverse

include:
- python3
- python3-tk
- python3-opencv
- python3-pkg-resources
- python3-certifi
- python3-distutils
- python3-apt
- binutils
- psmisc
- zip
- unzip
- optipng
- apngdis
- apngasm=3.1.10~139~ubuntu20.04.1
- apngasm=3.1.9~134~ubuntu18.04.1
exclude: []

runtime:
Expand All @@ -113,16 +164,14 @@ AppDir:
PYTHONHOME: '${APPDIR}/usr'
# Path to the site-packages dir or other modules dirs
# See https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH
PYTHONPATH: '${APPDIR}/usr/lib/python3.8/site-packages'
PYTHONPATH: '${APPDIR}/usr/lib/python3.11/site-packages'
# SSL Certificates are placed in a different location for every system therefore we ship our own copy
SSL_CERT_FILE: '${APPDIR}/usr/lib/python3.8/site-packages/certifi/cacert.pem'
SSL_CERT_FILE: '${APPDIR}/usr/lib/python3.11/site-packages/certifi/cacert.pem'
# Tcl library has to be specified or else cannot find init.tcl
TCL_LIBRARY: '${APPDIR}/usr/share/tcltk/tcl8.6'

files:
include:
- /usr/local/bin/pngquant
- /usr/local/bin/pngnq-s9
include: []
exclude:
- usr/share/man
- usr/share/doc/*/README.*
Expand Down
15 changes: 14 additions & 1 deletion docs/COMPILING.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ For MacOS, the following binaries are required:
- Easiest method is download from Homebrew `brew install apngasm`
- Note that version 3 is required. Sourceforge only provides up to version 2.

## 3.3 Executables / Binaries (Linux) (Tested with Ubuntu 20.04)
## 3.3 Execute script directly (Linux) (Tested with Ubuntu 20.04)
Some packages are usually not available in repo. To compile them, install these packages:

`sudo apt install gcc make cmake libpng-dev libboost-program-options-dev libboost-regex-dev libboost-system-dev libboost-filesystem-dev build-essential curl unzip pkg-config python3-tkinter python3-opencv binutils psmisc`
Expand Down Expand Up @@ -145,3 +145,16 @@ This repository uses `pyinstaller` for compiling. Install with `pip3 install pyi
1. Run `python3 get_deps.py` to get dependencies automatically. Please run with sudo.
2. Run `pyinstaller sticker_convert.spec`
3. Compilation result in `dist` directory
## Creating AppImage on Linux
1. Use Ubuntu 18.04 (May work on newer version if you change `sourceline` in `AppImageBuilder.yml`)
2. Install [appimage-builder](https://appimage-builder.readthedocs.io/en/latest/intro/install.html)
```
wget -O appimage-builder-x86_64.AppImage https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.1.0/appimage-builder-1.1.0-x86_64.AppImage
chmod +x appimage-builder-x86_64.AppImage
sudo mv appimage-builder-x86_64.AppImage /usr/local/bin/appimage-builder
```
3. Install dependencies: `sudo apt install curl libpng-dev build-essential pkg-config git cargo libxft-dev libfontconfig1-dev libfreetype6-dev`
4. Clone this repository
5. Run `appimage-builder` inside the directory containing `AppImageBuilder.yml`
6. If successful, `sticker-convert-latest-x86_64.AppImage` should be created

0 comments on commit 010dfea

Please sign in to comment.