2016-03-24 22 views
6

Sto lavorando su un progetto piccolo nodojs (nodejs v4.3) che utilizza node-serialport https://github.com/voodootikigod/node-serialport. L'ho avvolto in un'immagine docker. Per prima cosa ho usato debian con successo come immagine base ma aveva una dimensione totale di circa 600 MB. Poi sono passato a Alpine linux https://hub.docker.com/_/alpine/ e ho raggiunto 100 MB di dimensione dell'immagine. Tuttavia il progetto nodejs ha smesso di funzionare con Alpine come immagine di base. Qui ci sono alcuni tronchi:node-serialport non riuscito su linux alpino

Installare log nodo-serialport:

> [email protected] install /app/node_modules/serialport 
> node-pre-gyp install --fallback-to-build 

[serialport] Success: "/app/node_modules/serialport/build/Release/node-v46-linux-x64/serialport.node" is installed via remote 
[email protected] node_modules/serialport 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] ([email protected]) 
├── [email protected] 
└── [email protected] ([email protected], [email protected]) 

Quando provo ad aprire una porta seriale ottengo un errore:

npm ERR! Linux 3.19.0-30-generic 
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start" 
npm ERR! node v4.3.0 
npm ERR! npm v2.14.12 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] start: `node ./bin/www` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] start script 'node ./bin/www'. 
npm ERR! This is most likely a problem with the app package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  node ./bin/www 
npm ERR! You can get their info via: 
npm ERR!  npm owner ls app 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  /app/app/npm-debug.log 
module.js:435 
    return process.dlopen(module, path._makeLong(filename)); 
       ^

Error: Error relocating /app/app/node_modules/serialport/build/Release/node-v46-linux-x64/serialport.node: __strcpy_chk: symbol not found 
    at Error (native) 
    at Object.Module._extensions..node (module.js:435:18) 
    at Module.load (module.js:344:32) 
    at Function.Module._load (module.js:301:12) 
    at Module.require (module.js:354:17) 
    at require (internal/module.js:12:17) 
    at Object.<anonymous> (/app/app/node_modules/serialport/serialport.js:14:25) 
    at Module._compile (module.js:410:26) 
    at Object.Module._extensions..js (module.js:417:10) 
    at Module.load (module.js:344:32) 

Come ho detto, con Debian come base di immagine ha funzionato. Penso che potrebbe essere correlato al fatto che in Alpine Linux manca qualcosa su cui il nodo-serialport dipende. Ho creato un problema su https://github.com/voodootikigod/node-serialport/issues/682 ma non sono sicuro che questo sia un problema con node-serialport o con alpine linux. Ho letto che node-pre-gyp è in buggy su Alpine/busybox.

+0

hai provato ad installare un pacchetto come 'build-essentials' in ubuntu? – ArsalanDotMe

+0

@ArsalanDotMe yes, make e g ++ –

risposta

6

https://github.com/voodootikigod/node-serialport/pull/710

alpino è una (molto) piccola distro, ma utilizza la libreria standard MUSL invece di glibc (che la maggior parte delle altre distribuzioni Linux usano), in modo che richiede la compilazione.

# If you don't have node/npm already, add that first 
sudo apk add --no-cache nodejs 

# Add the necessary build and runtime dependencies 
sudo apk add --no-cache make gcc g++ python linux-headers udev 

# Then we can install serialport, forcing it to compile 
npm install serialport --build-from-source=serialport 

L'ho provato. Risolve il problema.

+3

Sì, è anche nel README - https://github.com/voodootikigod/node-serialport#alpine-linux –

0

Questo ha funzionato per me, in esecuzione alpino Linux in un contenitore Docker:

npm install serialport --unsafe-perm --build-from-source=serialport