Location of app when pushed to Heroku - ruby-on-rails

I have a Rails project under git.
The structure is:
SomeProject
-Docs
-Src
-Rails
Rails is the root of the rails application, but SomeProject is the root of the repo.
When I try and push to Heroku I get:
Heroku push rejected, no Cedar-supported app detected
So my questions are:
Would this be resulting because the rooot of the repo and the root of the Rails application are different?
If so is there a way I can tell Heroku where the root of the Rails application is?
If not what else would cause this problem?

This is not an ideal situation, especially for heroku, but the generally accepted solution is pretty straightforward. It will take a bit of work on your behalf, but nothing too bad.
Create two repositories, one for the rails app, and one for "SomeProject."
Add your rails app as a submodule to "SomeProject." You can add them pretty easily, using something like git submodule add git#github.com:user/rails_app/ rails. This will add the rails application as a submodule to your project, so it's essentially it's own repository. Find more information here.
Add heroku as a remote to the submodule, and when you want to deploy the app, push from the submodule, rather than the entire project.
This is not as easy as git push heroku master:'/rails', but nothing like that exists (yet, anyway).
Hope this helps!

The easiest solution is to split out your Rails application into its own repository, as andrewpthorp suggests.
Another solution is to write your own buildpack in a separate repository, based on heroku/heroku-buildpack-ruby but customized to support your alternate project layout, and use that to deploy your application.

Related

How to deploy a rails app to heroku using C9

I am trying to deploy my rails app to heroku. However, it seems that there is a long process to do. I have to change my db but I do not know how! I also want to know how to push to heroku please!
Thanks in advance!
I think you might be interested in Michael Hartl's tutorial where there is section on deploying to Heroku.
Remember that you will need Git before deploying to Heroku. There is good info on that in same tutorial here.
I hope this helps.
Read this instruction https://devcenter.heroku.com/articles/getting-started-with-rails4
I usually create a Git repo on GitHub or BitBucket and push my Rails project there. Then I go to Heroku website, manually create a new project there (in a dashboard) - and right after that step Heroku provides a detailed list of the Git commands describing how to pull your code from, say, GitHub.
After that you need to run migrations on Heroku - you can do that on your local machine in the console window - but you need to install Heroku CLI (locally) first.
That's it basically. After that Heroku starts your app automatically.
It is not required for you to deploy your code on GitHub or BitBucket. After you init a Git repo locally, you can directly push to Heroku Git. But I prefer use BitBucket as a convenient storage additionally.

Is there a way to let Rails push an internal repository to Github while its hosted?

Assume that I have a Rails project. I have published it on a server like Heroku. Think of it as a small app that have to update a git repository (a separate repository in its public folder). Is there a way to achieve this?
For example...
Think that i have some markdown files in my public folder. My rails app will give me an interface to edit these files. When the editing is over, I need to push these files to a git repository. Only that folder through a script in the Rails app.
You can either shell out to git:
Dir.chdir('/path/to/git/tree') do
system = "git commit -m'Updated by rails' -- #{name_of_file_to_commit}"
# Check $?, and do some appropriate error handling if it's != 0
end
Or you can use one of the several ruby Gems for interfacing with git. I am not familiar enough with them to recommend one; in any case, any recommendation will soon be out of date. It's best to do your own search, find candidate gems, and try them.

Can I update a single source file on Heroku without recompiling the slug?

