heroku CLI auth by token
Asked Answered
U

2

7

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
Unnamed answered 5/4, 2020 at 4:18 Comment(1)
I might be missing something. Why do you have to log in if you already have the API key set?Corrugation
U
2

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

Unnamed answered 6/4, 2020 at 7:15 Comment(0)
C
10

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.

Corrugation answered 5/4, 2020 at 4:51 Comment(3)
no, I don't use heroku's git. I just build my image in gitlab CI and gitlab's CI delivers it to heroku. But heroku won't start running image untill I execute heroku container:release web. I created heroku token for auth, but gitlab's runner can't auth in heroku (to execute heroku container:release web) with error Error: Cannot log in with HEROKU_API_KEY setUnnamed
@Unnamed As I mentioned in my answer, you don't need to do heroku login if you already have the API key.Corrugation
trying to run HEROKU_API_KEY=never-expiring-token heroku container:release web got an error: Invalid credentials provided. Error: Cannot log in with HEROKU_API_KEY set Command failed: heroku login. Trying to run export HEROKU_API_KEY=never-expiring-token and then heroku container:release web got the same error. Also was trying the same with non-never expiring token and got the same errorsUnnamed
U
2

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

Unnamed answered 6/4, 2020 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.