Login to Heroku on remote server without a browser - heroku

Is there a way to login into Heroku to see the logs on a remote server which has no browser installed ?

Using Heroku CLI
$ heroku login -i
$ heroku logs

Related

How to access Heroku app console by heroku CLI

I can check logs by heroku logs --app=my_app_name . I want to access app's console as shown in the picture. How can I access by heroku cli?
To access Heroku app bash by CLI:-
heroku login
heroku ps:exec --app=scoreboard-backend-dev
scoreboard-backend-dev is the app name

heroku CLI auth by token

Every time after building and pushing docker image from Gitlab registry to Heroku registry I need to execute heroku container:release web to Heroku run image (release), but I wanna automate this
I added heroku CLI tool installation into gitlab-ci-yml, but I can't auth heroku CLI by token
When I try to set HEROKU_API_KEY=token and run heroku login I get an error Error: Cannot log in with HEROKU_API_KEY set
Also tried to do this with HEROKU_DEBUG on, but debugger info couldn't help me
I can't use ~/.netrc
Any way to auth heroku CLI or automate releasing docker images in heroku?
current gitlab-ci.yml:
before_script:
- apt install snapd
- snap install --classic heroku
- HEROKU_API_KEY=$HEROKU_API_TOKEN heroku login
- docker login -u $REGISTRY_UNAME -p $REGISTRY_PWD registry.gitlab.com
- docker login --username=_ --password=$HEROKU_PWD registry.heroku.com
script:
# a lot of tag & push lines
- heroku container:release web
If you have set the HEROKU_API_KEY environment variable, you don't have to log in again. The API key will be used for the Heroku CLI commands if present.
Make sure to use heroku authorizations:create to create never-expiring tokens. Check this out for a detailed explanation.
Ref: https://github.com/heroku/cli/issues/502#issuecomment-309099883
Note that the git commands like git push heroku master won't use the API key. See this for more info.
problem solved by changing account password that causes tokens changing and re-creating new token
And then run again HEROKU_API_KEY=token heroku container:release web with success

Inspect Heroku local logs

I have an app that's deployed to production, but I'm also testing it locally.
When I run heroku logs --tail, I get the production logs. I can see when I make a request to the webapp and it shows up instantly in the logs.
However, my app on heroku local returns me a "500 Server Error." I want to inspect these logs to understand why. However, I can't find these logs. Is there a command like heroku local logs --tail?
In order to see logs in IDE or Console use below command
Local:
I'm using Python script and the same deployed in heroku. I want to run locally by using heroku local command and would like to see logs in console but it is not showing logs in IDE Console. So for workaround i tried below command and it works well. Now I can see logs in the IDE itself.
E.g. for Python Script:
heroku local:run python test.py
E.g. for Rails:
heroku local:run rails console
Production:
heroku logs --tail --app <app-name>

How can you see Heroku logs for git deployed app on Heroku

If we deploy app normally on heroku-cli, we can easily see all the logs by using
$ heroku logs
But how can we check heroku logs if we have connected the heroku app with git repository, then we can't use heroku logs

On deploy, Heroku says it can't find API key even though I've logged in

When I run heroku deploy:jar app.jar --app app, I receive this error:
$ heroku deploy:jar build/libs/app.jar --app app
Uploading app.jar
-----> Packaging application...
- app: app
- including: build/libs/app.jar
! ERROR: Could not get API key! Please install the toolbelt and login with `heroku login` or set the HEROKU_API_KEY environment variable.
! Re-run with HEROKU_DEBUG=1 for more info.
▸ There was a problem deploying to app.
▸ Make sure you have permission to deploy by running: heroku apps:info -a app
Here's there environment's information:
On a Mac.
Heroku version: heroku-cli/6.16.12 (darwin-x64) node-v9.11.1
Heroku plugins: heroku-cli-deploy 0.4.0
java version "1.8.0_131"
node version: v4.9.1
I've tried running heroku login multiple times. After it's run, I can run heroku apps:info -a app and it lists the information. I'm inferring that that means I'm logged in already.
My login works on another computer, so I assume it's a local config issue and not an account issue. When I set HEROKU_DEBUG=1, it provides no additional information.
The issue lay in heroku login. It creates a file ~/.netrc containing your login and token.
The format of this generated file on another mac (the mac I mentioned the deploy was working fine) was as follows:
machine api.heroku.com
password ...
login ...
machine git.heroku.com
password ...
login ...
The format of the same generated file on the mac which was giving the above problem was as follows:
machine api.heroku.com login ... password ...
machine git.heroku.com login ... password ...
Apparently, both formats are fine for most Heroku commands such as viewing apps and such. But for the deploy command (which requires the heroku-cli-deploy plugin, only the first format is acceptable.
So basically the heroku cli accepts both new lines and spaces as delimiters between the endpoint, login, and token. But the deploy plugin only accepts new lines. heroku login was using spaces for some reason; so heroku commands were working, while the heroku deploy commands were not.
There would be another reason for the same error in Ubuntu. For some reason in Ubuntu it is easy to make jhipster cli installation that requires sudo while heroku cli don't allow to log in under sudo because browser start doesn't work from the sudo call. And it is uneasy to figure out, what was wrong with jhipster sudo installation, which particular files now owned by the root and so on.
But if you have logged to heroku cli not from the root user (i.e not using sudo) or created api key variable not from root user (i.e not using sudo) your deploy will fail with the error above if you'll request jhipster with sudo:
sudo hipster heroku
if you'll try it without sudo, it will hang on
Installing Heroku CLI deployment plugin
To make it working just run
sudo -E jhipster heroku
and -E will pass your api key variable to the sudo execution

Resources