Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing on AWS elastic beanstalk #51

Open
curtisnn opened this issue Aug 17, 2018 · 2 comments
Open

Installing on AWS elastic beanstalk #51

curtisnn opened this issue Aug 17, 2018 · 2 comments

Comments

@curtisnn
Copy link

curtisnn commented Aug 17, 2018

Not sure where to put this, as it isn't an issue, just some lessons learned of what I did to get hummus-recipe to work within a NodeJS instance on AWS elastic beanstalk. Hopefully it saves someone some time. There may be advice for handling it better, which I would appreciate.

To install the package I simply ran npm install --save hummus-recipe

When I then deployed to amazon AWS, I got an error when it was trying to install npm that looked like this: (visible in var/log/eb-activity.log)

> [email protected] install /tmp/deployment/application/node_modules/hummus
> node-pre-gyp install --fallback-to-build
  
  node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v57 ABI, glibc) (falling back to source compile with node-gyp) 
  node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/hummus/binding' 
  gyp ERR! configure error 
  gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/hummus/build'

It seems that node-pre-gyp is run as the default user rather than root so didn't have the ability to mkdir. See:

To provide permissions I added a .ebextensions config file: 01_npmrc.config (make sure indentation is correct for YAML file)

files:
    # This is the npm user config file path.
    "/tmp/.npmrc":
        mode: "000755"
        owner: root
        group: root
        content: |
            # Force npm to run node-gyp also as root, preventing permission denied errors
            unsafe-perm=true

When I submitted this change, it was able to install npm but crashed my server with the error here:

stack: 
   [ 'Error: Cannot find module \'jpgjs\'',
     '    at Function.Module._resolveFilename (module.js:513:15)',
     '    at Function.Module._load (module.js:463:25)',
     '    at Module.require (module.js:556:17)',
     '    at require (internal/module.js:11:18)',
     '    at /var/app/current/node_modules/utif/UTIF.js:10:74',
     '    at Object.<anonymous> (/var/app/current/node_modules/utif/UTIF.js:911:3)',
     '    at Module._compile (module.js:612:30)',
     '    at Object.Module._extensions..js (module.js:623:10)',
     '    at Module.load (module.js:531:32)',
     '    at tryModuleLoad (module.js:494:12)',
     '    at Function.Module._load (module.js:486:3)',
     '    at Module.require (module.js:556:17)',
     '    at require (internal/module.js:11:18)',
     '    at Object.<anonymous> (/var/app/current/node_modules/jimp/dist/utils/image-bitmap.js:22:36)',
     '    at Module._compile (module.js:612:30)',
     '    at Object.Module._extensions..js (module.js:623:10)' ] }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

AWS kept trying to restart node, so this message continually popped up. (as seen in /var/log/nodejs/nodejs.log. I checked the node_modules folder on the ec2 instance and sure enough the jpgjs folder was missing. This package is required by the utif library used by hummus which is used by hummus-recipe as shown in the package-lock.json after installing hummus-recipe

"utif": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/utif/-/utif-2.0.0.tgz",
      "integrity": "sha512-9fl1Md7tUTsgjhWCLOra+nalQnDxWme+h0OB7WQsUBZbhrxEmzL6/suCPxI4ujrFAvv6KSu7B/74HhxfydVpfw==",
      "requires": {
        "jpgjs": "github:makr28/jpgjs#c83f107ad725b476a3441d20680a02590d8752cc",
        "pako": "^1.0.5"
      },
...
"jpgjs": {
      "version": "github:makr28/jpgjs#c83f107ad725b476a3441d20680a02590d8752cc",
      "from": "github:makr28/jpgjs"
    },

I am uncertain as to why it didn't install that package? However, to solve that issue, I downloaded the jpgjs folder from https://github.com/makr28/jpgjs and added it to a libs folder in my own repository. Then I added this postinstall script (within the scripts section of package.json) to copy the folder to node_modules.

"postinstall": "cp -R libs/jpgjs node_modules"

Perhaps not so elegant a solution ... but alas, it deploys to AWS elastic beanstalk without any issues! Yay!

@chunyenHuang
Copy link
Owner

@curtisnn Thanks for sharing. Since I always use docker so I havent seen this issue before. It's good to know. I have added this to FAQ in wiki page

@nikodunk
Copy link

nikodunk commented Feb 2, 2019

For anyone else running in to this permission issue, I solved this on Elastic Beanstalk with this solution script mentioned above or with more detail at ember-fastboot/fastboot-aws#4 (comment) and nothing else – didn't need the postscripts. Didn't run into the jpjs crash described above.

The NPMRC trick from https://stackoverflow.com/questions/46001516/beanstalk-node-js-deployment-node-gyp-fails-due-to-permission-denied/46001517#46001517 didn't solve the permission trick on EB for me, but didn't try it separate from the Elastic Beanstalk script in the paragraph above so can't be 100% sure that it had no effect.

Dockerization didn't solve the permission issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants