Deploy Multiple branch on Heroku - ruby-on-rails

I have a Heroku application that already deploy on Heroku (master-branch) in that I created new branch staging. The staging branch code are totally different with master. Now I want to deploy staging on Heroku but that will not affect on master. How can I do that?

You have to created separate applications on Heroku for each environment that you need. I typically create dev and staging using the free tier.
Here is blog post that walks you through the process:
http://agilewarrior.wordpress.com/2014/05/16/how-to-create-a-staging-environment-heroku/

You can run heroku buildpacks:clear -a yourAppName and redeploy the app.

Related

What is the flow of information when deploying an application on heroku servers?

According to what I have figured out..
Create local repo => add remote origin and PUSH to bitbucket =>create heroku =>push to heroku from master, from local repo and not from bitbucket
Please verify this flow.
You don't need this step - add remote origin and PUSH to bitbucket.
You add heroku as remote url to your git. You can read more about deployment process and what's going in official heroku doc - Deploying with Git.
Deploy a rails app to heroku is ideal. Just go through heroku official document here.
Hear I add some essential command, you need to run sequential, after push new changes to git repository.
> heroku login
> heroku create
> git push heroku master
> heroku run rake db:migrate
If you use Github then you can easily link your Heroku app with Github repo and all your Heroku code automatically pushed to Heroku.
This option is not available for BitBucket now.

Continuous Deployment

I am trying to setup continuous deployment for my Rails project. So far I have done following steps:
My app is on Github.
I have setup Travis CI.
I have created staging environment. (www.staging.myappname.com)
I have created prod environment. (www.myappname.com)
I have integrated Travis CI and Github.
What I am trying to achieve.
Someone creates a pull request.
Travis CI runs the build against pull request. (this part is done)
Once Pull request is merged into master branch then Travis CI run the test again. (this part is done)
If test is green then deploy master branch to staging environment. ( I can do this by adding deploy section to .travis.yml file.
Run test against staging environment, if test passes then deploy master branch to Production environment. ( I don't know how to achieve this part )
I am not sure if this is a right way to do it or not. I read couple of blog post and I noticed people creating different git branch for staging and production. Is this approach needed?
Also I can easily push my code to staging environment using Travis CI but I don't know how to run test again on staging environment and push code to production. What type of test shall I run against staging environment? Shall I only focus on selenium test for staging environment?
I can used tool like codeship but they offer only 100 build/month for free plan where as in Travis I can get unlimited build for free plan. This is the main reason for choosing Travis over codeship.
So my question:
Am I on right track?
What type of test shall I run against staging server?
how to deploy from staging to production using Travis CI?
Do I need staging.rb file in my rails app? If yes then how will it differ from production.rb file?
Do I need to create different git branch for staging and production? Currently I have only master branch which I am trying to deploy to both staging and production.
Usually people have 2 branches, one for staging/development which deploys on the staging server and one for production which deploys to the production branch
once your staging branch is tested and ready for deployment on production, you could create a pull request from staging to master (or just merge it locally and push it) and then the CI server should detect a new version on the master branch and then deploys it to the production server.

How to have Heroku build my development branch on a staging server?

I have a production application on master branch running all fine on heroku. I would like to run a second Heroku application but 'fed' from a local staging branch. These are the commands that i've run in my failed attempt to do this:
git checkout -b develop
heroku create --remote staging
git push staging develop
But because i'm pushing from a 'non master' branch it doesn't build the app;
remote: Pushed to non-master branch, skipping build.
I have read the managing multiple environments doc here; https://devcenter.heroku.com/articles/multiple-environments but it does not seem to address what I'm trying to achieve, rather merging develop branch into master first then pushing master to remote staging. I want to push my develop branch to a staging app and have it running live in RAILS_ENV=production mode, iteratively push to this live 'staging/testing' app then when i'm really comfy with what i'm going i'll merge the develop branch code into the master branch and push to the primary mast app.
Can anyone help me with how to achieve this?
as per heroku doc
git push staging develop:master
as per Git documentaion
git push <REMOTENAME> <LOCALBRANCHNAME>:<REMOTEBRANCHNAME>
so
git push heroku staging:master
means
push my staging local branch to master remote heroku branch
Its not as close to the most direct command line - but my DevOps pipeline using Codeship makes this much easier for commits on different branches.
I have Codeship automatically deploy anything to the dev branch to one Heroku app, anything in the staging branch to another, and anything to master to the live branch.
Not the direct solution you were probably looking for - but something that shows the benefits of a good CI setup!

Multiple Instances of an app on Heroku

I need to deploy several instances of the same app on heroku. It appears that I need to have a branch and local repo for each instance to deploy each instance to heroku via the cli. This just doesnt seem right.
Does anyone have any experience in this area?
You will need to have a git remote set up for each heroku app, but you can push to any remote from one local repo.
You can use the heroku git:remote command to set up multiple git remotes for your multiple heroku apps. Run that command with --help to see all the options, but this would create a git remote called staging for a heroku app named chunky-bacon-1234:
$ heroku git:remote -r staging -a chunky-bacon-1234
Then, if you wanted to deploy your local branch named my-experiment to that heroku app, you can push that branch to the remote's master branch:
$ git push staging my-experiment:master

Heroku as a private git repository

I am new to Heroku, as I understand heroku uses git to deploy our applications. i.e. I can push my changes to the heroku repository for deployment.
Can i use heroku as a test environment and private git repository at the same time? Is it possible?
Yes. You can push branches that are not master (which will not be deployed then). It might be a little slow at times.

Resources