How to stop deployment to Heroku in progress - heroku

Is it possible to stop a deploy to Heroku (git push heroku) that is currently being built?
Something like heroku run stopit!
Btw. rolling back after successful deploy is not what I'm looking for.

First, install the Heroku builds plugin:
heroku plugins:install heroku-builds
Then, to cancel a build, fetch the list of the recent builds:
heroku builds -a YOUR_APP_NAME
The first line of the output will be your currently running build, the first column is the build ID.
Cancel it with:
heroku builds:cancel BUILD_ID -a YOUR_APP_NAME
Et voilà, this will force fail the build.
Note: you could also get the build id from the build log URL.

I might have found an answer to this problem, it seems to have been answered by Heroku in May. I'm assuming that by release phase they mean deploy:
https://help.heroku.com/Z44Q4WW4/how-do-i-stop-a-release-phase
Release Phase processes are the same as any other Dyno in your formation, expect they run the codebase from the new release, instead of your current release.
To monitor your Release Phase processes as they execute, you can use the CLI command heroku ps -a YOUR_APP_NAME. as these are normal processes, you can use the ps:kill and ps:scale commands to stop the Release Phase from completing, which in turn, will prevent the latest release from completing.
I haven't tested this yet, but i will update with my exact commands when i have tested it out. If any one tests this out and can confirm, please feel free to update this answer.

I used the command
heroku builds:cancel -a <your_app_name>
and this worked for me

Related

How to OPEN Sonarqube Server on Heroku ( -> buildpack https://github.com/NayaraCaetano/heroku-buildpack-sonarqube.git)

What worked so far: I installed sonarqube locally with mvn sonar:sonar I get the results on localhost:9000.
Now I want to do the same thing for our app that is hosted on heroku. I could successfully install the buildpack from NayaraCaetano with
heroku buildpacks:set https://github.com/ https://github.com/NayaraCaetano/heroku-buildpack-sonarqube.git/heroku-buildpack-sonarqube.git -a ourAppName
On heroku I saw that the buildpack was added.
Not working / unclear
So how am I now able to open the sonarqube findings from heroku, I didn't find any documentation on this but not shure if I am missing the point of what this buildpack is supposed to do
In the end we were able to use sonarcloud.io. Since our heroku app was anyway connected to github we just created an account at sonarcloud that was connected to our master branch.
It's not really the solution i hoped for, but it meet our goal to constantly monitor our code coverage on every commit to the master branch.

heroku: flush redis in release phase

I have a node app running on heroku and I'm trying to use the release phase to flush my redis cache on deploy.
I've added the release: ./release-tasks.sh to my Procfile but I'm having a hard time finding information what tools are available for me to use in the release phase.
Currently my release-tasks.sh file looks like this:
redis-cli -u $REDIS_URL flushall
But it errors out with a redis-cli not found and it cannot find the heroku command either.
It says in the release-phase docs that it is a good place to invalidate a cache, does anyone have any thoughts on how to do this?
redis-cli nor the Heroku CLI is available on a dyno so you can't use them here. Depending on the language your app is built in your could write a task in that language that flushes the cache and then invoke that task from your shell script.

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

What is a good way to run a task whenever a Heroku app restarts?

Use case is to bust the cache.
What is a good way to run given code (or rake task) whenever a Ruby Heroku app is restarted (or deployed)?
There's no way to do this via the Heroku API far as I know. The Heroku Platform API doesn't support this.
What you can do (if you're fast, however!) is listen for a SIGTERM message in your code (that's what Heroku sends to your application process when it attempts to restart it) -- you can then fire off your script quickly.
Here's more information on SIGTERM on Heroku: https://devcenter.heroku.com/articles/dynos#graceful-shutdown-with-sigterm
If you're using some sort of CI, you can probably configure it there. Heres how to do it with CircleCI:
deployment:
production:
branch: production
commands:
- git push git#heroku.com:foo-bar-123.git $CIRCLE_SHA1:master
- heroku run rake <your task> --app <your app name>
If you're not using a CI you can still whip together a script that first does the git push to Heroku and then executes your cache busting task through heroku run (the app's bin/ folder would be an obvious place to put it).
Note: you can also use heroku run:detached, which will send output to your logs instead of stdout.
You can use "release" feature that allows you to run any command before a new release is deployed. https://devcenter.heroku.com/articles/release-phase
Define the command that should be run in your Procfile.
release: rake db:migrate
From documentation:
The release command is run immediately after a release is created, but before the release is deployed to the app’s dyno formation. That means it will be run after an event that creates a new release.

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

Resources