Heroku not deploying from a different branch - heroku

I'm trying to deploy my heroku application using a different branch from master. When I run:
git push heroku <mybranch>
Nothing happens and my application is not deployed.
Does anybody know what's going on?
Thanks.

Heroku apps only use the master branch (although you can push any branches you want). If you really do want to deploy another branch, you have to push it into the master branch on the heroku remote:
git push heroku mybranch:master

Related

Heroku can't find package.json during build although I have it

When I push my node app to heroku master I get this log
remote: Building source:
remote:
remote: -----> App not compatible with buildpack: https://codon-
buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz
remote: Node.js: package.json not found in application root
I can't find the reason why this would happen as I clearly have in my root directory. I checked using git ls-files and it appears.
Is it possible that my application root is not the same as my repository root? How would one config that?
It seems that when I push to heroku master, heroku pushes the main branch of my local repository to heroku instead of the branch I'm currently in. So what I had to do was pushing with:
git push heroku mybranchname:master
so that my branch (not the master) gets pushed
One common issue is not having added the files to git.
You might be having package.json in your root directory on you device, without adding it to git, heroku can't find it.
Please check status to confirm and add if not added already
git status
git add .
then followed by the usual
git push heroku master assuming you are on the master branch.
Hope this helps.
I think just pushing a branch and not the master should fix it. If you do not have a branch, I suggest you create one and push with that.

Redeploy Heroku app without code changes

I would like to deploy a Heroku app which will be done ideally using git push -u heroku master. However this will only work if there are any pending commits to be pushed to master.
How can I redeploy the app while there is nothing to push ? I tried git push -u heroku master -f and still get the same below
Branch master set up to track remote branch master from heroku.
Everything up-to-date
PS: I also want to retain the existing app, which means I cannot make use of this answer https://stackoverflow.com/a/22043184/968442
Normally setting a config var causes your application to be restarted. In most situations there should be no need to redeploy after doing this.
If you really do need to trigger a new deployment you can add a new empty commit, then push to Heroku again:
git commit --allow-empty -m "Trigger Heroku deploy after enabling collectstatic"
git push heroku master
The new empty commit is a regular commit. It has a hash, an author, a timestamp, etc. It will have the same tree as its parent. This should cause Heroku to build your app slug again using the same code as the previous commit.
It's a bit awkward, but it works.
You can do it from UI as well!
Login to your Heroku dashboard and go to deploy section
Find Manual deploy option
Hit Deploy Branch button!
Note: you must have your app connected to GitHub for this option to be available (see comment from Derek below).
There is now also a plugin for the Heroku command-line that allows you to re-release the most recently deployed slug.
See https://www.npmjs.com/package/heroku-releases-retry
It turns out there is a neat plugin for Heroku called heroku release retry that lets you retry the last deploy without resorting to adding bad commits to your repository.
// install plugin
heroku plugins:install heroku-releases-retry
// retry release
heroku releases:retry --app {your-app}
Source: https://www.darraghoriordan.com/2019/03/02/heroku-push-failed-force-rebuild
You can run heroku restart --app app_name and you are good to go.
This worked for me, it did an actual build and release without any commit, contrary to one other post that only does a release:
heroku plugins:install heroku-builds
heroku builds:create --source-url https://user:token#api.github.com/repos/<username>/<repo name>/tarball/master/ --app <app-name>
Source: https://help.heroku.com/I3E6QPQN/how-do-i-force-a-new-deploy-without-adding-a-commit-to-my-github-repo
For stop the heroku app uses :
$ heroku ps:scale web=0
And for start it uses :
$ heroku ps:scale web=1

Managing Heroku Multiple environments with existing app

I've got an app, that has 'heroku' configured as a remote, to one application.
Let's call this app 'MyAppDev'
However, I have another app, called 'MyAppLive'
I want to configure deployment like this:
git push staging
push to MyAppDev
git push production
push to MyAppLive
How can I do this?
Also, what about environment variables?
Both apps have MongoLab, so I'd like the MyAppDev app to use it's own db....
Here are the steps that you'd need to follow
git remote rm heroku - this will remove the heroku remote from your application
git remote add production <production apps heroku git repo url> - this will add a new remote named 'production' pointing at the production apps git repo url (you can get this from the My Apps page on heroku.com
git remote add staging <staging apps heroku git repo url>
This now means you can do git push production master or git push staging master to push your codebase to either repo.
NOTE If you need to push branches to Heroku you need to push them into the master branch of Heroku.
eg. assuming a staging branch locally you would do;
git push staging staging:master
To push your locally staging branch into master of the staging remote.
Any addons you use would need to be duplicated to the staging application.
Config variables can either be done manually via heroku config:set or you can use the plugin detailed at the bottom of this page https://devcenter.heroku.com/articles/config-vars which allows you to push and pull your Heroku variables into a .env file suitable for running with Foreman locally. Becareful about overriding variables though - I tend to do my variables manually as I don't typically have many.

Upgrading from Heroku Bamboo stack to a Cedar stack

I am upgrading my app from Rails 3.0 to Rails 3.1. To do this I need to upgrade my Heroku stack to Cedar rather than Bamboo which is currently on.
I am going through the following tutorial
and am getting stuck at the part where I deploy git push heroku master. When I run this git assumes I am pushing to my Bamboo app, when I really want to deploy to my new Cedar stack.
PhotoRambler tonybeninate$ heroku apps
photoramblr
young-river-1492
young-river-1492 is my new Cedar app, but I have no idea how to deploy to it. Can anyone advise? Thanks.
Or do I need to delete my Bamboo stack first?
No, your .git/config still thinks heroku is your old application. If you crack open that file and edit the heroku remote then it will start pushing to the right place.
have you tried checking how you added your heroku repo for the new app? ie
git remote remove heroku #to remove the link to photoramblr
git remote add heroku git#heroku.com:young-river-1492.git # to add the new one
and then
git push heroku master
You might also want to remove your bamboo app once the new once is up, otherwise you'll need to specify what app for heroku commands ie:
#instead of
heroku rake db:migrate
#you'll have to do
heroku rake db:migrate --app young-river-1492
Check out this tutorial on migrating to the Cedar stack - specifically the part on creating a new Cedar app and deploying. You're on the right track - you just need to specify which app git should push to, since you now have more than once to choose from.
Find out what the remote is called for your new app
>git remote
Push to the new remote
>git push young-river-1492-heroku young-river-1492
You can also rename your remote with git remote rename.
If you prefer, you could edit your config file instead, ala Neil's answer, or edit the config after you've successfully pushed once with the long form to make sure it works.

Only allow 'git push heroku master' from the master branch

I recently set up dev/staging/production environment on OSX Lion. I have a git repo with a development and a master branch, and a Heroku instance with master and staging origins.
The basic workflow is to develop in the development branch, merge into master, deploy to staging, then finally deploy to production.
I'd like to prevent Heroku deployments when I'm in any branch that isn't master, or at a minimum display a warning (e.g. "Would you like to continue? y/n").
Is this possible? Is there a git or Heroku feature that facilitates this, or would I need to write a bash script?
From the Heroku documentation:
Branches pushed to Heroku other than master will be ignored.

Resources