Skip to content

Commit

Permalink
Update to support Docker modern way
Browse files Browse the repository at this point in the history
  • Loading branch information
navidemad committed Jul 25, 2024
1 parent 8bb036e commit bb112b5
Show file tree
Hide file tree
Showing 244 changed files with 345 additions and 45,005 deletions.
Empty file added .dockerignore
Empty file.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ updates:
day: "saturday"
commit-message:
prefix: "gh"
target-branch: main
target-branch: master
73 changes: 14 additions & 59 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,18 @@
name: ci

on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.pull_request.head.ref || github.head_ref || github.ref }}
cancel-in-progress: true

permissions:
contents: read

on: [push, pull_request]
jobs:
fail_if_pull_request_is_draft:
if: github.event.pull_request.draft == true
runs-on: ubuntu-22.04
steps:
- name: Fails in order to indicate that pull request needs to be marked as ready to review and unit tests workflow needs to pass.
run: exit 1
build:
timeout-minutes: 15
if: ${{ (github.event_name == 'push' || !github.event.pull_request.draft) }}
runs-on: ubuntu-22.04
test:
runs-on: ubuntu-latest
strategy:
matrix:
heroku_stack_version: [24]
steps:
- name: 🏠 Checkout source code from repository
uses: actions/checkout@master
- name: 🗂️ Cache Docker
uses: satackey/action-docker-layer-caching@master
continue-on-error: true
- name: 🧪 Testing
run: |
docker build heroku/heroku:22-build --tag local-heroku22:$(date +%s)
docker run --rm local-heroku22:$(date +%s) convert -list configure
# docker run --rm heroku-imagemagick -list configure
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -resize 100 /container-test-images/test.jpg /container-test-images/test-resize.jpg
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -resize 100 /container-test-images/test.jpg webp:/container-test-images/test-jpg.webp
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -resize 100 /container-test-images/test.jpg avif:/container-test-images/test-jpg.avif
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -resize 100 /container-test-images/test.png /container-test-images/test-resize.png
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -resize 100 /container-test-images/test.png webp:/container-test-images/test-png.webp
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -resize 100 /container-test-images/test.png avif:/container-test-images/test-png.avif
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -resize 100 /container-test-images/test.png jxl:/container-test-images/test-png.jxl
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -resize 100 /container-test-images/test.tiff /container-test-images/test-resize.tiff
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -resize 100 /container-test-images/test.tiff webp:/container-test-images/test-tiff.webp
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -resize 100 /container-test-images/test.tiff avif:/container-test-images/test-tiff.avif
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -resize 100 /container-test-images/test.tiff jxl:/container-test-images/test-tiff.jxl
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick /container-test-images/test.pdf /container-test-images/test-pdf.png
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick /container-test-images/jpg-with-metadata.jpg /container-test-images/jpg-with-metadata.webp
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick -coalesce /container-test-images/test.gif /container-test-images/test-gif.webp
# docker run --rm -v $(pwd)/local-test-images:/container-test-images heroku-imagemagick /container-test-images/test.jpg -antialias -font DejaVu-Sans -pointsize 20 -gravity Southeast -annotate +15+15 'TEST' /container-test-images/test-text.jpg
# docker run --rm heroku-imagemagick -list configure | grep DELEGATES | grep "fontconfig freetype heic jbig jng jpeg jxl lcms lzma png ps tiff webp x xml zlib"
# - name: 🌅 Upload Test Results
# uses: actions/upload-artifact@master
# with:
# name: ubuntu-tests
# path: local-test-images
uses: actions/checkout@v4
with:
path: app
- name: Buildpack CI
uses: buildpack-ci/run-tests@v1
env:
APP_SUBDIR: app
STACK: heroku-24
52 changes: 52 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
on: [push, pull_request]

