Skip to content

How to run docker commands with env mentioned in the workflow? #35

@sathyamolagodaarimac

Description

@sathyamolagodaarimac
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 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'm getting the above issue when I'm using the env variables mentioned in the workflow. And 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

What is the correct way to use these variables here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions