Skip to content

Commit

Permalink
feat(appimage): switch to appimage-builder
Browse files Browse the repository at this point in the history
This commits introduces appimage-builder in favor of the hand-crafted shell script.
It allows a stable build environment, up-to-date library versions and multi-platform builds.
  • Loading branch information
git-developer committed Sep 24, 2023
1 parent a0fd405 commit 61d9a40
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 188 deletions.
31 changes: 27 additions & 4 deletions .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Build and publish AppImages

env:
UBUNTU_RELEASE: jammy
UBUNTU_PUBKEY: 871920D1991BC93C

on:
pull_request:
push:
Expand All @@ -16,6 +20,7 @@ jobs:
matrix:
platform:
- linux/amd64
- linux/arm64

steps:
- uses: actions/checkout@v4
Expand All @@ -34,16 +39,34 @@ jobs:
platforms: ${{ matrix.platform }}
outputs: build
build-args: |
APPIMAGE_VERSION=${{ env.GITHUB_REF_SLUG }}
REPO_OWNER=${{ env.GITHUB_REPOSITORY_OWNER }}
UBUNTU_RELEASE
- name: Prepare environment for building AppImage
env:
TARGET_PLATFORM: ${{ matrix.platform }}
shell: bash
run: |
set -eua
. build/.build-metadata.env
rm build/.build-metadata.env
APPIMAGE_SOURCE=build
APPIMAGE_VERSION="${GITHUB_REF_SLUG}"
APPIMAGE_APT_ARCH="${TARGETARCH}"
APPIMAGE_APT_DISTRO="${UBUNTU_RELEASE}"
APPIMAGE_APT_PUBKEY="${UBUNTU_PUBKEY}"
APPIMAGE_ARCH="${TARGETMACHINE}"
printenv | grep ^APPIMAGE_ >>"${GITHUB_ENV}"
- name: Build AppImage
uses: AppImageCrafters/[email protected]

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: appimages
path: |
./build/*.AppImage
./build/*.AppImage.zsync
./*.AppImage
./*.AppImage.zsync
if-no-files-found: error

release:
Expand Down
85 changes: 85 additions & 0 deletions AppImageBuilder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
version: 1

script:
- |
mv "{{APPIMAGE_SOURCE}}" "${TARGET_APPDIR}"
# Manual installation is required until fix of https://github.com/AppImageCrafters/build-appimage/issues/5
if ! command -v mksquashfs >/dev/null; then
apt-get update && apt-get install -y --no-install-recommends squashfs-tools
fi
AppDir:
app_info:
id: org.ryochan7.sc-controller
name: sc-controller
version: "{{APPIMAGE_VERSION}}"
icon: sc-controller
exec: bin/bash
exec_args: entrypoint $@

after_runtime: |
source="${TARGET_APPDIR}/usr/share/applications/sc-controller.desktop"
target="${TARGET_APPDIR}/org.ryochan7.sc-controller.desktop"
sed -i -E '/^(Comment|Categories)=.*$/d' "${target}"
grep -v -P '^(\[Desktop Entry\])|(Name|Exec|Type|Icon)=.*$' "${source}" >>"${target}"
apt:
arch:
- "{{APPIMAGE_APT_ARCH}}"
sources:
- sourceline: deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ "{{APPIMAGE_APT_DISTRO}}" main universe
key_url: "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x{{APPIMAGE_APT_PUBKEY}}"
- sourceline: deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ "{{APPIMAGE_APT_DISTRO}}"-updates main universe
- sourceline: deb [arch=amd64] http://security.ubuntu.com/ubuntu/ "{{APPIMAGE_APT_DISTRO}}"-security main universe
- sourceline: deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ "{{APPIMAGE_APT_DISTRO}}" main universe
- sourceline: deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ "{{APPIMAGE_APT_DISTRO}}"-updates main universe
- sourceline: deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ "{{APPIMAGE_APT_DISTRO}}"-security main universe
include:
- bash
- gir1.2-rsvg-2.0
- libc-bin
- libbluetooth3
- librsvg2-common
- python3-gi-cairo
- python3-evdev
- python3-pylibacl
- python3-vdf
exclude:
- 'gcc*'
- 'libblkid*'
- 'libc6*'
- 'libdb*'
- 'libgcc*'
- 'libicu*'
- 'libmount*'
- 'libncurses*'
- 'libreadline*'
- 'libssl*'
- 'libstdc*'
- 'libtirpc*'
- 'readline*'
- '*crypt*'
- '*krb*'
- '*sqlite*'

files:
exclude:
- usr/share/man
- usr/share/doc
- usr/share/gtk-doc
- usr/share/local
- usr/share/thumbnailers
- usr/share/icu
- usr/lib/*/glib-2.0
- usr/lib/*/gdk-pixbuf-2.0/*/loaders/libpixbufloader-[!s]*.so

