Gitlab-ci Docker login Heroku Error: Cannot perform an interactive login from a non TTY device

Viewed 513

I am trying to push image from GitLab registry to Heroku image registry, but I am unable to login in gitlab-ci.

Firstly, locally I was able to log in successfully. I was following this guide - https://devcenter.heroku.com/articles/container-registry-and-runtime#logging-in-to-the-registry. The log-in was successful:

docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /home/dave/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded

When I try to do the same in my gitlab-ci.yml file I receive error message trying both of these options:

script:
    - docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com

OR

script:
    - echo $HEROKU_API_KEY | docker login --username=_ --password-stdin registry.heroku.com

Error message:

Error: Cannot perform an interactive login from a non TTY device
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

Are there other methods I should use to log in via gitlab-ci to Heroku image registry?

Update: The HEROKU_API_KEY env variable is set up correctly. It is not masked, not protected and available in all environments. I was even able to use it previously with another command to deploy, but this time I must deploy a docker container. Another command that was used:

- dpl --provider=heroku --app=my-app --api-key=$HEROKU_SECRET_KEY

That being said, I still need a solution to deploy the container from the Gitlab registry to the Heroku registry but the docker login fails.

1 Answers

This issue arises from the environment variable HEROKU_API_KEY not being configured or available in the ci.

I recognize the problem since I ran into the exact same situation.
The error message says "interactive login not possible" because it received an empty input in stdin. Normally this is run in a shell, you could fill in the password manually, so docker presumes that this is what you wanted to do, however since stdin closes, it can't get the password. Well, that's just the explanation for the message you're getting.

As for what actually causes the variable not being available, there is a few possibilities:

  • Maybe you didn't configure the variable in the project settings yet.
    For that, go to your settings, to the CI section, to variables, and enter the variable with name and value.
  • Maybe the variable is protected, and you're trying to use it in a pipeline that can't use protected variables. In this case, you can uncheck the setting for the "protected" state of the variable, in the same menu as described in the above point.
    Alternatively you can check whether you might want to leave it be protected, but switch to only using the variable in a setting that can use protected variables.
Related