Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTERNAL: Add support for Heroku-24 stack #1

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn macOS litter

12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
build: build-heroku-16 build-heroku-20
build: build-heroku-24

build-heroku-16:
Copy link
Author

@swishstache swishstache Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heroku hasn't supported this stack since April 2021

@echo "Building imagemagick in Docker for heroku-16..."
@docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-16" -w /buildpack heroku/heroku:16-build scripts/build_imagemagick imagemagick-heroku-16.tar.gz

build-heroku-20:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stack reaches end of life April 30, 2025

@echo "Building imagemagick in Docker for heroku-20..."
@docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-20" -w /buildpack heroku/heroku:20-build scripts/build_imagemagick imagemagick-heroku-20.tar.gz
build-heroku-24:
@echo "Building imagemagick in Docker for heroku-24..."
@docker run --user root -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-24" -w /buildpack heroku/heroku:24-build scripts/build_imagemagick imagemagick-heroku-24.tar.gz
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike past heroku/heroku:N-build images, "heroku/heroku:24-build" sets the default user to "heroku" as its last step. That means the build_imagemagick script fails in a few places due to lack of permissions (such as writing to "/etc/apt/"). I set the user to root to ensure the script can execute without changes.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ heroku-buildpack-imagemagick-heif

## Motivation

The rise in popularity and use of HEIF/HEIC(High Efficency Image Format) means your project's image processing also needs to be able to handle this format. The current default version of imagemagick installed on heroku:16 dynos is 6.8.9.9 and does not support processing heic image files. This [Heroku buildpack](http://devcenter.heroku.com/articles/buildpacks) vendors a version of ImageMagick with HEIF support binaries into your project. It is based on several resources including https://github.com/retailzipline/heroku-buildpack-imagemagick-heif.
The rise in popularity and use of HEIF/HEIC(High Efficency Image Format) means your project's image processing also needs to be able to handle this format. This [Heroku buildpack](http://devcenter.heroku.com/articles/buildpacks) vendors a version of ImageMagick with HEIF support binaries into your project. It is based on several resources including https://github.com/retailzipline/heroku-buildpack-imagemagick-heif.

