Level / levelup

A wrapper for abstract-leveldown compliant stores, for Node.js and browsers.
MIT License
4.09k stars 267 forks source link

Docker node:8.5.0-alpine #484

Closed lagden closed 7 years ago

lagden commented 7 years ago

Hi...

I have 2 Dockerfiles very similar in my project (you can see below) Using node:8.5.0 works fine

But using node:8.5.0-alpine I've got this error: Segmentation fault

I tried this: npm i --silent --build-from-source --progress=false --production in alpine... unsuccessfully 😞

I discovered that:

Alpine uses musl instead of glibc, and therefore binaries built with gcc for glibc will be binary incompatible, as far as I'm aware.

Is there anyway for the levelup to work on the node:alpine?

Tks!

node                8.5.0-alpine                 67MB
node                8.5.0                        673MB

node:8.5.0 (Debian)

FROM node:8.5.0

# cria o usuário tex
RUN useradd -ms /bin/bash tex

# seta as variáveis de ambiente
ENV HOME=/home/tex
ENV APP=$HOME/consulta-cep

# cria a pasta do app
RUN mkdir $APP

# copia o package.json e ajusta as permissões
COPY package.json $APP/.
RUN chown -R tex:tex $HOME

# troca de usuário (tex) e instala os pacotes
USER tex
WORKDIR $APP
RUN npm i --silent --build-from-source --progress=false --production

# troca de usuário (root), copia os arquivos do app, ajusta as permissões e deleta o usuário node
USER root
COPY . $APP
RUN chown -R tex:tex $APP
RUN userdel -r node

# troca de usuário (tex), libera a porta 3000 e roda o comando
USER tex
EXPOSE 3000
CMD ["npm", "start"]

node:8.5.0-alpine

FROM node:8.5.0-alpine

# instala o bash e cria o usuário tex
RUN apk add --no-cache bash
RUN addgroup tex && adduser -s /bin/bash -D -G tex tex

# seta as variáveis de ambiente
ENV HOME=/home/tex
ENV APP=$HOME/consulta-cep

# cria a pasta do app
RUN mkdir $APP

# copia o package.json e ajusta as permissões
COPY package.json $APP/.
RUN chown -R tex:tex $HOME

# troca de usuário (tex) e instala os pacotes
USER tex
WORKDIR $APP
RUN npm i --silent --progress=false --production

# troca de usuário (root), copia os arquivos do app, ajusta as permissões e deleta o usuário node
USER root
COPY . $APP
RUN chown -R tex:tex $APP
RUN deluser --remove-home node

# troca de usuário (tex), libera a porta 3000 e roda o comando
USER tex
EXPOSE 3000
CMD ["npm", "start"]
jstabenow commented 7 years ago

Same problem with levelup@1.3.9 and 2.0.0-rc2

