sentry-cli: Protect against spawn of CLI for wrong architecture

Problem

The CLI is rarely used standalone. In most cases, it is executed via intermediates like the Sentry Webpack plugin.

When the CLI is installed via npm, it will run an install script that downloads a binary for the current architecture.

There are scenarios, when the architecture where the CLI eventually runs differs from the one npm install was executed from.

E.g.

  • A Dockerfile that will simply copy the local node_modules into the container
  • Any other deployment methods that will simply ship the bundle to the destination system including node_modules

This can lead to a rather obscure error when the binary is executed/spawned: #0 26.19 Sentry CLI Plugin: spawn Unknown system error -8. I could reproduce this problem by running npm install @sentry/nextjs on an M1 Mac before running the application in Docker (Alpine).

The problem was reported by other users as well and we didn’t come up with a solution proposal yet:

Quick fix

The problem can be solved by running

  • npm uninstall <sentry_module_that_installs_the_CLI_as_dep>
  • followed by npm install <sentry_module_that_installs_the_CLI_as_dep> as part of the deployment on the target system.

For a next.js application running in Docker, this would mean adding the following to the Dockerfile:

RUN npm uninstall -S @sentry/nextjs
RUN npm install -S @sentry/nextjs

# Further commands below, like:
# RUN npm run build

This ensures that the right binary is downloaded for the target system.

Product improvement

Sentry should detect that the binary doesn’t match the current architecture and provide an actionable error message to the user. E.g.

Wrong architecture detected while trying to execute the Sentry CLI. Please make sure to do a fresh npm uninstall/install step for @sentry modules on the target system.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 22 (7 by maintainers)

Most upvoted comments

Changing

COPY --from=deps /app/node_modules ./node_modules
COPY . .

to

COPY . .
COPY --from=deps /app/node_modules ./node_modules

fixes the issue and you don’t need to remove and install sentry again

Another option, without swapping copy/install is to add .dockerignore file and ignore node_modules there. This way docker won’t copy that dir.

#.dockerignore
node_modules

@samueldusek this is more for the purpose of triaging the problem. If it works in Docker then, this means that the right CLI can be installed and something just prevents this from happening. Would you mind posting the respective Dockerfile?

@samueldusek In your Dockerfile, try adding

RUN npm uninstall --save @sentry/nextjs
RUN npm install --save @sentry/nextjs

This works for me as it will make sure that you get the right CLI for the platform your container runs on.