由于garygrossgarten的非TTY设备错误,无法执行交互式登录/github-action-ssh@relea



我正试图在通过github操作建立的ssh连接中运行docker命令。我甚至在工作流程中提到了这一点。这是我的工作流程

# 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

但是,当我运行工作流时,会出现以下错误。

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]

我一直在寻找解决方案,但找不到合适的解决方案。什么是最好的解决方案?

根据关于无法从非TTY设备执行交互式登录的其他线程消息:

docker登录在使用--password stdin时打印此错误消息,但实际上不要向命令的stdin发送密码。

因此,$DOCKER_TOKEN变量似乎为空。

您可以尝试使用${{ env.DOCKER_TOKEN}},或者在部署作业的最后一步添加env: DOCKER_TOKEN: ${{ env.DOCKER_TOKEN }}

类似的内容:

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