GithubHelp home page GithubHelp logo

sharpred / better-faster-elastic-beanstalk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kopurando/better-faster-elastic-beanstalk

0.0 2.0 0.0 52 KB

Collection of hooks for AWS Elastic Beanstalk node.js containers designed to dramatically increase deployment speeds, avoid unnecessary rebuilding of node_modules, install any version of node.js, install global NPM modules and more.

Shell 100.00%

better-faster-elastic-beanstalk's Introduction

better-faster-elastic-beanstalk

This collection of hooks for AWS Elastic Beanstalk node.js containers that was designed to dramatically reduce deployment times, avoid unnecessary rebuilding of node_modules, install any version of node.js, install global NPM modules and more.

This project demonstrates several tweaks to the standard node.js Elastic Beanstalk configuration to significantly reduce deployment times by avoiding unnecessary rebuilds of node_modules.

Main features

  1. Install ANY desired node.js version as per your env.config (including the most recent ones that are not yet supported by AWS EB) โ€” control your node.js version to avoid surprises with sudden AWS updates or compatibility issues.
  2. Avoid rebuilding existing node modules, including in-app node_modules dir โ€” dramatically speed up deployment.
  3. Install node.js globally (and any desired module as well), if your use-case requires so.

Please see the original discussion on StackOverflow to grasp the concept: http://stackoverflow.com/questions/21200251/avoid-rebuilding-node-modules-in-elastic-beanstalk

NOTE: this respo is way ahead of the StackOverflow thread, and heavily customised for my own use-case. It still works as a charm though and saves a lot of time on each deployment. Feel free to look around, be inspired and find solutions for your problems in my code, but it is essential to fork this repo and adapt it for your own needs.

Usage

Put .ebextensions/example_env.config into your project .ebextensions dir and read through the file to get a grasp of its mechanics.
example_env.config from this repo does following:

  • installs bunch of packages (such as ImageMagick, git, tmux, mosh etc.);
  • fills option settings with default values (I strongly recommend NOT to put any passwords here, even in a private repo, and instead set them via instances profiles jsons, see docs here http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html);
  • fetches all *.sh hooks from this public repo. You can (and should) replace them with your own hooks from your private repos of course;
  • sets up simple PhantomJS proxy via nginx config modification;
  • injects z.sh (for admin comfort);
  • sets up logging io.server...

... and much much more. We used these hooks in our production and it worked bulletproof (unless github went down :). Chances are, you won't need 90% of functionality we developed, so please refer to the original SO thread for more ideas and less sophisticated config for generic use-cases:

http://stackoverflow.com/questions/21200251/avoid-rebuilding-node-modules-in-elastic-beanstalk

Principle of action

We use .ebextensions/example_env.config to replace default AWS deploy & config hooks with customized ones (all *.sh files, see detais below). Also, in a default EB container setup some env variables are missing ($HOME for example) and node-gyp sometimes fails during rebuild because of that (took me 2 hours of googling and reinstalling libxmljs to resolve it).

Below are the files to be included along with your build. You can inject them via env.config as inline code or via source: URL (as in example_env.config from this repo)

env.vars: desired node version & arch are included here and in `env.config, see below;

40install_node.sh: fetch and ungzip desired node.js version, make global symlinks, update global npm version,

50npm.sh: creates /var/node_modules, symlinks it to app dir and runs npm install. You can install any module globally from here, they will land in /root/.npm.

*you can add more .sh hooks for your needs: see 55phantomjs_restart.sh and 46update_geolitecity.sh for examples.

env.config: note node version here too, and to be safe, put desired node version in env config in your AWS console as well. I'm not 100% certain which of these settings will take precedence.

There you have it: on t1.micro instance deployment now takes 20-30 secs instead of 10-15 minutes! If you deploy 10 times a day, this tweak will save you 3 (three) weeks in a year. Hope it helps and special thanks to AWS EB staff for my lost weekend :)

##todo

  • remove (rename) and rebuild node_modules in case NodeJS or npm version gets changed

better-faster-elastic-beanstalk's People

Contributors

kopurando avatar sharpred avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.