Skip to content

Instantly share code, notes, and snippets.

@markudevelop
Forked from wearhere/deploy_aws.sh
Created December 23, 2016 10:11
Show Gist options
  • Save markudevelop/1104bdc43f1074985f70a86da82479ac to your computer and use it in GitHub Desktop.
Save markudevelop/1104bdc43f1074985f70a86da82479ac to your computer and use it in GitHub Desktop.
CI script to convert a Meteor application into a Node.js application then deploy it to AWS Elastic Beanstalk.
#!/bin/bash
#
# This script will convert a Meteor application into a Node.js application
# then deploy it to AWS Elastic Beanstalk.
#
# Run like `deploy_aws.sh my_eb_app my_eb_app-production`.
#
# That will deploy the Meteor application containing this script
# to the `my_eb_app-production` environment of the `my_eb_app` EB application.
# Propagate errors
set -e
# Compile CSS here if necessary.
# compass compile
# Install/update Node modules. (They'll be copied into the bundle. Native modules will be flagged
# to be rebuilt on AWS when we npm install on AWS (via the custom npm install .ebextension);
# that's the only thing that `npm install` will do on AWS.)
meteor npm install
meteor npm update
# Convert Meteor into a node application. Note the --architecture flag is correct for the platform
# that we are deploying to. We build the app outside Meteor's directory since we'll have to create
# a Git repository to deploy (see below).
meteor build --directory ../meteor-build/ --architecture os.linux.x86_64
# Copy over the Beanstalk config files.
cp -r .ebextensions ../meteor-build/bundle
# Copy over our settings. (If you don't have settings just remove the next few lines.)
cp ./settings.json ../meteor-build/bundle/settings.json
# Patch Meteor's startup file to load the settings as the first thing it does. Need to make it writable first.
chmod +w ../meteor-build/bundle/main.js
echo -e "process.env.METEOR_SETTINGS = require('fs').readFileSync('settings.json', 'utf8');" \
"\n$(cat ../meteor-build/bundle/main.js)" > ../meteor-build/bundle/main.js
# Use the new source code to deploy to Beanstalk
cd ../meteor-build/bundle
# Beanstalk requires a git repository to deploy, so create one here. We don't need to commit ALL the
# files because that takes a little longer. We can simply stage them.
git init && git add README && git commit -m "deploy" && git add .
# initialize the EB CLI tool. Use the parameters to select which Beanstalk application and environment to deploy to
eb init $1 --platform node.js --region us-east-1
eb use $2
eb deploy --staged --timeout 40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment