How to compile node.js module canvas on RedHat OpenShift servers?

℡╲_俬逩灬. 提交于 2019-12-10 11:51:46

问题


On RedHat OpenShift servers it is not possible to compile node.js module canvas, because there are missing cairo libraries for the linux, and related required libraries as well.


回答1:


This is how to make it compile:

export PATH=/sbin:$PATH:$OPENSHIFT_DATA_DIR/usr/local/bin
export LD_LIBRARY_PATH=$OPENSHIFT_DATA_DIR/usr/local/lib:/opt/rh/nodejs010/root/usr/lib64:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$OPENSHIFT_DATA_DIR/usr/local/lib/pkgconfig
cd $OPENSHIFT_DATA_DIR
curl -L http://sourceforge.net/projects/libpng/files/libpng16/1.6.17/libpng-1.6.17.tar.gz/download -o libpng.tar.gz
curl -L http://www.ijg.org/files/jpegsrc.v9a.tar.gz -o jpegsrc.tar.gz
curl -L http://www.cairographics.org/releases/pixman-0.32.6.tar.gz -o pixman.tar.gz  
curl -L http://public.p-knowledge.co.jp/Savannah-nongnu-mirror//freetype/freetype-2.5.5.tar.gz -o freetype.tar.gz
curl -L http://www.cairographics.org/releases/cairo-1.14.2.tar.xz -o cairo.tar.xz  
curl -L http://ftp.gnome.org/pub/GNOME/sources/pango/1.35/pango-1.35.3.tar.xz -o pango.tar.xz
curl -L http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.11.1.tar.gz -o fontconfig.tar.gz
curl -L http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-0.9.37.tar.bz2 -o harfbuzz.tar.bz2
curl -L http://ftp.gnome.org/pub/GNOME/sources/glib/2.34/glib-2.34.3.tar.xz -o glib.tar.xz
curl -L http://ftp.gnome.org/pub/GNOME/sources/pango/1.35/pango-1.35.3.tar.xz -o pango.tar.xz
cd $OPENSHIFT_DATA_DIR
gunzip libpng.tar.gz
tar -xvf libpng.tar
cd libpng-1.6.17/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
tar -zxf jpegsrc.tar.gz && cd jpeg-9a/
./configure --disable-dependency-tracking --prefix=$OPENSHIFT_DATA_DIR/usr/local 
make
make install
cd $OPENSHIFT_DATA_DIR
tar -zxf pixman.tar.gz && cd pixman-0.32.6/  
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local  
make
make install
cd $OPENSHIFT_DATA_DIR
tar -zxf freetype.tar.gz && cd freetype-2.5.5/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local  
make
make install
cd $OPENSHIFT_DATA_DIR
tar --xz -xvf cairo.tar.xz && cd cairo-1.14.2/
./configure --disable-dependency-tracking --without-x --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
tar -xvf fontconfig.tar.gz && cd fontconfig-2.11.1/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
bunzip2 harfbuzz.tar.bz2
tar -xvf harfbuzz.tar && cd harfbuzz-0.9.37/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
tar --xz -xvf glib.tar.xz && cd glib-2.34.3/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_DATA_DIR
tar --xz -xvf pango.tar.xz && cd pango-1.35.3/
./configure --prefix=$OPENSHIFT_DATA_DIR/usr/local
make
make install
cd $OPENSHIFT_REPO_DIR
scl enable nodejs010 v8314 'npm install canvas'   
rm -rf "${OPENSHIFT_NODEJS_DIR}/tmp/saved.node_modules"

To use these libraries in the node.js server, you need to add custom LD_LIBRARY_PATH entry which points to them:

In the OpenShift git project add directory: .openshift/markers In this directory create empty file named: use_npm

In the package.json file add this entry:

  "scripts": {
    "start": "export LD_LIBRARY_PATH=$OPENSHIFT_DATA_DIR/usr/local/lib:/opt/rh/nodejs010/root/usr/lib64:$LD_LIBRARY_PATH; supervisor server.js"
  }

This usually works, but sometimes there are happening npm update activities which start to rebuild canvas module.

Sometimes bcrypt module does not build too.

The solution is to create one gear, where everything just works, and then to make tar.gz file with the contents of $OPENSHIFT_DATA_DIR/usr/ and to transfer this file to your server where it is accessible via http://

That same should be done for node_modules/canvas, node_modules/bcrypt and other vulnerable entries.

Then, it is possible to use OpenShift app hooks (build, etc) to download and extraxt the contents of these files in the right places.

Also, you can compile many node_modules/xxxxx on the CentOS 6.6, and then to copy these in the right places on the server, which runs RHEL 6.6 (binary compatibility stuff, just like with rpm package installation)

This way it is possible to create git repository and downloadable tar.gz files which would allow to automatically launch new RedHat OpenShift gears.

Of course, if there will be some system upgrades, tar.gz files contents must be upgraded too.



来源:https://stackoverflow.com/questions/29728266/how-to-compile-node-js-module-canvas-on-redhat-openshift-servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!