Skip to content

Instantly share code, notes, and snippets.

@suthariy
Forked from etiennea/01.config
Created August 18, 2017 01:09
Show Gist options
  • Select an option

  • Save suthariy/b80f79227f5157b9c9b85bceed7d5f87 to your computer and use it in GitHub Desktop.

Select an option

Save suthariy/b80f79227f5157b9c9b85bceed7d5f87 to your computer and use it in GitHub Desktop.

Revisions

  1. @etiennea etiennea created this gist Mar 29, 2014.
    46 changes: 46 additions & 0 deletions 01.config
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    packages:
    yum:
    git: []
    gcc: []
    make: []
    openssl-devel: []
    ImageMagick: []

    option_settings:
    - option_name: NODE_ENV
    value: production
    - option_name: DB_NAME
    value: voice
    - option_name: NODE_ENV
    value: production
    - namespace: aws:elasticbeanstalk:container:nodejs
    option_name: NodeVersion
    value: 0.10.26

    files:
    "/opt/elasticbeanstalk/env.vars" :
    mode: "000775"
    owner: root
    group: users
    source: https://s3.amazonaws.com/myapp/env.vars
    "/opt/elasticbeanstalk/hooks/configdeploy/pre/50npm.sh" :
    mode: "000775"
    owner: root
    group: users
    source: https://s3.amazonaws.com/myapp/50npm.sh
    "/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh" :
    mode: "000775"
    owner: root
    group: users
    source: https://s3.amazonaws.com/myapp/50npm.sh
    "/opt/elasticbeanstalk/hooks/configdeploy/pre/50npm.sh" :
    mode: "000666"
    owner: root
    group: users
    content: |
    #no need to run npm install during configdeploy
    "/opt/elasticbeanstalk/hooks/appdeploy/pre/40install_node.sh" :
    mode: "000775"
    owner: root
    group: users
    source: https://s3.amazonaws.com/myapp/40install_node.sh
    33 changes: 33 additions & 0 deletions 40install_node.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/bin/bash
    #source env variables including node version
    . /opt/elasticbeanstalk/env.vars

    function error_exit
    {
    eventHelper.py --msg "$1" --severity ERROR
    exit $2
    }

    #UNCOMMENT to update npm, otherwise will be updated on instance init or rebuild
    #rm -f /opt/elasticbeanstalk/node-install/npm_updated

    #download and extract desired node.js version
    OUT=$( [ ! -d "/opt/elasticbeanstalk/node-install" ] && mkdir /opt/elasticbeanstalk/node-install ; cd /opt/elasticbeanstalk/node-install/ && wget -nc http://nodejs.org/dist/v$NODE_VER/node-v$NODE_VER-linux-$ARCH.tar.gz && tar --skip-old-files -xzpf node-v$NODE_VER-linux-$ARCH.tar.gz) || error_exit "Failed to UPDATE node version. $OUT" $?.
    echo $OUT

    #make sure node binaries can be found globally
    if [ ! -L /usr/bin/node ]; then
    ln -s /opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/node /usr/bin/node
    fi

    if [ ! -L /usr/bin/npm ]; then
    ln -s /opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/npm /usr/bin/npm
    fi

    if [ ! -f "/opt/elasticbeanstalk/node-install/npm_updated" ]; then
    /opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/ && /opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/npm update npm -g
    touch /opt/elasticbeanstalk/node-install/npm_updated
    echo "YAY! Updated global NPM version to `npm -v`"
    else
    echo "Skipping NPM -g version update. To update, please uncomment 40install_node.sh:12"
    fi
    19 changes: 19 additions & 0 deletions 50npm.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #!/bin/bash
    . /opt/elasticbeanstalk/env.vars
    function error_exit
    {
    eventHelper.py --msg "$1" --severity ERROR
    exit $2
    }

    #install not-installed yet app node_modules
    if [ ! -d "/var/node_modules" ]; then
    mkdir /var/node_modules ;
    fi
    if [ -d /tmp/deployment/application ]; then
    ln -s /var/node_modules /tmp/deployment/application/
    fi

    OUT=$([ -d "/tmp/deployment/application" ] && cd /tmp/deployment/application && /opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/npm install --production 2>&1) || error_exit "Failed to run npm install. $OUT" $?
    echo $OUT

    7 changes: 7 additions & 0 deletions env.vars
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    export HOME=/root
    export NPM_CONFIG_LOGLEVEL=error
    export NPM_CONFIG_PRODUCTION=true
    export NODE_VER=0.10.26
    export ARCH=x64
    export PATH="$PATH:/opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/:/root/.npm"
    export NODE_PATH=/usr/bin/node