FROM node:8.4-alpine
RUN npm install -g standard tape faucet levelup@1.3.9
WORKDIR /usr/local/lib/node_modules/levelup
RUN npm install && \
    standard && tape test/*-test.js | faucet
# approximateSize(): approximateSize() is deprecated
✓ approximateSize(): approximateSize() is deprecatedcatedSegmentation fault
not ok 2 no plan found
⨯ fail  1
christophjohannsdotter commented 7 years ago

You can easily reproduce this error on Docker node:8.4-alpine by calling node -e 'require("levelup")("test")' -> Segmentation fault

ralphtheninja commented 7 years ago

@jstabenow Thanks for an easy and reproducible Dockerfile!

This modified version triggers a rebuild, but get other errors due to missing python etc:

FROM node:8.4-alpine                                      
RUN npm install -g tape levelup@1.3.9                     
WORKDIR /usr/local/lib/node_modules/levelup               
RUN npm install --build-from-source && tape test/*-test.js
> leveldown@1.7.2 install /usr/local/lib/node_modules/levelup/node_modules/leveldown
> prebuild-install || node-gyp rebuild

prebuild-install info begin Prebuild-install version 2.2.2
prebuild-install info install --build-from-source specified, not attempting download.
gyp info it worked if it ends with ok
gyp info using node-gyp@3.6.2
gyp info using node@8.4.0 | linux | x64
gyp ERR! configure error 
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:483:19)
gyp ERR! stack     at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:397:16)
gyp ERR! stack     at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:68:16)
gyp ERR! stack     at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:80:29)
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/which/which.js:89:16
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/which/node_modules/isexe/index.js:42:5
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/which/node_modules/isexe/mode.js:8:5
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Linux 4.10.0-33-generic
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/levelup/node_modules/leveldown
gyp ERR! node -v v8.4.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
npm info lifecycle leveldown@1.7.2~install: Failed to exec install script
npm WARN bustermove@1.0.1 requires a peer of tap@2.x.x but none was installed.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! leveldown@1.7.2 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the leveldown@1.7.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2017-09-13T13_53_32_264Z-debug.log
ralphtheninja commented 7 years ago

@lagden leveldown is a devDependency of levelup so I'm guessing the following line will not trigger a rebuild of leveldown (because of --production flag)

RUN npm i --silent --build-from-source --progress=false --production
ralphtheninja commented 7 years ago

@lagden You could use level instead, which bundles levelup and leveldown and then --build-from-source should work fine.

christophjohannsdotter commented 7 years ago

I tried

/# npm install level --build-from-source --production --silent
+ level@1.7.0
updated 1 package in 5.079s
/# node -e 'require("level")("test")'
Segmentation fault

but it does not seem to work or did i get you wrong?

ralphtheninja commented 7 years ago

@christophjohannsdotter Hmm, did it actually build leveldown or not? I get this:

$ npm i level --build-from-source --production --silent
prebuild-install info begin Prebuild-install version 2.2.2
prebuild-install info install --build-from-source specified, not attempting download.
make: Entering directory '/home/lms/tmp/level-test2/node_modules/leveldown/build'
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/builder.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/db_impl.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/db_iter.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/filename.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/dbformat.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/log_reader.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/memtable.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/log_writer.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/repair.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/table_cache.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/version_edit.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/version_set.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/write_batch.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/helpers/memenv/memenv.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/port/port_posix_sse.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/table/block.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/table/block_builder.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/table/filter_block.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/table/format.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/table/iterator.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/table/merger.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/table/table.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/table/table_builder.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/table/two_level_iterator.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/arena.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/bloom.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/cache.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/coding.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/comparator.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/crc32c.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/env.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/filter_policy.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/hash.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/logging.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/options.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/status.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/port/port_posix.o
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/util/env_posix.o
  CXX(target) Release/obj.target/snappy/deps/snappy/snappy-1.1.4/snappy-sinksource.o
  CXX(target) Release/obj.target/snappy/deps/snappy/snappy-1.1.4/snappy-stubs-internal.o
  CXX(target) Release/obj.target/snappy/deps/snappy/snappy-1.1.4/snappy.o
  AR(target) Release/obj.target/deps/leveldb/leveldb.a
  COPY Release/leveldb.a
  AR(target) Release/obj.target/deps/snappy/snappy.a
  COPY Release/snappy.a
  CXX(target) Release/obj.target/leveldown/src/batch_async.o
  CXX(target) Release/obj.target/leveldown/src/batch.o
  CXX(target) Release/obj.target/leveldown/src/database.o
  CXX(target) Release/obj.target/leveldown/src/database_async.o
  CXX(target) Release/obj.target/leveldown/src/iterator.o
  CXX(target) Release/obj.target/leveldown/src/iterator_async.o
  CXX(target) Release/obj.target/leveldown/src/leveldown.o
  CXX(target) Release/obj.target/leveldown/src/leveldown_async.o
  SOLINK_MODULE(target) Release/obj.target/leveldown.node
  COPY Release/leveldown.node
make: Leaving directory '/home/lms/tmp/level-test2/node_modules/leveldown/build'
+ level@1.7.0
added 75 packages in 15.376s
christophjohannsdotter commented 7 years ago

Thank you! had to remove my old package first, then the rebuild from source worked. Level ist now working on alpine 👍

jstabenow commented 7 years ago

@ralphtheninja you are right. for building from source we need additional packages:

FROM node:8.4-alpine
RUN apk add --update python make g++ && \
    npm install -g standard tape faucet levelup@1.3.9
WORKDIR /usr/local/lib/node_modules/levelup
RUN npm install --build-from-source && \
    standard && \
    tape test/*-test.js | faucet

And the result:

# tests 137
# pass  137
✓ ok

Thanks!

ralphtheninja commented 7 years ago

Please re-open if something needs extra clarification.

lagden commented 7 years ago

@jstabenow and @ralphtheninja

Very thanks!