Friday, October 28, 2022

[SOLVED] Cannot perform an interactive login from a non TTY device error from garygrossgarten/github-action-ssh@release

Issue

I'm trying to run docker commands in an ssh connection which was made from github actions. There I'm using even mention in the workflow. Here is my workflow

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
  pull_request:
    branches: ['main']

env:
  REGISTRY: 'ghcr.io/testing/api-gateway'
  IMAGE_NAME: ${{ format('{0}-{1}', github.event.repository.name, github.sha) }}
  USERNAME: ${{ secrets.USERNAME }}
  DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16.x]

    steps:
      - uses: actions/checkout@v3

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
      - run: npm install
      - run: npm run build

      - name: Build & Push docker
        run: docker build -t $REGISTRY:$IMAGE_NAME .

      - name: Login to github package repository
        run: echo $DOCKER_TOKEN | docker login ghcr.io -u $USERNAME --password-stdin

      - name: Push docker image
        run: docker push $REGISTRY:$IMAGE_NAME

  deploy:
    runs-on: ubuntu-latest
    needs: build

    steps:
      - name: Deploy to Digital Ocean droplet via SSH action
        uses: garygrossgarten/github-action-ssh@release
        with:
          host: ${{ secrets.DO_HOST }}
          username: ${{ secrets.DO_USER }}
          privateKey: ${{ secrets.DO_KEY }}
          passphrase: ${{ secrets.DO_PASSPHRASE }}
          command: |
            echo $DOCKER_TOKEN | docker login ghcr.io -u $USERNAME --password-stdin
            docker pull $REGISTRY:$IMAGE_NAME
            docker run -p 3000:3000 $REGISTRY:$IMAGE_NAME

But I'm getting the following error when I run the workflow.

Run garygrossgarten/github-action-ssh@release
Establishing a SSH connection to ***.
using provided private key
(node:1514) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
🤝 Connected to ***.
Executing command: echo $DOCKER_TOKEN | docker login ghcr.io -u $USERNAME --password-stdin
docker pull $REGISTRY:$IMAGE_NAME
docker run -p 3000:3000 $REGISTRY:$IMAGE_NAME
Error: Cannot perform an interactive login from a non-TTY device

invalid reference format

docker: invalid reference format.
See 'docker run --help'.

⚠️ An error happened executing the command echo $DOCKER_TOKEN | docker login ghcr.io -u $USERNAME --password-stdin
docker pull $REGISTRY:$IMAGE_NAME
docker run -p 3000:3000 $REGISTRY:$IMAGE_NAME. Command exited with code 125
Error: Command exited with code 125
 1: 0xa1a640 node::Abort() [/home/runner/runners/2.296.0/externals/node12/bin/node]
 2: 0xa90649  [/home/runner/runners/2.296.0/externals/node12/bin/node]
 3: 0xc06599  [/home/runner/runners/2.296.0/externals/node12/bin/node]
 4: 0xc08387 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/home/runner/runners/2.296.0/externals/node12/bin/node]
 5: 0x140dd19  [/home/runner/runners/2.296.0/externals/node12/bin/node]

I was looking for a solution and I couldn't find a proper one. what would be the best solution for this?


Solution

According to this other thread about the Cannot perform an interactive login from a non-TTY device message:

docker login prints this error message when you use --password-stdin, but don't actually send a password to the command's stdin.

Therefore, it seems the $DOCKER_TOKEN variable is empty.

You could try using ${{ env.DOCKER_TOKEN}}, or add env: DOCKER_TOKEN: ${{ env.DOCKER_TOKEN }} in the last step of your deploy job.

Something like this:

  deploy:
    runs-on: ubuntu-latest
    needs: build

    steps:
      - name: Deploy to Digital Ocean droplet via SSH action
        uses: garygrossgarten/github-action-ssh@release
        env:
          DOCKER_TOKEN: ${{ env.DOCKER_TOKEN }}
        with:
          host: ${{ secrets.DO_HOST }}
          username: ${{ secrets.DO_USER }}
          privateKey: ${{ secrets.DO_KEY }}
          passphrase: ${{ secrets.DO_PASSPHRASE }}
          command: |
            echo $DOCKER_TOKEN | docker login ghcr.io -u $USERNAME --password-stdin 
            # or using directly ${{ env.DOCKER_TOKEN}} instead of $DOCKER_TOKEN
            docker pull $REGISTRY:$IMAGE_NAME
            docker run -p 3000:3000 $REGISTRY:$IMAGE_NAME


Answered By - GuiFalourd
Answer Checked By - Mary Flores (WPSolving Volunteer)