runtime:
path_mappings:
- '/sbin/ldconfig.real:${APPDIR}/sbin/ldconfig.real'
env:
PYTHONPATH: '${APPDIR}/usr/lib/python3/dist-packages:${PYTHONPATH}'
GI_TYPELIB_PATH: '${APPDIR}/usr/lib/{{APPIMAGE_ARCH}}-linux-gnu/girepository-1.0'

AppImage:
arch: "{{APPIMAGE_ARCH}}"
update-information: "gh-releases-zsync|Ryochan7|sc-controller|latest|sc-controller-*.glibc-{{APPIMAGE_ARCH}}.AppImage.zsync"
45 changes: 27 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,37 @@ RUN apt-get update && \
libacl1-dev imagemagick librsvg2-2 \
zsync

RUN curl -sSL -o /tmp/appimagetool.AppImage "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-$(uname -m).AppImage" && \
chmod +x /tmp/appimagetool.AppImage && \
cd /opt && /tmp/appimagetool.AppImage --appimage-extract && \
mv squashfs-root appimage-tool.AppDir && \
ln -s /opt/appimage-tool.AppDir/AppRun /usr/bin/appimagetool && \
rm /tmp/appimagetool.AppImage

COPY . /work
WORKDIR /work
RUN if [ ! -d /usr/include/linux ]; then \
ln -s "$(find /usr -xdev -type f -name 'input-event-codes.h' -exec dirname '{}' \; -quit)" /usr/include/linux; \
fi
RUN ./appimage-build.sh
ARG TARGET=/work/appimage

# Build and install
RUN python3 setup.py build --executable "/usr/bin/env python3" && \
python3 setup.py install --single-version-externally-managed --prefix "${TARGET}/usr" --record /dev/null

# Provide input-event-codes.h as fallback for runtime systems without linux headers
RUN cp -a \
"$(find /usr -type f -name input-event-codes.h -print -quit)" \
"$(find "${TARGET}" -type f -name uinput.py -printf '%h\n' -quit)"

# Create symlinks with short names for static libraries
RUN suffix=".cpython-*-$(uname -m)-linux-gnu.so" && \
find "${TARGET}/usr" -type f -path "*/site-packages/*${suffix}" \
| while read -r path; do ln -sfr "${path}" "${path%${suffix}}.so"; done

# Put AppStream metadata into required location
RUN mkdir -p ${TARGET}/usr/share/metainfo && \
cp scripts/sc-controller.appdata.xml "${TARGET}/usr/share/metainfo/"

# Convert icon to PNG (required for icons in .desktop file)
RUN convert -background none "${TARGET}/usr/share/pixmaps/sc-controller.svg" "${TARGET}/sc-controller.png"

# Copy start script
RUN cp -a scripts/appimage-AppRun.sh "${TARGET}/entrypoint"

# Store build metadata
ARG TARGETOS TARGETARCH TARGETVARIANT
RUN export "TARGETMACHINE=$(uname -m)" && printenv | grep ^TARGET >>.build-metadata.env
ARG APPIMAGE_VERSION=latest
ARG REPO_OWNER=Ryochan7
ARG APPIMAGE_UPDATE_INFO
RUN set -a && . ./.build-metadata.env && \
update_info="${APPIMAGE_UPDATE_INFO:-gh-releases-zsync|${REPO_OWNER}|sc-controller|latest|sc-controller-*.glibc-${TARGETMACHINE}.AppImage.zsync}" && \
appimagetool -n -u "${update_info}" appimage "sc-controller-${APPIMAGE_VERSION}.glibc-${TARGETMACHINE}.AppImage"

FROM scratch AS export-stage
COPY --from=build-stage /work/*.AppImage* /work/appimage /work/.build-metadata.env /
COPY --from=build-stage /work/appimage /work/.build-metadata.env /
164 changes: 0 additions & 164 deletions appimage-build.sh

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/appimage-AppRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
export PATH=${APPDIR}:${APPDIR}/usr/bin:$PATH
export LD_LIBRARY_PATH=${APPDIR}/usr/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${APPDIR}/usr/lib64:$LD_LIBRARY_PATH
export GI_TYPELIB_PATH=${APPDIR}/usr/lib/girepository-1.0
export GDK_PIXBUF_MODULEDIR=${APPDIR}/usr/lib/gdk-pixbuf-2.0/2.10.0/loaders
export GI_TYPELIB_PATH="${APPDIR}/usr/lib/girepository-1.0:${GI_TYPELIB_PATH}"
export GDK_PIXBUF_MODULEDIR="${GDK_PIXBUF_MODULEDIR:-${APPDIR}/usr/lib/gdk-pixbuf-2.0/2.10.0/loaders}"
export PYTHONPATH=${APPDIR}/usr/lib/python3.10/site-packages:$PYTHONPATH
export PYTHONPATH=${APPDIR}/usr/lib64/python3.10/site-packages:$PYTHONPATH
export SCC_SHARED=${APPDIR}/usr/share/scc
Expand Down

0 comments on commit 61d9a40

Please sign in to comment.