I'm working on a rails project that's being hosted on Heroku.
I'm wondering if it's possible to update one file, without restarting the app.
Why. I have a bug, but I can't track it down. It works perfectly on my local system, but it seems to stop mid way through processing on heroku.
As there are no break points, I'm scattering status updates in the code. (to be removed later)
But adding one line of code to a rails app is like a five minute process.
change file
stage file to git
commit file
push git (all the above is quite fast)
wait for heroku to pull down the app, do what looks like a gem install, or at least a gem update.
change a few files to reflect the local url
start up the service again.
Is there a way to push the git without running all those other things? Perhaps a special parameter to add to the push?
A further annoyance is that my git now has a bunch of check-ins that I don't want my co-workers to see. I'm targeting a my own non-production instance of heroku (testing only) and there's no reason to include all these attempts in the global source control.
There's a good reason as to why it's not possible. When you push to Heroku, they produce a 'slug' of your application (https://devcenter.heroku.com/articles/slug-compiler). To provide the massive scalability that Heroku provides this slug is read only so that it can be spun up on multiple dynos which are likely to be distributed across many different physical machines. Each of these dynos runs a separate instance of your application whilst the routing mesh ensures that requests to your application goes to the correct dynos.
Now consider what would occur if any of these instances were writeable, if you're running 5 dynos you'd have your application running on 5 seperate instances - if a file is written how is it then distributed across of your running dynos? Yes, Heroku could have considered some kind of shared file system for running applications out of but that's complicated. By making the file system read only (https://devcenter.heroku.com/articles/read-only-filesystem) this problem is alleviated.
If you've built an app and deployed to Heroku but forgotten to use S3 type peristant storage your application will let you upload files to it (via Paperclip of such like in the Ruby world) but that uploaded asset will only exist on the dyno that received it and will then be lost when new code is deployed or the application restarted as the dyno receives the latest code from the slug.
If you're debugging against Heroku don't forget you've got the usual git arsenal available, git commit --amend. Alternatively work in a branch and deploy that to directly to Heroku (git push heroku <yourbranchname>:master) then when you've isolated the problem rebase (http://git-scm.com/book/en/Git-Branching-Rebasing) your branch onto master squashing any commits you no longer need.
XY Problem
This is a classic XY Problem. X is your non-working code; Y is your search for a non-existent Git misfeature.
How Git Works
Git commits fundamentally work at the tree level, not the file level. As a gross over-simplification, a commit points to a tree, which points to a set of files. When you push a commit, you have to push all the objects related to that commit unless the objects already exist on the receiver.
How Heroku Works
Heroku compiles the application in your Git repository into a slug. While you can ignore certain files during compilation, you can't avoid compiling the slug. That's just the way the platform works.
This is not a problem if you have a reasonable slug size; my Heroku apps only take a couple of seconds to compile. If your slugs are very large, and therefore take a long time to compile (you claim it takes you 5+ minutes), then you have another XY problem on your hands if you're trying to solve for "don't compile."
Debugging on Heroku
Heroku has lots of features and add-ons to aid debugging. Here's a short list to get you started.
interactive console sessions
logging
Exceptional Add-On
See Also
https://devcenter.heroku.com/articles/read-only-filesystem
https://devcenter.heroku.com/articles/dynos#ephemeral_filesystem
It's not possible. The way heroku is setup, every time you push up a change the server will restart.
Yes you can.
First, list all the files that have been modified since the last commit.
git status
Add the files you want to commit individually.
git add location/file_name.rb
git add location/file_name2.rb
...
Make commit to the files you added to push.
git commit -m "committing files one at a time or two at a time"
Now push
git push heroku

Heroku: Deploying rails application troubles

I'm trying to deploy my rails application with heroku (as shown here). I've created a very simple rails application (using ruby 1.9.2 and rails 3.0.3; i'm sure heroku supports these - see heroku docs), created and pushed github repo, created heroku repo and pushed it (all commiting is done). And when i'm trying to access my application controller, it throws 404 rails page like it's saying 'there is no such controller'. I've done heroku rake db:migrate but first time i ran it i got 'host not found' error. Running this again fixed that. Well, i'm not sure if i should run heroku addons add:postgresql - i though postgres is on by default, but heroku says i should pay in order to get DB (running command i've mentioned asks me to confirm billing it).
May be it sounds stupid, but how can i deploy my rails application (it's a very simple one) without paying any fees and such troubles as 404 pages like i mentioned in the beginning of my post? (and this is my question). Maybe i should choose other hosting (if it exists in our world) or am i doing something wrong with heroku?
You forgot to push your quotes_controller.rb to git and heroku probably.
git add controllers/quotes_controller.rb
it seems you forgot models also, and probably lot of files.

how to clone a project on heroku

I have a project on heroku working fine. Now I want to create same project with different url (same code) as the one I have working now. So that I can give the new url to the customer as a 'test' site. I know in heroku i can just rename the url but I want to completely separate development from test (database wise).
What is the best solution? Do I start from scratch? cd into new folder on my machine...clone project from github...make new database -test ...push to heroku...etc. etc.
Heroku toolbelt now provides a fork method to clone an existing application. It will duplicate your app with same source code, same database data and same add-ons.
Just type :
heroku fork --from sourceapp --to targetapp
https://devcenter.heroku.com/articles/fork-app
You should check out heroku_san, I designed it specifically for deploying multiple environments to Heroku easily. It also has grown to include a lot of other niceties you'll need to automate when dealing with multiple "apps" like sharing and auto migrating with restarts.
Once you have it setup it's as simple as:
rake production deploy
I'm using a method very similar to the one presented here:
http://jqr.github.com/2009/04/25/deploying-multiple-environments-on-heroku.html
What is the best solution? Do I start from scratch? cd into new folder on my machine...clone project from github...make new database -test ...push to heroku...etc. etc.
Yeah, I'd just make a copy (clone) of the repo, either from GitHub (if you have it up on GitHub) or the current Heroku location. Then start a new project in Heroku and push the cloned (and possibly modified) second site up to Heroku as that project.

Resources