getsentry / sentry-cli

A command line utility to work with Sentry.
https://docs.sentry.io/cli/
BSD 3-Clause "New" or "Revised" License
896 stars 222 forks source link

Cannot install inside a docker container #281

Closed gonfva-bcl closed 6 years ago

gonfva-bcl commented 6 years ago

When I try to install sentry-cli inside a docker container, I get the following error:

Error: spawn /node_modules/@sentry/cli/sentry-cli ENOENT
npm WARN enoent ENOENT: no such file or directory, open '/package.json'
npm WARN !invalid#1 No description
npm WARN !invalid#1 No repository field.
npm WARN !invalid#1 No README data
npm WARN !invalid#1 No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @sentry/cli@1.30.3 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @sentry/cli@1.30.3 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/2018-04-03T16_33_43_838Z-debug.log
The command '/bin/sh -c npm install @sentry/cli' returned a non-zero code: 1

Tested with the following Dockerfile

FROM keymetrics/pm2:latest
RUN npm install @sentry/cli

on Docker version 1.11.2, build bac3bae (CoreOS) and Docker version 17.12.0-ce, build c97c6d6 (Mac)

(I understand the WARN are related not having a package.json)

It may be a docker issue, but it is not clear to me how to debug and the mac version is quite recent.

gonfva-bcl commented 6 years ago

Apparently, using a different image

FROM keymetrics/pm2:latest-slim
RUN npm install @sentry/cli

It seems to run OK.

This suggests there is a need for some library.

JalilArfaoui commented 6 years ago

I have the same problem (initially on the webpack-plugin, so I created an issue there : https://github.com/getsentry/sentry-webpack-plugin/issues/44), but it seems to be related to the cli :

This simple Dockerfile does not work :

FROM docker:latest
RUN apk --update add --no-cache nodejs yarn
RUN yarn add @sentry/cli

Output :

✘  ~/code/tmp/test-sentry  docker build .
Sending build context to Docker daemon 14.34kB
Step 1/3 : FROM docker:latest
---> cf0bbd4500c6
Step 2/3 : RUN apk --update add --no-cache nodejs yarn
---> Running in ea8efb65baa7
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
(1/10) Installing nodejs-npm (8.9.3-r1)
(2/10) Installing c-ares (1.13.0-r0)
(3/10) Installing libcrypto1.0 (1.0.2o-r0)
(4/10) Installing libgcc (6.4.0-r5)
(5/10) Installing http-parser (2.7.1-r1)
(6/10) Installing libssl1.0 (1.0.2o-r0)
(7/10) Installing libstdc++ (6.4.0-r5)
(8/10) Installing libuv (1.17.0-r0)
(9/10) Installing nodejs (8.9.3-r1)
(10/10) Installing yarn (1.3.2-r0)
Executing busybox-1.27.2-r7.trigger
OK: 65 MiB in 22 packages
Removing intermediate container ea8efb65baa7
---> e3954dde4012
Step 3/3 : RUN yarn add
---> Running in 0ccf32704425
yarn add v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
error /node_modules/: Command failed.
Exit code: 1
Command: node scripts/install.js
Arguments:
Directory: /node_modules/
Output:
fetching sentry-cli-Linux-x86_64 1%
fetching sentry-cli-Linux-x86_64 2%
...
fetching sentry-cli-Linux-x86_64 99%
fetching sentry-cli-Linux-x86_64 100%
Error: spawn /node_modules//sentry-cli ENOENT
The command '/bin/sh -c yarn add ' returned a non-zero code: 1
✘  ~/code/tmp/test-sentry 

But if I try this one, it works fine :

FROM node
RUN yarn add @sentry/cli

So I agree this must be some dependency problem ...

JalilArfaoui commented 6 years ago

OK, new test :

This Dockerfile does not work either :

FROM node:alpine
RUN yarn add @sentry/cli

So Alpine is missing a lib that Debian has ...

JalilArfaoui commented 6 years ago

I suggest we should rename this issue "Cannot install on Alpine Linux"

JalilArfaoui commented 6 years ago

I found this issue which seems to be the same problem :

https://github.com/getsentry/sentry-cli/issues/70

But I understand that it will not be fixed :-(

JalilArfaoui commented 6 years ago

This issue also seems to relate to the same source problem :

https://github.com/getsentry/sentry-cli/issues/227

I understand from this one that there is a work in progress (last january) to support sentry-cli on Alpine distributions ....

I also understand that there is a workaround using SENTRYCLI_CDNURL, but I'm not sure how ...

JalilArfaoui commented 6 years ago

Oh ! I understand that @mrmckeb uses the sentry-cli Docker image to get the binary, host it somewhere and the point to that somewhere with SENTRYCLI_CDNURL in order for the npm package to find the binary !

But this is too much complexity for me to add in our CI ...

jan-auer commented 6 years ago

Thank you both for providing a detailed analysis of your problem. As you've already mentioned, we do not distribute an alpine-compatible (i.e. musl) sentry-cli binary, apart from the Docker image.

It is still planned to provide such a build. However, I cannot give you a timeline on this right now until we have some time to look at 32-bit builds.

227 is the correct place to continue discussion, so I am going to close this issue for now. Feel free to reopen if you see fit.

tonyo commented 6 years ago

FYI, should be fixed for version 1.31.0, more details here: https://github.com/getsentry/sentry-cli/issues/227#issuecomment-386641791

batjko commented 5 years ago

@tonyo Doesn't seem to be fixed with 1.46.0, getting this error inside my node:10-alpine image. :/

tonyo commented 5 years ago

@batjko just checked, the following command works for me:

docker run --rm node:10-alpine sh -c 'yarn add @sentry/cli@1.46.0 && ./node_modules/.bin/sentry-cli'

What are you trying to do and what kind of error are you getting?

batjko commented 5 years ago

What are you trying to do and what kind of error are you getting?

Tried to use it as part of the webpack plugin, to send my sourcemaps up to Sentry during build.

Similar error as OP above: Error: spawn /app/node_modules/@sentry/cli/sentry-cli ENOENT

I've gotten around it now by saving the pre-compiled binary in my project and copying it into the folder where it was expected, inside my Dockerfile after the yarn install step, i.e.:

COPY sentry-cli /app/node_modules/@sentry/cli/

This works fine, but is ugly as hell.

tonyo commented 5 years ago

@batjko There also might be a problem with the webpack plugin 🤔 It would be helpful if you could share a minimal reproducible example for when it fails for you, e.g., a Dockerfile.