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
sula
  • 91
  • 1
  • 5

2 Answers2

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.

Arun Kumar Mohan
  • 11,517
  • 3
  • 23
  • 44
  • 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 set` – sula Apr 05 '20 at 06:32
  • @sula As I mentioned in my answer, you don't need to do `heroku login` if you already have the API key. – Arun Kumar Mohan Apr 05 '20 at 22:19
  • 1
    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 errors – sula Apr 06 '20 at 07:05
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

sula
  • 91
  • 1
  • 5