Redeploy Heroku app without code changes - heroku

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

Related

heroku deployment error [Item could not be created: Unauthorized] [duplicate]

This post relates to a rapidly changing event.
I simply want to connect to my GitHub account. When I do it, I get this error message as a small red pop up on the upper right side of the page:
Items could not be retrieved, Internal server error.
As of May 25, 2022, at 19:52 UTC, GitHub integration has been re-enabled:
We are happy to report that the GitHub integration is re-enabled! You can now reconnect with GitHub and restore your Heroku pipeline functionality, including Review Apps, with newly generated tokens.
You can connect to GitHub immediately or wait for the enhanced integration as described in this blog post. To re-establish your GitHub connection now, please follow these instructions.
Here is what the referenced blog post says about "enhanced integration":
In an effort to improve the security model of the integration, we are exploring additional enhancements in partnership with GitHub, which include moving to GitHub Apps for more granular permissions and enabling RFC8705 for better protection of OAuth tokens. As these enhancements require changes by both Heroku and GitHub, we will post more information as the engagement evolves.
No timeline is mentioned for availability of the enhanced integration.
Between April 15 and May 25, 2022, Heroku's GitHub integration feature was disabled while Heroku investigated a security breach. During that time, deploying was still possible via other means, most notably via git push.
To mitigate impact from potentially compromised OAuth tokens, we will revoke over the next several hours all existing tokens from the Heroku GitHub integration. We are also preventing new OAuth tokens from being created until further notice. Your GitHub repositories will not be affected in any way by this action.
Which Heroku features have become non-operative due to the removal of the Heroku-GitHub integration?
Enabling review apps
Creating (automatic and manual) review apps
Deploying (automatic and manual) review apps
Deploying an app from GitHub (either manual or automatic)
Heroku CI cannot create new runs (automatically or manually) or see GitHub branch list
Heroku Button: unable to create button apps from private repositories
ChatOps: unable to deploy or get deploy notifications
Any app with a GitHub integration may be affected by this issue. To address specific integration issues, please open a case with Heroku Support
Migrating from GitHub deployment to Git deployment
At 2022-04-21 23:53 UTC, Heroku provided extended instructions for migrating from GitHub-based deployment to Git-based deployment:
While our customers remain unable to reconnect to GitHub via the Heroku dashboard, we wanted to share a supplement to the code deployment methods previously provided. For instructions on how to change your deployment method from GitHub to Heroku Git, please refer to the following Help article: How to switch deployment method from GitHub to Heroku Git with all the changes/app code available in a GitHub repo.
This is due to an issue reported at their status portal, here.
For now, the solution is to use another pushing strategy.
The best one, for now, is using their remote with Heroku CLI. The steps for it are:
1. Install the Heroku CLI if not yet installed
Further information about installation and setup can get here
2. Perform login with the heroku login command
You will be prompted with your default browser window for completing the login at the Heroku portal.
3. Assuming you already have your app set up at Heroku (if not, please follow this), you just need to add a new remote for your Git repository with Heroku CLI.
Run heroku git:remote -a example-app - substitute "example-app" with your app name.
4. git remote -v to check if the remote has been set successfully
You should see something like this appear as a response:
heroku https://git.heroku.com/your-app-name.git (fetch)
heroku https://git.heroku.com/your-app-name.git (push)
5. Push your branch to the new heroku remote
git push heroku your_branch_name
6. You should see the progress of your deployment being displayed in the terminal
The reference for this answer has been taken from here, which can also be used if further information other than the one provided in this answer is needed.
I'm in the same situation, and, as others stated, it's due to a Heroku security issue. In the meantime, you can deploy your code by using the Heroku CLI.
So, on the Heroku web dashboard, select Heroku Git:
Then set up the Heroku CLI with heroku login.
Finally, if your repository already exists on GitHub, you need to add a new remote by running:
heroku git:remote -a your_app_name
git push heroku master
You can find more information about this solution in the official documentation.
It is just a temporary thing, and more details about this issue are here.
You could push to both GitHub and Heroku at once for a temporary solution:
git push -u origin <branch>
git push heroku <branch>
I see the previous answers, but since I was facing an issue with review-apps (PR apps), mostly you will be working with different branches in that case, so here is a solution for pushing your stuff other than the (master/main) branch to Heroku.
First make sure your remote origin is set up correctly
heroku git:remote -a your_awesome_app
You can also confirm it by git remote -v and you should see your origin pointing to your Heroku application.
git remote -v
heroku https://git.heroku.com/your_awesome_app.git (fetch)
Here origin name is heroku.
If you want to deploy your changes from the main branch
git push heroku main
If you want to push your changes from feature branch (other than the* main branch)
Then push your feature branch to Heroku using the below command
git push heroku feature:main
heroku - is your origin name (confirm your origin name with git remote -v
feature - is your current branch which is other than main/master branch (check your branch name with git branch or git status)
For those who are using this integration for deployment purposes this, I suggest you use the deploy to a Heroku GitHub action here:
Deploy to Heroku
That way, you do not have to make significant changes to your deployment workflow.
I had the same issue. I already had cli installed.
git remote
Output:
heroku
origin
git remote -v
Output:
heroku https://git.heroku.com/YOUR-APP.git (fetch)
heroku https://git.heroku.com/YOUR-APP.git (push)
origin https://github.com/GitUserName/yourRepo.git (fetch)
origin https://github.com/GitUserName/yourRepo.git (push)
Verify using the Git branch, if your branch is named main. For example, you would do:
git push heroku main
For me it is
git push heroku master
Now push your local changes
git push heroku master
Output:
To https://git.heroku.com/YOUR-APP.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.heroku.com/YOUR-APP.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I do not care that it is different than its remote. I've been developing locally and did not realize the automatic Git deploys had been failing. I care about the local changes:
git push heroku master -f
Now the deployed application is working as expected.
If you are getting an error while trying to push, it may be due to having different branch names for development vs deployment. In such a case, follow the instruction below;
If you are developing on a branch and deploying via Git you must run:
git push heroku <branchname you're developing on>:<branch you're deploying from>
This article goes into details on the behavior:
Duplicate Build Version Detected
Here's the easy work pattern I have used for Heroku. This is intended to help others who may not have gone through this before. I used this previously (2014-5) and had to set it up again last night to push.
First add the Heroku remote:
git remote add heroku https://git.heroku.com/YOUR-APP.git
As GitHub is often "origin" (git push origin...), this adds another remote destination, "heroku" (git push heroku...)
git remote
Output:
heroku
origin
My pattern for code/git/pushing:
Local development is the same. Push to GitHub, merge, and nothing changes.
Set your deploy to "Heroku git" as #a-chris outlines.
To push to Heroku, simply push the correct branch to the newly added "heroku" remote source. I use the --force option to dismiss any possibility of conflict. Unless you have been using Heroku Git and branching previously, there should only be one branch - typically "master" to use.
This will trigger a deploy. You can watch or review in the dashboard as well as the terminal. Treat the new "heroku" source as a directory to dump code to promote and not a repository you want to keep history, etc. A second-class citizen in this particular pattern.
I push from my local terminal now instead of auto-deploy or via the dashboard button. If your organisation is large, I recommend controlling access. Many developers may not have experience juggling multiple destination repositories or to catch an accidental push.
To trigger a local push, be sure your master (or whatever) is up to date...watch your commit hashes!
This will set you up to follow advice such as BR19_so and others.
Henrique Aron's answer is working for the local machine.
For a remote SSH server, you will face an IP mismatch error.
To resolve it:
Log in to the Heroku website
Go to account settings
Reveal the API keys in the panel
In the server CLI, type heroku login -i
Input email, use the API key as the password, and you can follow the rest of the steps of a Git remote push
I am using a 2014 MacBook Pro with macOS 11.6.5 (Big Sur) version for command
brew tap heroku/brew && brew install heroku
I was getting an error and a message to update to the latest Xcode. The latest Xcode needed the latest macOS, which I could not upgrade to (I needed a 2015 MacBook Pro or newer). For a 2014 MacBook Pro, I was able to Install Xcode_13.2.1.xip and was able to run. Now I can push updates to Heroku.
brew tap heroku/brew && brew install heroku
There is an update regarding this issue. You can now enable GitHub integration as mentioned in the update.
If it doesn't work, you can try removing the App connection to GitHub (disconnect) and adding the connection again. Adding the connection again can also be done in incognito mode because sometimes an issue occurs related to cookies (mentioned here).

Heroku Internal Server Error while deploying code [duplicate]

This post relates to a rapidly changing event.
I simply want to connect to my GitHub account. When I do it, I get this error message as a small red pop up on the upper right side of the page:
Items could not be retrieved, Internal server error.
As of May 25, 2022, at 19:52 UTC, GitHub integration has been re-enabled:
We are happy to report that the GitHub integration is re-enabled! You can now reconnect with GitHub and restore your Heroku pipeline functionality, including Review Apps, with newly generated tokens.
You can connect to GitHub immediately or wait for the enhanced integration as described in this blog post. To re-establish your GitHub connection now, please follow these instructions.
Here is what the referenced blog post says about "enhanced integration":
In an effort to improve the security model of the integration, we are exploring additional enhancements in partnership with GitHub, which include moving to GitHub Apps for more granular permissions and enabling RFC8705 for better protection of OAuth tokens. As these enhancements require changes by both Heroku and GitHub, we will post more information as the engagement evolves.
No timeline is mentioned for availability of the enhanced integration.
Between April 15 and May 25, 2022, Heroku's GitHub integration feature was disabled while Heroku investigated a security breach. During that time, deploying was still possible via other means, most notably via git push.
To mitigate impact from potentially compromised OAuth tokens, we will revoke over the next several hours all existing tokens from the Heroku GitHub integration. We are also preventing new OAuth tokens from being created until further notice. Your GitHub repositories will not be affected in any way by this action.
Which Heroku features have become non-operative due to the removal of the Heroku-GitHub integration?
Enabling review apps
Creating (automatic and manual) review apps
Deploying (automatic and manual) review apps
Deploying an app from GitHub (either manual or automatic)
Heroku CI cannot create new runs (automatically or manually) or see GitHub branch list
Heroku Button: unable to create button apps from private repositories
ChatOps: unable to deploy or get deploy notifications
Any app with a GitHub integration may be affected by this issue. To address specific integration issues, please open a case with Heroku Support
Migrating from GitHub deployment to Git deployment
At 2022-04-21 23:53 UTC, Heroku provided extended instructions for migrating from GitHub-based deployment to Git-based deployment:
While our customers remain unable to reconnect to GitHub via the Heroku dashboard, we wanted to share a supplement to the code deployment methods previously provided. For instructions on how to change your deployment method from GitHub to Heroku Git, please refer to the following Help article: How to switch deployment method from GitHub to Heroku Git with all the changes/app code available in a GitHub repo.
This is due to an issue reported at their status portal, here.
For now, the solution is to use another pushing strategy.
The best one, for now, is using their remote with Heroku CLI. The steps for it are:
1. Install the Heroku CLI if not yet installed
Further information about installation and setup can get here
2. Perform login with the heroku login command
You will be prompted with your default browser window for completing the login at the Heroku portal.
3. Assuming you already have your app set up at Heroku (if not, please follow this), you just need to add a new remote for your Git repository with Heroku CLI.
Run heroku git:remote -a example-app - substitute "example-app" with your app name.
4. git remote -v to check if the remote has been set successfully
You should see something like this appear as a response:
heroku https://git.heroku.com/your-app-name.git (fetch)
heroku https://git.heroku.com/your-app-name.git (push)
5. Push your branch to the new heroku remote
git push heroku your_branch_name
6. You should see the progress of your deployment being displayed in the terminal
The reference for this answer has been taken from here, which can also be used if further information other than the one provided in this answer is needed.
I'm in the same situation, and, as others stated, it's due to a Heroku security issue. In the meantime, you can deploy your code by using the Heroku CLI.
So, on the Heroku web dashboard, select Heroku Git:
Then set up the Heroku CLI with heroku login.
Finally, if your repository already exists on GitHub, you need to add a new remote by running:
heroku git:remote -a your_app_name
git push heroku master
You can find more information about this solution in the official documentation.
It is just a temporary thing, and more details about this issue are here.
You could push to both GitHub and Heroku at once for a temporary solution:
git push -u origin <branch>
git push heroku <branch>
I see the previous answers, but since I was facing an issue with review-apps (PR apps), mostly you will be working with different branches in that case, so here is a solution for pushing your stuff other than the (master/main) branch to Heroku.
First make sure your remote origin is set up correctly
heroku git:remote -a your_awesome_app
You can also confirm it by git remote -v and you should see your origin pointing to your Heroku application.
git remote -v
heroku https://git.heroku.com/your_awesome_app.git (fetch)
Here origin name is heroku.
If you want to deploy your changes from the main branch
git push heroku main
If you want to push your changes from feature branch (other than the* main branch)
Then push your feature branch to Heroku using the below command
git push heroku feature:main
heroku - is your origin name (confirm your origin name with git remote -v
feature - is your current branch which is other than main/master branch (check your branch name with git branch or git status)
For those who are using this integration for deployment purposes this, I suggest you use the deploy to a Heroku GitHub action here:
Deploy to Heroku
That way, you do not have to make significant changes to your deployment workflow.
I had the same issue. I already had cli installed.
git remote
Output:
heroku
origin
git remote -v
Output:
heroku https://git.heroku.com/YOUR-APP.git (fetch)
heroku https://git.heroku.com/YOUR-APP.git (push)
origin https://github.com/GitUserName/yourRepo.git (fetch)
origin https://github.com/GitUserName/yourRepo.git (push)
Verify using the Git branch, if your branch is named main. For example, you would do:
git push heroku main
For me it is
git push heroku master
Now push your local changes
git push heroku master
Output:
To https://git.heroku.com/YOUR-APP.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.heroku.com/YOUR-APP.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I do not care that it is different than its remote. I've been developing locally and did not realize the automatic Git deploys had been failing. I care about the local changes:
git push heroku master -f
Now the deployed application is working as expected.
If you are getting an error while trying to push, it may be due to having different branch names for development vs deployment. In such a case, follow the instruction below;
If you are developing on a branch and deploying via Git you must run:
git push heroku <branchname you're developing on>:<branch you're deploying from>
This article goes into details on the behavior:
Duplicate Build Version Detected
Here's the easy work pattern I have used for Heroku. This is intended to help others who may not have gone through this before. I used this previously (2014-5) and had to set it up again last night to push.
First add the Heroku remote:
git remote add heroku https://git.heroku.com/YOUR-APP.git
As GitHub is often "origin" (git push origin...), this adds another remote destination, "heroku" (git push heroku...)
git remote
Output:
heroku
origin
My pattern for code/git/pushing:
Local development is the same. Push to GitHub, merge, and nothing changes.
Set your deploy to "Heroku git" as #a-chris outlines.
To push to Heroku, simply push the correct branch to the newly added "heroku" remote source. I use the --force option to dismiss any possibility of conflict. Unless you have been using Heroku Git and branching previously, there should only be one branch - typically "master" to use.
This will trigger a deploy. You can watch or review in the dashboard as well as the terminal. Treat the new "heroku" source as a directory to dump code to promote and not a repository you want to keep history, etc. A second-class citizen in this particular pattern.
I push from my local terminal now instead of auto-deploy or via the dashboard button. If your organisation is large, I recommend controlling access. Many developers may not have experience juggling multiple destination repositories or to catch an accidental push.
To trigger a local push, be sure your master (or whatever) is up to date...watch your commit hashes!
This will set you up to follow advice such as BR19_so and others.
Henrique Aron's answer is working for the local machine.
For a remote SSH server, you will face an IP mismatch error.
To resolve it:
Log in to the Heroku website
Go to account settings
Reveal the API keys in the panel
In the server CLI, type heroku login -i
Input email, use the API key as the password, and you can follow the rest of the steps of a Git remote push
I am using a 2014 MacBook Pro with macOS 11.6.5 (Big Sur) version for command
brew tap heroku/brew && brew install heroku
I was getting an error and a message to update to the latest Xcode. The latest Xcode needed the latest macOS, which I could not upgrade to (I needed a 2015 MacBook Pro or newer). For a 2014 MacBook Pro, I was able to Install Xcode_13.2.1.xip and was able to run. Now I can push updates to Heroku.
brew tap heroku/brew && brew install heroku
There is an update regarding this issue. You can now enable GitHub integration as mentioned in the update.
If it doesn't work, you can try removing the App connection to GitHub (disconnect) and adding the connection again. Adding the connection again can also be done in incognito mode because sometimes an issue occurs related to cookies (mentioned here).

Heroku move region

I have been trying to migrate my app to a new region for a while now. It is on the hobby plan and I don't want to create a new one with the same region and manually move everything.
Following the docs, I reached the step:
heroku fork --from fapp --to sapp --region eu
Getting:
HEROKU FORK IS UNMAINTAINED AND MAY NO LONGER FUNCTION.
HEROKU FORK IS UNMAINTAINED AND MAY NO LONGER FUNCTION.
HEROKU FORK IS UNMAINTAINED AND MAY NO LONGER FUNCTION.
HEROKU FORK IS UNMAINTAINED AND MAY NO LONGER FUNCTION.
HEROKU FORK IS UNMAINTAINED AND MAY NO LONGER FUNCTION.
! No slug for app fapp was found.
! Push some code to fapp before forking it.
I can read that it says that code is not pushed to the app. But I don't know what it means by that. The app is already in prod, it's functional, it's connected to github and even has automatic deploys activated.
Some sanity checks:
git --version
git version 2.30.2.windows.1
heroku version
heroku/7.59.2 win32-x64 node-v12.21.0
git remote -v
heroku https://git.heroku.com/fapp.git (fetch)
heroku https://git.heroku.com/fapp.git (push)
origin git#github.com:edited/fapp.git (fetch)
origin git#github.com:edited/fapp.git (push)
I am logged in heroku login
I am logged in heroku container:login
(doubt it's needed)
Don't know if it matters: I used to run git push heroku master, but now I'm running git push origin main for my automatic deploys via Heroku
EDIT: Running heroku apps:info -a fapp gives
=== fapp
Auto Cert Mgmt: true
Dynos: web: 1
Git URL: https://git.heroku.com/fapp.git
Owner: redacted#email.com
Region: us
Repo Size: 0 B
Slug Size: 0 B
Stack: container
Web URL: https://fapp.herokuapp.com/
Please keep in mind the app is not actually called fapp, but I did not want to self-advertise.
heroku-fork still works. But it only works if there is actually any code to fork. The important lines here are:
! No slug for app sourceapp was found.
! Push some code to sourceapp before forking it.
Also important: heroku-fork will not work with container apps.
Note: you may be able to make heroku-fork work with a container app if it was originally built with a standard buildpack and converted into a container app (as reported in the comments below), but standard container apps will not work.
From your application info:
Repo Size: 0 B
Slug Size: 0 B
Nothing else seems wrong here without the repo, please re-check your repository. Sometimes I create an empty file and push to GitHub just to check if the file also get's deployed in Heroku, you may try this.

How do you force a deploy to Heroku without doing a git commit

I had a case where a push to heroku failed because of a database issue. I fixed it, but the only way I know to deploy is via "git push heroku master". Since I didn't commit anything, it won't push a new deployment. The only way I can get it to deploy to make some minor change and then do it. Is there a way to force a deploy? I'm using play 2.1.2.
You could try a throw-away commit if you concern is to avoid actually saving the 'minor/dummy' commits to the repo permanently:
Heroku Throwaway Commit
See Section: "Automating the throwaway commit"
The author has basically automated the above with a quick bash script; however, as the author indicates use with caution -- you wouldn't want to use this in other situations with un-tested code.
https://www.darraghoriordan.com/2019/03/02/heroku-push-failed-force-rebuild/
heroku plugins:install heroku-releases-retry
heroku releases:retry
# or
heroku releases:retry --app darragh-starter
If you are just trying to reload the dynos you can issue this from the command line:
heroku restart -a appname
More info https://devcenter.heroku.com/articles/application-offline

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.

Resources