Rails3 & Git & Heroku - development/staging server - ruby-on-rails

I have a Rails 3 app I'm developing with a team using Git/Github and deploying to a Heroku cedar stack. Our Github respository has 2 main branches Master and Development.
I would like to push our Development branch regularly to a different server on Heroku as a development/staging environment.
What's the cleanest simplest way to push our Development branch to a different app than Master without disrupting our Git flow much?
Thanks a lot!

You'll want to add a second git remote i.e. your second application's heroku git repo url to your app to be able to push to that from a single codebase.
At the moment you probably have the default remote origin named 'heroku' which is pushing to your production application.
You'll want to add a second remote origin pointing at your new heroku app that you intend to use for staging, eg
git remote add staging <git repo url from 'my apps' page on heroku>
once you have the new git origin set up you can push to it via;
git push staging <branch to deploy>:master

Simple. Heroku always uses the master branch, but using Git will allow you to push /your/ development branch, to /their/ master
For instance:
git push heroku development:master
where heroku is your origin for your heroku development env, and development is your local development branch. You might also want to override the RACK_ENV var on Heroku too if you don't want your dev branch running in production mode (although, personally I would create a staging environment in your code which does caching etc, but not send email to production addresses etc)

heroku_san is a Gem which allows complex deploy configurations when using Heroku, without the need to constantly specify which Heroku app you wish to push to on the command line. It would allow you to do exactly what you describe above.

Related

The page you were looking for doesn't exist

I'm trying to learn Rails ( developpment beginner here )
When I try to deploy my first app on Heroku and execute $ heroku open I got
"The page you were looking for doesn't exist.”
In my Heroku control pannel I also have a second link who works, http://secret-refuge-2130.herokuapp.com/, but different from localhost.
Here's my first app https://github.com/Freysh/first_app
As Michael Hartl propose "Unfortunately, the resulting page is an error; as of Rails 4.0, for technical reasons the default Rails page doesn’t work on Heroku. The good news is that the error will go away (in the context of the full sample application) when we add a root route in Section 5.3.2."
You need to work on the Root route of your routes.rb in config folder.
Looks like you haven't pushed your repo to Heroku yet?
Since you're new, let me give you some ideas about how Heroku works, and how you can deploy your app to it...
Heroku
When you use Heroku, you basically get a bare git repo which you can push your application to. This repo will essentially allow you to use the following commands:
> $ git add .
> $ git commit -a -m "Your App"
> $ git push heroku master
This is, of course, only possible if you have added your heroku repo to your local remote repositories:
> $ git remote add heroku https://heroku.com/......
When you push your local repo to your Heroku one, Heroku then runs what's known as a buildpack:
When you git push heroku, Heroku’s slug compiler prepares your code
for execution by the Heroku dyno manager. At the heart of the slug
compiler is a collection of scripts called a buildpack.
Heroku’s Cedar
stack has no native language or framework support; Ruby, Python, Java,
Clojure, Node.js and Scala are all implemented as buildpacks.
This means that when you push your app to your repo, Heroku will endeavour to compile & run it for you. This is when the app will run.
Fix
To fix, you should follow the tutorial here
Basically, you need to get your git repo created locally, which will then provide you with the ability to push to your remote heroku repo

Heroku push to production

I set up my staging and production environments on heroku, and pushed to both and it worked fine. I came back a day later and was able to push to staging but got the following message about git push production master:
fatal: 'production' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
To confirm where each remote points to, login to Heroku and open the settings to your app and then match the git URL of the app to the ones displayed by git remote -v. Then, if necessary, add a remote for production (i.e. heroku).

How to set up an additional server in Heroku?

I want to set up a new Heroku server for QA purposes.
I've done most of the pieces but I've missed something:
1) I made a new app using the CLI Heroku toolbelt:
heroku apps:create myapp-qa
2) I made a copy of the existing git repostory on my local machine:
git clone git#github.com:me/myapp.git
3) Added the remote for the aq server:
git remote add myapp-qa git#github.com:myrepo/myapp.git
3) I then tried to push my new app with:
cd myapp
git push myapp-qa master
I got the message "already up-to-date"
4) If I go to the app in a browser to http://myapp-qa.herokuapp.com/ it says "Heroku | Welcome to your new app!" instead of showing any of my application pages.
What did I miss?
Heroku has a plugin specifically designed for this.
https://github.com/heroku/heroku-pipeline
It allows you to specify a "pipeline" of servers
Dev -> Staging -> Production and allows you to deploy to dev, then promote that build to staging, then promote that to production.
Setup needed to be:
git remote add myapp-qa git#heroku.com:myapp-qa.git
git push origin myapp-qa

heroku staging or new app in heroku for staging?

What are thoughts around creating a staging environment for my app or should i create a second app on heroku for staging? Which one is better, or preferred?
Thanks.
Second app - add the git remote of the new app to your repo so you can deploy to it from a single code base.
Read more at https://devcenter.heroku.com/articles/multiple-environments

Deploying to Heroku with sensitive setting information

I'm using GitHub for code and Heroku for the deployment platform for my rails app.
I don't want to have sensitive data under Git. Such data include database file settings (database.yml) and some other files that have secret API keys.
When I deploy to heroku, how can I deal with files that are not under revision control.
When I use Capistrano, I can write some hook methods, but I don't know what to do with Heroku.
For Heroku, you'll need to have database.yml under Git because Heroku will automatically read it and create a PostgreSQL configuration from it.
For other sensitive information such as API keys, Heroku provide config vars which are effectively environment variables. You can add them using:
heroku config:add KEY=value
—and access them from within your application using:
ENV['KEY']
Note that config vars can be listed, added and removed using the heroku command-line program and that once set they are persistent.
Heroku Config Vars documentation
I would create a local branch, let's call it SECRET, and make the 'secret' modifications there. Commit them and DO NOT push them to github.
Now just checkout and keep working on the master branch till ready to release.
To prepare the release checkout the SECRET branch, merge the master branch into it, and push it to heroku as usual.
(BTW : I always forget to switch back to the work branch, git stash is your friend in this case)

Resources