我想将png图像转换为travis中的webp替代品,但Travis CI使用相当旧的ubuntu版本12.04,因此捆绑的imagemagick并不是最新的:
$ 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
我知道我可以使用sudo: required
在虚拟机中使用travis并在那里安装和构建东西。相反,我想将容器化的构建环境与sudo: false
一起使用,因为它更快。
如果我尝试编译libwepb
或imagemagick
,则由于我没有/usr/local/
文件夹的权限,因此travis会向我提供权限拒绝错误:
$ 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 .
答案 0 :(得分:1)
Travis允许用户更改$PATH
并将二进制文件安装到$HOME
目录中。
这是ruby的完整示例。它只编译二进制文件并缓存它们。如果版本号不匹配,它只会再次安装它们。
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
致谢:我查看了这个ruby库如何安装libwebp
并弄清楚其余内容很简单:https://github.com/le0pard/webp-ffi/blob/master/.travis.yml