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

Allow use of Heroku config for ImageMagick version #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@ heroku-buildpack-imagemagick
=================================

This is a [Heroku buildpack](http://devcenter.heroku.com/articles/buildpacks) for vendoring the ImageMagick binaries into your project.

## Note on Heroku config

Optionally, set the ImageMagick version in a Heroku config like this:

```
heroku config:set IMAGE_MAGICK_VERSION=7.0.5-0
```

Make sure the version you're referencing exists on as a `.tar.xz` file amon the [ImageMagic releases](http://www.imagemagick.org/download/releases/).

(Buildpack developer note: the config setting does not show up in the compile script as an environment variable, and has to be read from a file in `$3`, as explained in the [Heroku buildpack docs](https://devcenter.heroku.com/articles/buildpack-api#bin-compile-summary).)
12 changes: 11 additions & 1 deletion bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ echo "-----> Install ImageMagick"

BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
VENDOR_DIR="$BUILD_DIR/vendor"
mkdir -p $VENDOR_DIR
INSTALL_DIR="$VENDOR_DIR/imagemagick"
mkdir -p $INSTALL_DIR
IMAGE_MAGICK_VERSION="${IMAGE_MAGICK_VERSION:-6.9.5-10}"
if [ -d $ENV_DIR ]; then
Copy link

Choose a reason for hiding this comment

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

Could we collapse this conditional and the one two lines down together into a single -f test? I think that would also make it so we only have to specify the default version once.

Copy link
Author

Choose a reason for hiding this comment

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

I did run it on a live app, and it worked to install the right version of ImageMagick. But the app failed because ImageMagick requires some version-specific configuration setup that I couldn't figure out how to add via the buildback. So I ended up using a different approach (Linux 'file' command instead of 'identify') and abandoned this direction.

Copy link

@bf4 bf4 Jan 17, 2018

Choose a reason for hiding this comment

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

like

[ -f "${ENV_DIR}/IMAGE_MAGICK_VERSION" ] && export "IMAGE_MAGICK_VERSION=$(cat "${ENV_DIR}/IMAGE_MAGICK_VERSION")"
IMAGE_MAGICK_VERSION="${IMAGE_MAGICK_VERSION:-6.9.5-10}"

I wrote a function for this:

load_env_vars() {
  local env_var; env_var="${1:-}"
  until [ -z "$env_var" ]; do [ -f "$ENV_DIR/$env_var" ] && export "$env_var=$(cat "$ENV_DIR/$env_var")"; shift ; env_var="${1:-}" ; done
}
load_env_vars "IMAGE_MAGICK_VERSION" "OTHER_THING"

ENV_FILE="$ENV_DIR/IMAGE_MAGICK_VERSION"
if [ -f $ENV_FILE ]; then
IMAGE_MAGICK_VERSION="`cat $ENV_FILE`"
else
IMAGE_MAGICK_VERSION="6.9.5-10"
fi
else
IMAGE_MAGICK_VERSION="6.9.5-10"
fi
CACHE_FILE="$CACHE_DIR/imagemagick-$IMAGE_MAGICK_VERSION.tar.gz"

if [ ! -f $CACHE_FILE ]; then
Expand Down