Skip to content

Instantly share code, notes, and snippets.

@BigAlRender
Created August 24, 2022 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigAlRender/935bd05b4155a3d1bda275a8cc991b7e to your computer and use it in GitHub Desktop.
Save BigAlRender/935bd05b4155a3d1bda275a8cc991b7e to your computer and use it in GitHub Desktop.
libmagic config for ruby-filemagic gem
# NOTES
# Sample render-build.sh
#
# Symlinks libmagic and downloads headers. Then adds config so that Bundler can compile the native Gem
#
# Usage
# store in bin/render-build.sh
# chmod +x bin/render-build.sh
#
# Configure Render service to use as build command `./bin/render-build.sh`
#
# OR
# via render.yaml
# `buildCommand: "./bin/render-build.sh"`
# END NOTES
#!/usr/bin/env bash
# exit on error
set -o errexit
LIBMAGIC_DIR=$XDG_CACHE_HOME/libmagic
# Download/setup libmagic headers if it's not in the cache
if [[ ! -d $XDG_CACHE_HOME/libmagic ]]; then
echo "...Downloading libmagic headers"
mkdir -p $LIBMAGIC_DIR/include/file
wget -P $LIBMAGIC_DIR/include https://raw.githubusercontent.com/NetsoftHoldings/heroku-buildpack-magic/master/include/magic.h
wget -P $LIBMAGIC_DIR/include/file https://raw.githubusercontent.com/NetsoftHoldings/heroku-buildpack-magic/master/include/file/file.h
mkdir $LIBMAGIC_DIR/lib
ln -s /usr/lib/x86_64-linux-gnu/libmagic.so.1.0.0 $LIBMAGIC_DIR/lib/libmagic.so
else
echo "...Using libmagic from build cache"
fi
# Set a bundler config option with the path to the freeTDS directory
bundle config build.ruby-filemagic --with-magic-dir=$LIBMAGIC_DIR
# We always want these run
#bundle config set --local without 'development test'
bundle install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment