Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/create-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,50 @@ jobs:
-
name: Update apt packages
run: docker exec -t imagine-${{ matrix.php-version }} apt-get upgrade -qy
-
name: Inspect container environment
id: inspect
run: |
if docker exec -t imagine-${{ matrix.php-version }} /installer.sh support-avif; then
echo 'AVIF is supported'
AVIF_SUPPORT=yes
else
AVIF_SUPPORT=no
fi
if docker exec -t imagine-${{ matrix.php-version }} /installer.sh support-heic; then
echo 'HEIC is supported'
HEIC_SUPPORT=yes
else
HEIC_SUPPORT=no
fi
echo "::set-output name=avif-support::$AVIF_SUPPORT"
echo "::set-output name=heic-support::$HEIC_SUPPORT"
-
name: Install git
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh git $GIT_VERSION
-
name: Install libaom ${{ env.LIBAOM_VERSION }}
if: ${{ steps.inspect.outputs.avif-support == 'yes' || steps.inspect.outputs.heic-support == 'yes' }}
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libaom $LIBAOM_VERSION
-
name: Install libdav1d ${{ env.LIBDAV1D_VERSION }}
if: ${{ steps.inspect.outputs.avif-support == 'yes' }}
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libdav1d $LIBDAV1D_VERSION
-
name: Install libyuv
if: ${{ steps.inspect.outputs.avif-support == 'yes' || steps.inspect.outputs.heic-support == 'yes' }}
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libyuv
-
name: Install libavif ${{ env.LIBAVIF_VERSION }}
if: ${{ steps.inspect.outputs.avif-support == 'yes' }}
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libavif $LIBAVIF_VERSION
-
name: Install libde265 ${{ env.LIBDE265_VERSION }}
if: ${{ steps.inspect.outputs.heic-support == 'yes' }}
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libde265 $LIBDE265_VERSION
-
name: Install libheif ${{ env.LIBHEIF_VERSION }}
if: ${{ steps.inspect.outputs.heic-support == 'yes' }}
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libheif $LIBHEIF_VERSION
-
name: Install Composer
Expand Down
180 changes: 158 additions & 22 deletions docker/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ installGit() {
git version --build-options
}

# Try to install libaom.
# Install libaom.
#
# Arguments:
# $1: the version to be installed
#
# Return:
# 0 in case of success
# 1 in case of errors
installLibaom() {
if ! isCMakeAtLeastVersion '3.6'; then
echo 'libaom not installed because cmake is too old' >&2
return
if ! isAvifSupported 2>/dev/null && ! isHeicSupported 2>/dev/null; then
echo 'libaom not installed because the system does not support neither AVIF nor HEIC' >&2
return 1
fi
installAptPackages '' 'cmake ninja-build nasm'
printf 'Downloading libaom v%s... ' "$1"
Expand All @@ -54,16 +58,21 @@ installLibaom() {
ldconfig
markPackagesAsInstalledByRegex '^(lib)?aom([0-9]|-dev)'
pkg-config --list-all | grep -E '^(lib)?aom\s'
return 0
}

# Try to install libdav1d.
# Install libdav1d.
#
# Arguments:
# $1: the version to be installed
#
# Return:
# 0 in case of success
# 1 in case of errors
installLibdav1d() {
if ! isMesonAtLeastVersion '0.44'; then
echo 'libdav1d not installed because meson is too old' >&2
return
if ! isAvifSupported 2>/dev/null; then
echo 'libdav1d not installed because the system does not support AVIF' >&2
return 1
fi
installAptPackages '' 'meson ninja-build nasm'
printf 'Downloading libdav1d v%s... ' "$1"
Expand All @@ -82,16 +91,21 @@ installLibdav1d() {
ldconfig
markPackagesAsInstalledByRegex '^(lib)?dav1d([0-9]|-dev)'
pkg-config --list-all | grep -E '^(lib)?dav1d\s'
return 0
}

# Try to install libyuv.
# Install libyuv.
#
# Arguments:
# $1: the version to be installed
#
# Return:
# 0 in case of success
# 1 in case of errors
installLibyuv() {
if ! isGccAtLeastVersion '4.9.3'; then
echo 'libyuv not installed because gcc is too old' >&2
return
if ! isAvifSupported 2>/dev/null && ! isHeicSupported 2>/dev/null; then
echo 'libyuv not installed because the system does not support neither AVIF nor HEIC' >&2
return 1
fi
installAptPackages '^libjpeg[0-9]*-turbo' 'cmake ^libjpeg[0-9]*-turbo-dev'
printf 'Downloading libyuv... '
Expand All @@ -100,27 +114,60 @@ installLibyuv() {
printf 'done.\n'
mkdir "$installLibyuv_dir/build"
cd "$installLibyuv_dir/build"
printf '\nconfigure_file(imaginepatch-libyuv.pc.in imaginepatch-libyuv.pc @ONLY)\n' >>../CMakeLists.txt
cat <<'EOT' >../imaginepatch-libyuv.pc.in
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${prefix}/lib

Name: @CPACK_PACKAGE_NAME@
Description: @CPACK_PACKAGE_DESCRIPTION@
Version: @CPACK_PACKAGE_VERSION@
Requires: @pc_req_public@
Requires.private: @pc_req_private@
Cflags: -I${includedir}
Libs: -L${libdir} -llibyuv
EOT
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -B. ..
make -j$(nproc) install
ldconfig
if ! pkg-config --exists libyuv && ! pkg-config --exists yuv; then
cp imaginepatch-libyuv.pc /usr/lib/pkgconfig/libyuv.pc
ldconfig
fi
cd - >/dev/null
rm -rf "$installLibyuv_dir"
ldconfig
markPackagesAsInstalledByRegex '^(lib)?yuv([0-9]|-dev)'
#pkg-config --list-all | grep -E '^(lib)?yuv\s'
pkg-config --list-all | grep -E '^(lib)?yuv\s'
return 0
}

# Try to install libavif.
# Install libavif.
#
# Arguments:
# $1: the version to be installed
#
# Return:
# 0 in case of success
# 1 in case of errors
installLibavif() {
if ! isAvifSupported 2>/dev/null; then
echo 'libavif not installed because the system does not support AVIF' >&2
return 1
fi
if ! pkg-config --list-all | grep -E '^(lib)?aom\s' >/dev/null; then
echo 'libavif not installed because libaom is not installed' >&2
return
return 1
fi
if ! isCMakeAtLeastVersion '3.5'; then
echo 'libavif not installed because cmake is too old' >&2
return
if ! pkg-config --list-all | grep -E '^(lib)?dav1d\s' >/dev/null; then
echo 'libavif not installed because libdav1d is not installed' >&2
return 1
fi
if ! pkg-config --list-all | grep -E '^(lib)?yuv\s' >/dev/null; then
echo 'libavif not installed because libyuv is not installed' >&2
return 1
fi
installAptPackages '' 'cmake'
printf 'Downloading libavif v%s... ' "$1"
Expand All @@ -136,17 +183,26 @@ installLibavif() {
ldconfig
markPackagesAsInstalledByRegex '^(lib)?avif([0-9]|-dev)'
pkg-config --list-all | grep -E '^(lib)?avif\s'
return 0
}

# Install libde265.
#
# Arguments:
# $1: the version to be installed
#
# Return:
# 0 in case of success
# 1 in case of errors
#
# @todo:
# configure: WARNING: Did not find libvideogfx or libsdl, video output of dec265 will be disabled.
# configure: WARNING: Did not find libvideogfx or libswscale, compilation of sherlock265 will be disabled.
installLibde265() {
if ! isHeicSupported 2>/dev/null; then
echo 'libde265 not installed because the system does not support HEIC' >&2
return 1
fi
installAptPackages '' 'automake libtool'
printf 'Downloading libde265 v%s... ' "$1"
installLibde265_dir="$(mktemp -d)"
Expand All @@ -161,14 +217,31 @@ installLibde265() {
ldconfig
markPackagesAsInstalledByRegex '^(lib)?de265'
pkg-config --list-all | grep -E '^(lib)?de265\s'
return 0
}

# Install libheif.
#
# Arguments:
# $1: the version to be installed
#
# Return:
# 0 in case of success
# 1 in case of errors
installLibheif() {
installAptPackages '^libjpeg[0-9]*-turbo ^libpng[0-9\-]*$' 'automake libtool ^libjpeg[0-9]*-turbo-dev libpng-dev'
if ! isHeicSupported 2>/dev/null; then
echo 'libheif not installed because the system does not support HEIC' >&2
return 1
fi
if ! pkg-config --list-all | grep -E '^(lib)?aom\s' >/dev/null; then
echo 'libheif not installed because libaom is not installed' >&2
return 1
fi
if ! pkg-config --list-all | grep -E '^(lib)?de265\s' >/dev/null; then
echo 'libheif not installed because libde265 is not installed' >&2
return 1
fi
installAptPackages '^libjpeg[0-9]*-turbo ^libpng[0-9\-]*$ ^libx265(-[0-9\.\-]+)?$' 'automake libtool ^libjpeg[0-9]*-turbo-dev libpng-dev libx265-dev'
printf 'Downloading libheif v%s... ' "$1"
installLibheif_dir="$(mktemp -d)"
curl -ksSLf -o - https://github.com/strukturag/libheif/releases/download/v$1/libheif-$1.tar.gz | tar xzm -C "$installLibheif_dir"
Expand All @@ -182,6 +255,59 @@ installLibheif() {
ldconfig
markPackagesAsInstalledByRegex '^libheif.*'
pkg-config --list-all | grep -E '^(lib)?heif\s'
return 0
}

# Check if AVIF format is supported in this environment
#
# Output (stderr):
# the reason (if any) why it's not supported
#
# Return:
# 0: true
# 1: false
isAvifSupported() {
if ! isCMakeAtLeastVersion '3.6'; then
echo 'AVIF support not provided since compiling libaom requires a more recent cmake version' >&2
return 1
fi
if ! isMesonAtLeastVersion '0.44'; then
echo 'AVIF support not provided since compiling libdav1d requires a more recent meson version' >&2
return 1
fi
if ! isGccAtLeastVersion '4.9.3'; then
echo 'AVIF support not provided since compiling libyuv requires a more recent gcc version' >&2
return 1
fi
if ! isCMakeAtLeastVersion '3.5'; then
echo 'AVIF support not provided since compiling libavif requires a more recent cmake version' >&2
return 1
fi
return 0
}

# Check if HEIC format is supported in this environment
#
# Output (stderr):
# the reason (if any) why it's not supported
#
# Return:
# 0: true
# 1: false
isHeicSupported() {
if ! isCMakeAtLeastVersion '3.6'; then
echo 'HEIC support not provided since compiling libaom requires a more recent cmake version' >&2
return 1
fi
if [ -z "$(getAptPackageAvailableVersion 'libx265(-[0-9\.\-]+)?$')" ]; then
echo 'HEIC support not provided since libx265 is not available'
return 1
fi
if ! isGccAtLeastVersion '4.9.3'; then
echo 'HEIC support not provided since compiling libyuv requires a more recent gcc version' >&2
return 1
fi
return 0
}

# Install GraphicsMagick.
Expand All @@ -204,7 +330,7 @@ installGraphicsmagick() {
curl -ksSLf -o - http://ftp.icm.edu.pl/pub/unix/graphics/GraphicsMagick/${1%.*}/GraphicsMagick-$1.tar.gz | tar xzm -C "$installGraphicsmagick_dir"
printf 'done.\n'
cd "$installGraphicsmagick_dir/GraphicsMagick-$1"
CFLAGS='-Wno-misleading-indentation -Wno-unused-const-variable -Wno-pointer-compare -Wno-tautological-compare' ./configure --enable-shared
CFLAGS='-Wno-misleading-indentation -Wno-unused-const-variable -Wno-pointer-compare -Wno-tautological-compare' ./configure --disable-static --enable-shared
make V=0 -j$(nproc) install
cd - >/dev/null
rm -rf "$installGraphicsmagick_dir"
Expand Down Expand Up @@ -232,7 +358,7 @@ installImagemagick() {
curl -ksSLf -o - https://www.imagemagick.org/download/releases/ImageMagick-$1.tar.xz | tar xJm -C "$installImagemagick_dir"
printf 'done.\n'
cd "$installImagemagick_dir/ImageMagick-$1"
./configure --disable-docs
./configure --disable-docs --disable-static --enable-shared
make V=0 -j$(nproc) install
cd - >/dev/null
rm -rf "$installImagemagick_dir"
Expand All @@ -242,13 +368,23 @@ installImagemagick() {

if grep -Eq 'PRETTY_NAME.*jessie' /etc/os-release; then
# https://bugs.launchpad.net/ubuntu/+source/apt/+bug/1332440
ulimit -n 10000
ulimit -n 10000 2>/dev/null || true
fi

case "$1" in
git)
installGit "$2"
;;
support-avif)
if ! isAvifSupported; then
return 1
fi
;;
support-heic)
if ! isHeicSupported; then
return 1
fi
;;
libaom)
installLibaom "$2"
;;
Expand Down
12 changes: 10 additions & 2 deletions docker/utilities.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ stringInList() {
# 0: true
# 1: false
isAtLeastVersion() {
if [ -z "$1" ]; then
return 1
fi
isAtLeastVersion_actual=$(printf '%s' "$1" | cut -d. -f1)
isAtLeastVersion_wanted=$(printf '%s' "$2" | cut -d. -f1)
if [ $isAtLeastVersion_actual -lt $isAtLeastVersion_wanted ]; then
Expand Down Expand Up @@ -136,9 +139,14 @@ isGccAtLeastVersion() {
# $1: the package name (regex, without leading '^' or trailing '$')
#
# Output:
# the version (in format <mayor>.<minor>.<patch>)
# the version (in format <mayor>.<minor>.<patch> or <mayor>.<minor>)
# outputs nothing if the package can't be found
getAptPackageAvailableVersion() {
apt-cache show "^$1$" | grep -E '^Version: ' | head -n1 | sed -E 's/^.*[^0-9]([0-9]+\.[0-9]+\.[0-9]+).*$/\1/'
getAptPackageAvailableVersion_found="$(apt-cache show "^$1$" 2>/dev/null || true)"
if [ -z "$getAptPackageAvailableVersion_found" ]; then
return
fi
printf '%s' "$getAptPackageAvailableVersion_found" | grep -E '^Version: ' | head -n1 | sed -E 's/^.*[^0-9\.]([0-9]+\.[0-9]+(\.[0-9]+)?).*$/\1/'
}

# Check if the version of an apt package is at least the provided one.
Expand Down