Question

I'm creating a webservice and I want to store the source on github and run the app on heroku. I haven't seen my exact scenario addressed anywhere on the 'net so far, so I'll ask it here:

I want to have the following directory structure:

/project
  .git
  README <-- project readme file
  TODO.otl <-- project outline
  ... <-- other project-related stuff
  /my_rails_app
     app
     config
     ...
     README <-- rails' readme file 

In the above, project corresponds to http://github.com/myuser/project, and my_rails_app is the code that should be pushed to heroku. Do I need a separate branch for the rails app, or is there a simpler way that I'm missing?

I guess my project-related non-rails files could live in my_rails_app, but the rails README already lives there and it seems inconsistent to overwrite that. However, if I leave it, my github page for the rails app will contain the rails readme, which makes no sense.

Also ... I tried just setting it up as described above and running

git push heroku

from the main project folder. Of course, heroku doesn't know I want to deploy the subfolder:

-----> Heroku receiving push
 !     Heroku push rejected, no Rails or Rack app detected.
Was it helpful?

Solution

Here's a simple solution that may or may not work for you.

  • Create two projects on GitHub. One project should be just the Rails app (i.e. everything inside the Rails app directory). The other project should be everything outside the Rails app directory.

  • Add the Rails app project as a git-submodule within the "container" project.

  • Now you can add Heroku as a remote on the Rails app repository separately and push it to heroku. Heroku will accept the push because it is just a Rails app with the expected directories and files.

OTHER TIPS

A solution for the Heroku situation (not the README file):

If you're using the new Heroku Cedar (I believe it wasn't available when you first asked your question) then your processes (like the rails server process) start up using Foreman. Thus, you can place a Procfile in the root github directory that looks like this:

web:     my_rails_app/script/runserver.sh

And then my_rails_app/script/runserver.sh could be a simple

#!/bin/sh

cd my_rails_app
bundle exec rails server -p $PORT

Locally, you should also create a file called .env (note the . at the beginning), which contains

PORT=3000

This file is read by foreman and used to set environment variables so that the port is set when you execute foreman start on your machine (from the root github directory, where the Procfile lies). The Heroku server takes care of the .env file on your dyno. The big advantage is you can set up multiple processes on the dyno that way!

Just overwrite Rails' default README file. There's no reason to keep it around. Put your other project-management-related stuff in the doc directory. While you certainly have valid reasons for wanting to set it up the way you did, you're just creating a headache for yourself by going against convention, and it's probably not worth the benefit.

I would add everything underneath /my_rails_app to the Heroku git repository. Then add GitHub as a remote and add everything underneath /project to the GitHub repository. Then you can push the Rails application to Heroku (from /my_rails_app) and push the full project to GitHub (from /project).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top