Multiple apps on heroku from the same git repository

Inspired by https://devcenter.heroku.com/articles/multiple-environments

I have 3 version of the same app running on heroku. The difference between each versions is the demo group that the app is using (teens, moms and fashion).

To make deployments easy, I wanted to push to all three apps from the same git repo.

Here are the steps to get this working.

1. Go to your local folder where the app files are located.

2. Make sure you’re logged in to heroku, then create your three apps:

heroku create --remote [name_of_your_app]  // app_demo1

This will automatically create a git connection with a remote named “heroku”. Go ahead and rename that to a more descriptive name:

git remote rename heroku [your_descriptive_remote_name] 

Repeat this for all three of your apps (or however many you have). To check your remote repos, run:

git remote -v

3. Create config variables for each app, so they can act as your settings

heroku config:add CONF_VAR_NAME=var_value --app [name_of_your_app] 
// in my case DEMO_NAME=teens

Then run “heroku config –app [name_of_your_app]” to make sure the variables are set

4. In your app code, use heroku environment config variables where needed:

var demo = process.env.DEMO_NAME; 

The output will show: DEMO_NAME => teens

5. Now you should be ready for deployment! Commit your changes and push to your remote:

git push [your_descriptive_remote_name] master

And that’s it! This will initiate the deployment on heroku.

To check logs for your app, just run:

heroku logs --app [name_of_your_app]
Advertisements

Node.js session variables not working (get lost) on heroku

Ahhh… so this issue took me a while to figure out and caused some frustration: I use session variables in my node.js app, and locally everything working perfectly fine. However, on heroku, some mysterious behavior was taking place: sometimes session vars were preserved and working OK, but sometimes they would just get blank/undefined, and there was no pattern to this madness!

I took a few steps to troubleshoot this:
1) Moved from memorystore to Mongo DB session store, as recommended for production environment
2) Opened up Charles (network monitoring tool) to make sure all requests were processed, since I’m switching a parameter in my app and updating my session variable via AJAX call
3) Took a hard, long look at my heroku logs and found that I had TWO web processes running! So if I set a variable with one process, then the page reload is done by another web process, of course all session info gets lots (however, I’m still thinking since it’s Mongo storage it should have preserved the session vars).

Here’s a snapshot of the log where you can see the root of the issue:

2012-07-12T21:00:12+00:00 app[web.2]: new demo set: teens
2012-07-12T21:00:12+00:00 app[web.2]: demo: teens 
//session var preserved on same web.2 process 

2012-07-12T21:00:17+00:00 app[web.2]: new demo set: moms
2012-07-12T21:00:17+00:00 app[web.1]: demo: undefined 
//aha! web.1 has no idea what it is

For now, the app is working as expected, phew. However, I’m going to look more into why the values are not being read from Mongo and how this can still work when multiple processes are running (for the scaled up version of the app)

NYTM > July 2012 Meetup Notes

Three favorite demos:

  • Twilio Bot: super cool! Robot on wheels controlled by dialing into a Twilio number
  • Get Instinct: learn to play guitar, great live demo with a real guitar plugged into the Mac. I would absolutely use it. Wonder how well it would work with advanced levels
  • Social Bicycles: ZipCar for bikes. Custom-made heavy duty bikes equipped with GPS and controller.

I noticed that the coolest things (in my opinion) are not web or mobile apps anymore, but actual real life objects and interactions tied to digital world. So inspired to build a physical thing connected to an API.

Full lineup NYTM website

LiveStream webcast

Import/export of Mongo DB to Mongolab

So today I decided it’s time for the app to be live on the internets!

First off, I migrated the app to heroku (pretty straightforward process, instructions can be found here: https://devcenter.heroku.com/articles/nodejs and I wrote about migration to Heroku/Mongolab my post)

Then, of course, needed to migrate the existing local mongo database to Mongolab.

Step 1: export your local mongo database using mongodump:

In terminal, find your mongo directory and run

./mongodump or bin/mongodump

This will create a directory “dump” with all existing databases and collections

Note: if you only need to export certain databases or collections, read up the instructions on the mongo site

Step 2: import your dumped db files to Mongolab:

bin/mongorestore -h .mongolab.com: -d  -u  -p  dump/

The values for db name, port, app id can be easily found through Mongolab admin console:

As you see, once imported, your collections will be listed in the admin console.