github / safe-settings

ISC License
607 stars 147 forks source link

Permission denied when building Docker image #362

Closed martinm82 closed 1 year ago

martinm82 commented 1 year ago

Problem Description

What is actually happening

When running docker-compose I get an error that the build cannot access /opt/safe-settings when installing the npm packages.

I think the issue has been introduced with the recent root/user changes in the Dockerfile. In my opinion the fix is to run the build process as root and change only after the npm install command to the node user.

What is the expected behavior

Building the Docker image should be successful.

Error output, if available

npm WARN deprecated @types/pino-pretty@5.0.0: This is a stub types definition. pino-pretty provides its own type definitions, so you do not need this installed.
npm WARN deprecated @types/pino-std-serializers@4.0.0: This is a stub types definition. pino-std-serializers provides its own type definitions, so you do not need this installed.
npm WARN checkPermissions Missing write access to /opt/safe-settings
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^2.3.2 (node_modules/jest-haste-map/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN safe-settings@0.1.0-rc.26 No description

npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /opt/safe-settings
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/opt/safe-settings'
npm ERR!  [Error: EACCES: permission denied, access '/opt/safe-settings'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/opt/safe-settings'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/node/.npm/_logs/2022-12-13T15_59_49_444Z-debug.log

Context

Are you using the hosted instance of probot/settings or running your own?

self-hosted

If running your own instance, are you using it with github.com or GitHub Enterprise?

GitHub.com

Version of probot/settings

latest

Version of GitHub Enterprise

davyrod commented 1 year ago

@martinm82 I had the same issue. I added the following at line 8, right before USER node:

RUN mkdir /opt/safe-settings && chown -R node:node /opt/safe-settings

martinm82 commented 1 year ago

@davyrod, yes indeed. That was as well one thing I did. But reading the Probot docs they actually state that one should use the node user to run the application only. It does not state you should use it for the installation process.

But changing permissions might be indeed the better approach as there might be during runtime other permission denied errors if some files are owned by root.

martinm82 commented 1 year ago

@davyrod I have applied the fix and created a pull request: https://github.com/github/safe-settings/pull/384

@decyjphr could you please take a look. Thanks

aakash-pinc commented 1 year ago

@martinm82 @decyjphr Can you merge the Pull Request #384?