Skip to content

Instantly share code, notes, and snippets.

@martinmidtsund
Last active April 3, 2017 09:52
Show Gist options
  • Save martinmidtsund/7672052 to your computer and use it in GitHub Desktop.
Save martinmidtsund/7672052 to your computer and use it in GitHub Desktop.
Script for deploying a Meteor.js application to Heroku. The script will create a new application on Heroku with the given APPNAME, and add a MongoHQ addon, with the Sandbox plan(free plan with 512 MB MongoDB). It will then deploy your Meteor.js app to heroku.
#!/bin/bash
# Deploy script for Meteor.js to Heroku
#
# Author: Martin A. Midtsund / martin@iterate.no
#
# Before running this script, you need to have these tools in your path:
# meteor - To install: $ curl https://install.meteor.com | sh
# heroku - Install Heroku toolbelt and log in to your user: https://toolbelt.heroku.com/
# git - You'll get this in the Heroku toolbelt, if you don't already have it.
#
# Set name of your application here
APPNAME="YOUARPPNAME";
if [ ! -d ".meteor" ]; then
echo "ERROR: You need to run this script in a folder with a Meteor.js project";
exit 1;
fi
echo "Bundling your Meteor-app ...";
meteor bundle /tmp/bundle.tgz;
echo "Unpacking the bundle ...";
cd /tmp/;
tar -zxf bundle.tgz;
rm bundle.tgz > /dev/null;
# We have to remove fibers: http://docs.meteor.com/#deploying
# Heroku will run npm install and install it for us after deployment.
echo "Removing fibers ...";
rm -r bundle/programs/server/node_modules/fibers;
echo "Initiating git repository ...";
cd bundle/;
git init;
echo "Creating app on Heroku ...";
heroku create $APPNAME;
echo "Creating package.json ...";
cat << EOF > package.json
{
"name": "$APPNAME",
"version": "0.0.1",
"dependencies": {
"fibers": "1.0.1"
},
"engines": {
"node": "0.10.21",
"npm": "1.2.x"
}
}
EOF
echo "Creating Procfile ...";
echo "web: node main.js" > Procfile;
echo "Adding Heroku as git remote ...";
git remote add heroku git@heroku.com:$APPNAME.git;
echo "Adding mongohq-addon and setting MONGO_URL ...";
heroku addons:add mongohq:sandbox;
MONGOHQ_URL=$(heroku config:get MONGOHQ_URL);
heroku config:set MONGO_URL=$MONGOHQ_URL;
echo "Deploying app to Heroku ...";
git add .;
git commit -q -m "New version of the app. See Meteor repo for commit history.";
git push -f -q heroku master;
cd ..;
echo "Deleting bundle-folder ...";
rm -rf bundle/;
echo "Finished deployment. Go check out your awesome app at: $APPNAME.herokuapp.com";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment