From 40747c964fe88f69fbdd146c1754bcdb035a9d81 Mon Sep 17 00:00:00 2001 From: Nemuel Wainaina Date: Mon, 25 Nov 2024 10:13:42 +0300 Subject: [PATCH] Polish the AppImage build process --- .github/workflows/ci.yml | 68 ++++++++++++++++++---------------------- .gitignore | 1 + Dockerfile | 27 ++++++++++++++-- 3 files changed, 56 insertions(+), 40 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d28d55..0a94213 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,65 +20,57 @@ jobs: - name: Install dependencies run: | - pip3 install flake8 + pip install flake8 - name: Run flake8 run: | flake8 . - multiarch-build: + build: runs-on: ubuntu-latest - strategy: - matrix: - arch: [amd64, arm64] steps: + - name: Install dependencies + run: | + sudo apt-get install -y desktop-file-utils + - name: Checkout repository uses: actions/checkout@v3 + with: + fetch-depth: 0 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build Docker image + - name: Set clean version variable run: | - docker build --platform linux/${{ matrix.arch }} -t protodesk . - - - name: Run Docker image + VERSION=$(git describe --tags) + APP_VERSION=${VERSION#v} + echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV + + - name: Set up python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + + - name: Install project dependencies run: | - docker run --name protodesk-container protodesk + pip install -r requirements.txt - - name: Copy build from container to host + - name: Build the app with Nuitka run: | - docker cp protodesk-container:/app/protodesk . + nuitka --enable-plugin=pyside6 --include-data-dir=./assets=./assets --standalone --onefile --lto=yes --output-filename=protodesk app.py - - name: Prepare AppImage directory + - name: Prepare AppImage contents run: | mkdir -p app.AppDir/usr/bin - cp ./protodesk app.AppDir/usr/bin/ - cp ./assets/logo.png app.AppDir/protodesk.png + cp protodesk app.AppDir/usr/bin/ + cp assets/logo.png app.AppDir/protodesk.png - - name: Download AppImageTool for amd64 - if: matrix.arch == 'amd64' + - name: Set up appimagetool run: | wget https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage -O appimagetool chmod +x appimagetool - - name: Download AppImageTool for aarch64 - if: matrix.arch == 'arm64' - run: | - wget https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-aarch64.AppImage -O appimagetool - chmod +x appimagetool - - - name: Install the desktop-file-utils dependency - run: | - sudo apt-get update && sudo apt-get install -y desktop-file-utils - - - name: Build AppImage for amd64 + - name: Build the AppImage run: | - ./appimagetool app.AppDir Protodesk-${{ matrix.arch }}.AppImage - echo "[+] Build successful on ${{ matrix.arch }}" + ./appimagetool app.AppDir Protodesk-${APP_VERSION}-x86_64.AppImage # - name: Upload release asset # uses: actions/upload-release-asset@v1 @@ -86,6 +78,6 @@ jobs: # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # with: # upload_url: ${{ github.event.release.upload_url}} - # asset_path: Protodesk-${{ matrix.arch }}.AppImage - # asset_name: Protodesk-${{ matrix.arch }}.AppImage + # asset_path: Protodesk-${{ env.APP_VERSION }}-${{ matrix.arch }}.AppImage + # asset_name: Protodesk-${{ env.APP_VERSION }}-${{ matrix.arch }}.AppImage # asset_content_type: application/octet-stream diff --git a/.gitignore b/.gitignore index 219d308..0683ce7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ app.onefile-build/ protodesk .DirIcon *.AppImage +Dockerfile diff --git a/Dockerfile b/Dockerfile index 92838b4..3829d82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,13 @@ FROM python:3.12-bullseye +ARG APP_VERSION +ARG ARCH +# ENV APP_VERSION=${APP_VERSION} +# ENV ARCH=${ARCH} + WORKDIR /app -RUN apt-get update && apt-get install -y patchelf +RUN apt-get update && apt-get install -y patchelf desktop-file-utils libfuse2 COPY . /app @@ -10,7 +15,25 @@ COPY . /app RUN python -m venv .venv && chmod +x .venv/bin/activate && .venv/bin/activate # install project dependencies -RUN pip3 install -r requirements.txt +RUN pip install -r requirements.txt # build the app with Nuitka RUN nuitka --enable-plugin=pyside6 --include-data-dir=./assets=./assets --standalone --onefile --lto=yes --output-filename=protodesk app.py + +# prepare AppImage directory +RUN mkdir -p app.AppDir/usr/bin +RUN cp protodesk app.AppDir/usr/bin/ +RUN cp assets/logo.png app.AppDir/protodesk.png + +# set up appimagetool +RUN bash -c "\ + if [ "$(uname -m)" == "x86_64" ]; then \ + wget https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage -O appimagetool; \ + elif [ "$(uname -m)" == "aarch64" ]; then \ + wget https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-aarch64.AppImage -O appimagetool; \ + fi && \ + chmod +x appimagetool \ + " + +# build the AppImage +RUN ./appimagetool app.AppDir Protodesk-${APP_VERSION}-${ARCH}.AppImage