I wanted to convert png images to webp alternatives in travis but Travis CI uses quite old ubuntu version 12.04 so the bundled imagemagick wasn't really up to date:
$ convert -version
Version: ImageMagick 6.6.9-7 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
I know that I can use sudo: required
to use travis in virtual machine and install and build things over there. Instead I would like to use the containerized build environment with sudo: false
because it's much faster.
If I try to compile libwepb
or imagemagick
travis gives me permission denied errors because I don't have permissions to /usr/local/
folder:
$ make install
...
/bin/mkdir -p '/usr/local/include/webp'
/bin/mkdir: cannot create directory `/usr/local/include/webp': Permission denied
...
The command "make install" failed and exited with 2 during .
Travis allows users to change $PATH
and install binaries into $HOME
directory.
Here's complete example for ruby. It only compiles the binaries once and caches them. It only installs them again if the version numbers don't match.
language: ruby
sudo: false
dist: precise
cache:
directories:
- "$HOME/opt"
addons:
apt:
packages:
- libjpeg-dev
- libpng-dev
- libgif-dev
env:
global:
- IMAGEMAGICK_VERSION: '7.0.3-10'
- LIBWEBP_VERSION: '0.5.1'
# Install newer libwebp and imagemagick
before_install:
# Update PATH so that travis can find newer imagemagick
- export PATH=$HOME/opt/bin:$PATH
# Checks if Imagemagick is already sufficient version
# If not installs it from the sources
- convert -version | grep $IMAGEMAGICK_VERSION || {
export CORES=$(nproc) &&
echo "Using $CORES cores for compiling..." &&
cd /tmp &&
curl -O https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-$LIBWEBP_VERSION.tar.gz &&
tar xvzf libwebp-$LIBWEBP_VERSION.tar.gz &&
cd libwebp-* &&
./configure --prefix=$HOME/opt &&
make -j$CORES &&
make install -j$CORES &&
cd /tmp &&
curl -O https://www.imagemagick.org/download/ImageMagick-$IMAGEMAGICK_VERSION.tar.gz &&
tar xvzf ImageMagick-$IMAGEMAGICK_VERSION.tar.gz &&
cd ImageMagick-* &&
./configure --prefix=$HOME/opt &&
make -j$CORES &&
make install -j$CORES &&
$HOME/opt/bin/magick -version | grep $IMAGEMAGICK_VERSION &&
cd $TRAVIS_BUILD_DIR; }
# Update library paths for programs
- export LD_FLAGS=-L$HOME/opt/lib
- export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:$HOME/opt/lib
- export CPATH=$CPATH:$HOME/opt/include
Credits: I looked how this ruby library installs libwebp
and figuring out the rest was easy: https://github.com/le0pard/webp-ffi/blob/master/.travis.yml