The orginal buildpack was created for `heroku-18` stacks but this one was modified to work with [Heroku stack:](https://devcenter.heroku.com/articles/stack) `heroku-16` and `heroku-20`.
The orginal buildpack was created for `heroku-18` stacks but this one was modified to work with [Heroku stack:](https://devcenter.heroku.com/articles/stack) `heroku-24`.

The tar file in the [/build folder](./build) currently contains:

You will need to build a new binary if you want to use a newer or different version. To build a new binary see [How to Build a New Binary](#how-to-build-a-new-binary)

## Versions

This buildpack currently supports **Heroku 16** and **Heroku 20** and contains **ImageMagick 7.0.11-4 Q16 x86_64** https://imagemagick.org
This buildpack currently supports **Heroku 24** and contains **ImageMagick 7.0.11-5 Q16 x86_64** https://imagemagick.org

## Usage

Expand Down Expand Up @@ -53,7 +53,7 @@ $ make build
To build the binary for a specific Heroku stack (for example, Heroku 16), run:

```
$ make build-heroku-16
$ make build-heroku-24
```

Check the [currently supported versions](#versions).
Expand All @@ -76,8 +76,8 @@ Heroku provides [Docker images](https://hub.docker.com/r/heroku/heroku/tags?page
Those images can be referenced in `Makefile` in this repo to build ImageMagick for a new Stack.

```
build-heroku-20:
@docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-20" -w /buildpack heroku/heroku:20-build scripts/build_imagemagick imagemagick-heroku-20.tar.gz
build-heroku-26:
@docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-26" -w /buildpack heroku/heroku:26-build scripts/build_imagemagick imagemagick-heroku-26.tar.gz
```

In the example above we use the Docker image `heroku/heroku:20-build` as well as passing the variable `STACK` as `heroku-20` and the output binary file as `imagemagick-heroku-20.tar.gz`.
Expand Down
Binary file removed build/imagemagick-heroku-16.tar.gz
Binary file not shown.
Binary file added build/imagemagick-heroku-24.tar.gz
Binary file not shown.
43 changes: 5 additions & 38 deletions scripts/build_imagemagick
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,23 @@ function handle_error() {
}
trap handle_error EXIT SIGINT

function add_xenial_repositories() {
Copy link
Author

@swishstache swishstache Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even when building for Heroku-20, this script was reaching back to xenial so it could apt-get install libjasper-dev for imagemagick. That library has been superseded by https://github.com/uclouvain/openjpeg which is included in Heroku-24.

$ ldconfig -p | grep libopenjp2
libopenjp2.so.7 (libc6,x86-64) => /lib/x86_64-linux-gnu/libopenjp2.so.7
libopenjp2.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libopenjp2.so

cat <<-EOT >> /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu/ xenial main universe
deb http://security.ubuntu.com/ubuntu xenial-security main
EOT
}
# avoid error: E: You must put some 'deb-src' URIs in your sources.list
echo "deb-src http://archive.ubuntu.com/ubuntu noble main universe" >> /etc/apt/sources.list

# add source packages repository to sources.list
function add_source_repositories() {
echo "deb-src http://archive.ubuntu.com/ubuntu/ xenial main universe" >> /etc/apt/sources.list
if [[ $STACK == "heroku-20" ]]; then
add_xenial_repositories
fi
}

add_source_repositories

echo "⚙️ Getting libraries and dependencies..."
apt-get update -y
apt-get install -y build-essential autoconf libtool git-core
if [[ $STACK == "heroku-20" ]]; then
echo "⚙️ Getting additional dependencies for the selected stack..."
apt-get install -y libomp5 libomp-10-dev libjasper-dev
Copy link
Author

@swishstache swishstache Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment about libjasper-dev..

libomp5 libomp-10-dev are for OpenMP support. "heroku/heroku:24-build" uses gcc 13.2.0 which has support for OpenMP built-in (see https://gcc.gnu.org/wiki/openmp. and https://www.openmp.org/resources/openmp-compilers-tools/).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ apt show libomp-dev
Package: libomp-dev
Version: 1:18.0-59~exp2
Priority: extra
Section: universe/libdevel
Source: llvm-defaults (0.59~exp2)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: LLVM Packaging Team <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: libomp-18-dev (>= 18~)
Download-Size: 5366 B
APT-Sources: http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages
Description: LLVM OpenMP runtime - dev package

$ apt show libomp5
Package: libomp5
Version: 1:18.0-59~exp2
Priority: extra
Section: universe/libs
Source: llvm-defaults (0.59~exp2)
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: LLVM Packaging Team <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11.3 kB
Depends: libomp5-18 (>= 18~)
Download-Size: 5348 B
APT-Sources: http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages
Description: LLVM OpenMP runtime

fi
apt-get build-dep -y imagemagick libmagickcore-dev

# install the libde265 library
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lib is now part of heroku-24

$ ldconfig -p | grep libde265
libde265.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libde265.so.0
libde265.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libde265.so

echo "⚙️ Installing and configuring libde265..."
git clone https://github.com/strukturag/libde265.git $WORK_DIR/libde265
cd $WORK_DIR/libde265
./autogen.sh && ./configure && make && make install

# install the libheif library
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lib is now part of heroku-24

$ ldconfig -p | grep libheif
libheif.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libheif.so.1
libheif.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libheif.so

echo "⚙️ Installing and configuring libheif..."
git clone https://github.com/strukturag/libheif.git $WORK_DIR/libheif
cd $WORK_DIR/libheif
./autogen.sh && ./configure && make && make install

# get, configure and install newest imagemagick
echo "⚙️ Installing latest imagemagick..."
git clone https://github.com/ImageMagick/ImageMagick.git $WORK_DIR/imagemagick
# get, configure and install imagemagick
echo "⚙️ Installing imagemagick version 7.0.11-5..."
git clone --depth 1 --branch 7.0.11-5 https://github.com/ImageMagick/ImageMagick.git $WORK_DIR/imagemagick
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

---depth 1 - don't clone the whole repo.

--branch 7.0.11-5 - only clone the tag "7.0.11-5".

cd $WORK_DIR/imagemagick
./configure --with-heic=yes --prefix=$WORK_DIR/imagemagick --without-gvc
make && make install

# copy the dependencies into imagemagick lib directory
cp /usr/local/lib/libde265.so.0 $WORK_DIR/imagemagick/lib
cp /usr/local/lib/libheif.so.1 $WORK_DIR/imagemagick/lib
cp /usr/lib/x86_64-linux-gnu/libomp.so.5 $WORK_DIR/imagemagick/lib
cp /usr/lib/x86_64-linux-gnu/libiomp5.so $WORK_DIR/imagemagick/lib
Comment on lines -62 to -65
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these ship with the heroku-24 image


# clean up the build and get ready for packaging
echo "🧹 Cleaning up..."
Expand Down