jobs:
test-buildpack:
runs-on: ubuntu-latest
strategy:
matrix:
heroku_stack_version: [22, 24]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build Docker image for stack version ${{ matrix.heroku_stack_version }}
run: |
docker build \
--build-arg STACK_VERSION=${{ matrix.heroku_stack_version }} \
--tag heroku-imagemagick-stack-${{ matrix.heroku_stack_version }} \
--progress=plain \
--pull \
--file container/Dockerfile \
container
- name: Run tests for stack version ${{ matrix.heroku_stack_version }}
run: |
mkdir -p build
docker run --rm -t \
-v $PWD/build:/build \
heroku-imagemagick-stack-${{ matrix.heroku_stack_version }} \
sh -c 'cp -f /usr/local/build/imagemagick-heroku-*.tar.bz2 /build/ && cp -f /usr/local/build/*.config.log /build/configurations'
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Install dependencies
run: pip install pytest

- name: Run tests on fixture images
run: |
tar -xjf build/imagemagick-heroku-${{ matrix.heroku_stack_version }}.tar.bz2 -C /tmp/imagemagick
pytest test_fixtures.py --stack-version ${{ matrix.heroku_stack_version }}
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
.DS_Store
### Linux ###
*~

### macOS ###
.DS_Store

# Build artifacts
/build
!/build/configurations/heroku-*.config.log
!/build/heroku-*.tar.bz2
3 changes: 3 additions & 0 deletions .profile.d/imagemagick.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export PATH="$PATH:$HOME/vendor/imagemagick/bin"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$HOME/vendor/imagemagick/lib/pkgconfig"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/vendor/imagemagick/lib"
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# 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.
The current default version of imagemagick installed on heroku:22 dynos is a version 6.xx and does not support processing heic image files.
The current default version of imagemagick installed on heroku:24 dynos is a version 6.xx and does not support processing heic image files.

