如何在Heroku上运行二进制文件

我有一个简单的node.js应用程序,在我的OSX开发环境中运行良好。 但是,当我把相同的代码推到Heroku,我得到undefined返回在意想不到的地方。

行为不可预知的图书馆被称为pandoc 。 它转换文档格式。 我使用包装程序包node-pdc将其集成到我的节点应用程序中。 Pdc需要安装pandoc,但是它接受一个path来指定pandoc的位置,我在本地做这个工作,效果很好。 我在本地机器上全局卸载了pandoc,以确保我指向可执行文件的正确位置。

这完全符合预期的地方:

 var pdc = require('pdc'); var path = require('path'); var fs = require('fs'); var Q = require('q'); // optional, if pandoc is not in PATH pdc.path = path.resolve(__dirname +'/pandoc/1.15.0.6/bin/pandoc'); module.exports.mdToHtml = function (input, callback) { //TEST pdc('## Emerson', 'markdown', 'html', ['--template=smashingtemplate'], function(err, result){ console.log(result); // <h2>Emerson</h2> }); ... 

但在Heroku上,我在日志中看到了undefined的内容。 它不会抛出任何错误。 为什么它在我的笔记本电脑上工作,而不是在Heroku上?

这两个环境都运行节点v4.0.0

更新1:我testing了看看在Heroku上是否有pandoc …

 $ heroku run bash ~ $ ls /app/pandoc/1.15.0.6/bin/ pandoc ~ $ /app/pandoc/1.15.0.6/bin/pandoc --version bash: /app/pandoc/1.15.0.6/bin/pandoc: cannot execute binary file: Exec format error ~ $ ls /app/pandoc/1.15.0.6/bin/ -lah total 73M drwx------ 2 u35911 dyno 4.0K Jun 5 04:48 . drwx------ 4 u35911 dyno 4.0K Jun 5 04:48 .. -rwx------ 1 u35911 dyno 73M Jun 5 04:48 pandoc 

二进制文件在那里。 但我不能跑他们…

更新2

 ~ $ objdump -i /app/pandoc/1.15.0.6/bin/pandoc BFD header file version (GNU Binutils for Ubuntu) 2.24 elf64-x86-64 (header little endian, data little endian) i386 elf32-i386 (header little endian, data little endian) i386 elf32-x86-64 (header little endian, data little endian) i386 a.out-i386-linux (header little endian, data little endian) i386 pei-i386 (header little endian, data little endian) i386 pei-x86-64 (header little endian, data little endian) i386 elf64-l1om (header little endian, data little endian) l1om elf64-k1om (header little endian, data little endian) k1om elf64-little (header little endian, data little endian) i386 l1om k1om plugin elf64-big (header big endian, data big endian) i386 l1om k1om plugin elf32-little (header little endian, data little endian) i386 l1om k1om plugin elf32-big (header big endian, data big endian) i386 l1om k1om plugin pe-x86-64 (header little endian, data little endian) i386 pe-i386 (header little endian, data little endian) i386 plugin (header little endian, data little endian) srec (header endianness unknown, data endianness unknown) i386 l1om k1om plugin symbolsrec (header endianness unknown, data endianness unknown) i386 l1om k1om plugin verilog (header endianness unknown, data endianness unknown) i386 l1om k1om plugin tekhex (header endianness unknown, data endianness unknown) i386 l1om k1om plugin binary (header endianness unknown, data endianness unknown) i386 l1om k1om plugin ihex (header endianness unknown, data endianness unknown) i386 l1om k1om plugin elf64-x86-64 elf32-i386 elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little i386 elf64-x86-64 elf32-i386 elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 ---------- ---------- elf64-little l1om ------------ ---------- ------------ ---------------- -------- ---------- elf64-l1om ---------- elf64-little k1om ------------ ---------- ------------ ---------------- -------- ---------- ---------- elf64-k1om elf64-little plugin ------------ ---------- ------------ ---------------- -------- ---------- ---------- ---------- elf64-little elf64-big elf32-little elf32-big pe-x86-64 pe-i386 plugin srec symbolsrec verilog tekhex binary ihex i386 elf64-big elf32-little elf32-big pe-x86-64 pe-i386 ------ srec symbolsrec verilog tekhex binary ihex l1om elf64-big elf32-little elf32-big --------- ------- ------ srec symbolsrec verilog tekhex binary ihex k1om elf64-big elf32-little elf32-big --------- ------- ------ srec symbolsrec verilog tekhex binary ihex plugin elf64-big elf32-little elf32-big --------- ------- ------ srec symbolsrec verilog tekhex binary ihex 

和…

 ~ $ uname -a Linux 7f4e1d74-8fc2-47d2-89b7-97bfc9db30dd 3.13.0-85-generic #129-Ubuntu SMP Thu Mar 17 20:50:15 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux 

我可能没有正确理解,但看起来他们都是64架构。

 ~ $ file /app/pandoc/1.15.0.6/bin/pandoc /app/pandoc/1.15.0.6/bin/pandoc: Mach-O 64-bit x86_64 executable 

更新3

遵循@ mbs1的build议…

 Creating a relocatable binary ----------------------------- It is possible to compile pandoc such that the data files pandoc uses are embedded in the binary. The resulting binary can be run from any directory and is completely self-contained. cabal install hsb2hs # a required build tool cabal install --flags="embed_data_files" citeproc-hs cabal configure --flags="embed_data_files" cabal build You can find the pandoc executable in `dist/build/pandoc`. Copy this wherever you please. 

当我做cabal build它说:

 cabal: No cabal file found. Please create a package description file <pkgname>.cabal 

我无法使用任何需要cabal的解决scheme。 我终于得到它使用stack (一旦我想出了如何得到它安装)。

$ stack install pandoc --flag pandoc:embed-data_files

然后,我将生成的exec文件从vm中拷贝出来,并推送到Heroku。

您需要在与Heroku完全相同的操作系统上构build一个可重定位的pandoc二进制文件,因此,如果您使用的是Mac OS X,则需要安装Ubuntu Linux系统(如果将其安装在虚拟机中),请遵循本文或本文 。 基本上下面应该创build一个可重定位的二进制文件:

 stack install pandoc --flag pandoc:embed_data_files 

或者,您也可以使用Docverter ,这是一种pandoc作为服务。

你在本地运行OSX。 Heroku在Ubuntu Linux上运行。 这些体系结构不是二进制兼容的。