node-bunyan icon indicating copy to clipboard operation
node-bunyan copied to clipboard

Issue with node:8-alpine image

Open Kostanos opened this issue 6 years ago • 7 comments

Using node:8-alpine docker image, and on installing bunyan got the error:

> [email protected] install /node_modules/dtrace-provider
> node-gyp rebuild || node suppress-error.js

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.15.0-42-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 /node_modules/dtrace-provider
gyp ERR! node -v v8.11.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 

Is it possible to use the library without python dependency?

Kostanos avatar Dec 18 '18 18:12 Kostanos

For those who has the same issue, you'll need to add python and make packages before installing bunyan:

apk add python make

Kostanos avatar Dec 18 '18 18:12 Kostanos

I had same issue.. installing python and it starts complaining about pkg-config, and then about libsecrets.. This is what worked finally.

RUN apk update && apk add --no-cache python2 make g++ pkgconfig libsecret-dev
ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig

rnarayana avatar Jul 12 '20 17:07 rnarayana

IMO, This is not a great solution. Putting a compiler compiler and an unnecessary scripting language runtime into a container that is meant to host a web-service is just asking for trouble, not to mention introducing a bunch of overhead.
Is there a way to just remove the dtrace-provider dependency?

rrichardson avatar Nov 02 '20 17:11 rrichardson

@rrichardson If you don't care about the optional dependencies (meaning dtrace-provider which is what wants python, mv, or moment) then you can install with the --no-optional flag see https://github.com/trentm/node-bunyan#installation

But this does present a problem when installing in a Dockerfile as if you do a npm install --no-optional anything else you are using will also have any optional dependencies excluded (maybe that's ok for your use case though).

One way to get around this is you could put bunyan in your devDependencies then install using the --production flag first and then bunyan it by itself with the --no-optional flag in your Dockerfile which would still allow local development happen outside of the container like usual and no error in the container.

For instance if you have a package.json like

{
  "name": "bunyan-alpine-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "dotenv": "^8.2.0"
  },
  "devDependencies": {
    "bunyan": "1.8.14"
  }
}

For example the following Dockerfile doesn't get upset

FROM node:8-alpine
COPY package.json package.json
RUN npm install --production && npm install bunyan --production -no-optional
COPY index.js index.js
CMD ["node", "index.js"]

zlintz avatar Nov 03 '20 04:11 zlintz

@zlintz - Thanks. This is essentially what I ended up doing. I'm using typescript, so it ended up being a bit more complicated than this, but the idea is the same.

rrichardson avatar Nov 03 '20 17:11 rrichardson

@rrichardson Good to hear, do you mind sharing your approach for typescript for myself and others?

zlintz avatar Nov 03 '20 17:11 zlintz

It follows that same multi-step process, but it relies on npm prune --production after the typescript compile.

We use yarn, yarn install prunes by default, so if you're running npm, then run npm prune --production instead of the yarn cmd.

(bunyan installed as a dev dependency)
ADD all your stuff
RUN yarn
RUN npx tsc -b
RUN yarn --production --ignore-optional --ignore-scripts  # npm prune --production 
RUN yarn add bunyan --production --ignore-optional 

I also supply --ignore-scripts because we have a postinstall script which runs some utilities that leverage ts-node which is no longer available after the --production pruning.

rrichardson avatar Nov 03 '20 18:11 rrichardson