This [Heroku buildpack](https://devcenter.heroku.com/articles/buildpacks) vendors a version of ImageMagick with **WEBP and HEIF support** binaries into your project.

This one works was built for [**Heroku stack 20**](https://devcenter.heroku.com/articles/stack).

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

Version: ImageMagick 7.1.0-55
Version: ImageMagick 7.1.1-35

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)

Expand Down Expand Up @@ -37,7 +37,7 @@ heroku builds:cache:purge -a HEROKU_APP_NAME
# How to Build a New Binary (if you want to make somes changes)

The binary in this repo was built in a heroku:22 docker image running in a local dev environment.
However, there is a script called [**build.sh**](./build.sh) made to build a tar file through docker easily, it will be copied to the `build` directory. Then you should commit this changes to your git, and adjust the buildpack url previously mentionned just above.
However, there is a script called [**build.sh**](./build.sh) made to build a tar file through docker easily, it will be copied to the `build` directory. Then you should commit this changes to your git, and adjust the buildpack url previously mentioned just above.

## Prerequisites

Expand All @@ -50,6 +50,10 @@ However, there is a script called [**build.sh**](./build.sh) made to build a tar
- https://github.com/steeple-dev/heroku-buildpack-imagemagick
- https://github.com/retailzipline/heroku-buildpack-imagemagick-heif

## Knowledge Base

https://devcenter.heroku.com/articles/heroku-24-stack#upgrade-notes

## License

The gem is available as open source under the terms of the [MIT License](https://github.com/yespark/heroku-imagemagick-buildpack/blob/master/LICENSE).
84 changes: 61 additions & 23 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,57 +1,95 @@
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>

set -e
# bin/compile <build-dir> <cache-dir> <env-dir>

# fail hard
set -o pipefail

# fail harder
set -eu

# move hidden files too, just in case
shopt -s dotglob

BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3

BUILDPACK_NAME=imagemagick
BINARY_NAME=imagemagick-heroku-${STACK}.tar.gz

BIN_DIR=$(cd "$(dirname "$0")"; pwd)
ROOT_DIR=$(dirname "$BIN_DIR")

function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}

arrow() {
sed -u 's/^/-----> /'
}

ADD_PATH=""

function vendor() {
local binary="$1"
local path="$2"

if [ ! -f "$binary" ]; then
echo "Binary file '${binary}' not found for stack ${STACK}" | indent
exit 1
fi

echo "Fetching $binary" | indent
mkdir -p $path
tar -xj -f $binary -C $path

if [ -d "$path/bin" ]; then
export PATH="$path/bin:$PATH"
ADD_PATH="$path/bin"
else
ADD_PATH=""
fi

if [ -d "$path/lib/pkgconfig" ]; then
export PKG_CONFIG_PATH="$path/lib/pkgconfig:$PKG_CONFIG_PATH"
ADD_PKG_CONFIG_PATH="$path/lib/pkgconfig"
else
ADD_PKG_CONFIG_PATH=""
fi

export CPPPATH="$path/include:$CPPPATH"
export CPATH="$path/include:$CPATH"
export LIBRARY_PATH="$path/lib:$LIBRARY_PATH"
export LD_LIBRARY_PATH="$path/lib:$LD_LIBRARY_PATH"
ADD_CPPPATH="$path/include"
ADD_CPATH="$path/include"
ADD_LIBRARY_PATH="$path/lib"
ADD_LD_LIBRARY_PATH="$path/lib"
}

vendor "$ROOT_DIR/build/imagemagick.tar.bz2" "$BUILD_DIR/vendor/imagemagick"
echo "Vendoring binaries" | arrow
vendor "$ROOT_DIR/build/$BINARY_NAME" "$BUILD_DIR/vendor/imagemagick"

echo "Configuring build environment" | arrow
cat <<EOF > export
export MAGICK_HOME="$BUILD_DIR/vendor/imagemagick"
export MAGICK_CONFIGURE_PATH="/app/.magick"
export PATH="/app/bin:$PATH:\$PATH"
export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:$LD_LIBRARY_PATH"
export LIBRARY_PATH="\$LIBRARY_PATH:$LIBRARY_PATH"
export PKG_CONFIG_PATH="\$PKG_CONFIG_PATH:$PKG_CONFIG_PATH"
export CPPPATH="\$CPPPATH:$CPPPATH"
export CPATH="\$CPATH:$CPATH"
export PATH="/app/bin:$ADD_PATH:\$PATH"
export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:$ADD_LD_LIBRARY_PATH"
export LIBRARY_PATH="\$LIBRARY_PATH:$ADD_LIBRARY_PATH"
export PKG_CONFIG_PATH="\$PKG_CONFIG_PATH:$ADD_PKG_CONFIG_PATH"
export CPPPATH="\$CPPPATH:$ADD_CPPPATH"
export CPATH="\$CPATH:$ADD_CPATH"
EOF

echo "Building runtime environment" | arrow
mkdir -p $BUILD_DIR/.profile.d
cat <<EOF > $BUILD_DIR/.profile.d/imagemagick.sh

cat <<EOF > $BUILD_DIR/.profile.d/$BUILDPACK_NAME.sh
export MAGICK_HOME="$BUILD_DIR/vendor/imagemagick"
export MAGICK_CONFIGURE_PATH="/app/.magick"
export PATH="/app/bin:${PATH//$BUILD_DIR//app}:\$PATH"
export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:${LD_LIBRARY_PATH//$BUILD_DIR//app}"
export LIBRARY_PATH="\$LIBRARY_PATH:${LIBRARY_PATH//$BUILD_DIR//app}"
export PKG_CONFIG_PATH="\$PKG_CONFIG_PATH:${PKG_CONFIG_PATH//$BUILD_DIR//app}"
export CPPPATH="\$CPPPATH:${CPPPATH//$BUILD_DIR//app}"
export CPATH="\$CPATH:${CPATH//$BUILD_DIR//app}"
export PATH="/app/bin:${ADD_PATH//$BUILD_DIR//app}:\$PATH"
export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:${ADD_LD_LIBRARY_PATH//$BUILD_DIR//app}"
export LIBRARY_PATH="\$LIBRARY_PATH:${ADD_LIBRARY_PATH//$BUILD_DIR//app}"
export PKG_CONFIG_PATH="\$PKG_CONFIG_PATH:${ADD_PKG_CONFIG_PATH//$BUILD_DIR//app}"
export CPPPATH="\$CPPPATH:${ADD_CPPPATH//$BUILD_DIR//app}"
export CPATH="\$CPATH:${ADD_CPATH//$BUILD_DIR//app}"
EOF
12 changes: 11 additions & 1 deletion bin/detect
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
#!/usr/bin/env bash
echo "ImageMagick" && exit 0

SUPPORTED_STACKS=(heroku-22 heroku-24)

for stack_option in "${SUPPORTED_STACKS[@]}"; do
if [[ $STACK = $stack_option ]]; then
echo "imagemagick ($stack_option stack)"
exit 0
fi
done

echo "imagemagick buildpack doesn't support the $STACK stack" && exit 1
40 changes: 40 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

# bin/test <build-dir> <env-dir>
# env vars are passed in already, so we can ignore the dir

# fail hard
set -o pipefail

# fail harder
set -eu

# Setup Path variables, for later use in the Buildpack.
BIN_DIR=$(cd "$(dirname "$0")"; pwd)
export PATH=/app/.heroku/vendor/bin:$PATH

# unlike a regular app.json "test" script, this one isn't run with the app dir as the CWD
# we `cd` with a default value, so that the script can also be called from inside the app dir (`cd ""` does not change cwd)
cd "${1-}"

echo "Trying to run imagemagick with differents images from fixtures folder." >&2

echo $PATH | indent
magick -list configure | indent
magick -resize 100 /fixtures/test.avif /fixtures/test-resize.avif | indent
magick -resize 100 /fixtures/test.heic /fixtures/test-resize.heic | indent
magick -resize 100 /fixtures/test.jpg /fixtures/test-resize.jpg | indent
magick -resize 100 /fixtures/test.jpg webp:/fixtures/test-jpg.webp | indent
magick -resize 100 /fixtures/test.jpg avif:/fixtures/test-jpg.avif | indent
magick -resize 100 /fixtures/test.png /fixtures/test-resize.png | indent
magick -resize 100 /fixtures/test.png webp:/fixtures/test-png.webp | indent
magick -resize 100 /fixtures/test.png avif:/fixtures/test-png.avif | indent
magick -resize 100 /fixtures/test.png jxl:/fixtures/test-png.jxl | indent
magick -resize 100 /fixtures/test.tiff /fixtures/test-resize.tiff | indent
magick -resize 100 /fixtures/test.tiff webp:/fixtures/test-tiff.webp | indent
magick -resize 100 /fixtures/test.tiff avif:/fixtures/test-tiff.avif | indent
magick -resize 100 /fixtures/test.tiff jxl:/fixtures/test-tiff.jxl | indent
magick /fixtures/test.pdf /fixtures/test-pdf.png | indent
magick /fixtures/jpg-with-metadata.jpg /fixtures/jpg-with-metadata.webp | indent
magick -coalesce /fixtures/test.gif /fixtures/test-gif.webp | indent
magick /fixtures/test.jpg -antialias -font DejaVu-Sans -pointsize 20 -gravity Southeast -annotate +15+15 'TEST' /fixtures/test-text.jpg | indent
12 changes: 12 additions & 0 deletions bin/test-compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# bin/test-compile <build-dir> <cache-dir> <env-dir>

# fail hard
set -o pipefail

# fail harder
set -eu

bp_dir=$(cd $(dirname $0); cd ..; pwd)
source $bp_dir/bin/compile
Loading

0 comments on commit bb112b5

Please sign in to comment.