authenticate to GitHub ghcr in workflow

619 views Asked by At

I have been trying to set up a container workflow in my github project so that it is triggered by every push to to repo and. It must build the container image from the default Dockerfile and push the image to my GitHub container registry (GHCR). Before I can push an image to the registry, I need to be authenticated. I have a PAT (personal access token) for it that I can use from terminal for manual push. Then I made a secret for it so that I can use it in the workflow. So far, I have not been able to pass authentication step in the workflow.

Here's my container workflow yaml:.

name: Docker Image CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:

  build:

    runs-on: ubuntu-latest
        

    steps:
    - uses: actions/checkout@v2
      with: 
        repo-token: ${{secrets.GHCR_LOGIN}}
    - name: Build the Docker image
#       run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
      run: docker build -t ghcr.io/myusername/repo:latest .
    # - name: Authenticate in the Workflow
     run: echo $GHCR_LOGIN |docker login ghcr.io -u myusername --password-stdin
    - name: Push the Docker image
      run: docker push ghcr.io/myusername/repo:latest

The error I get with this definition is that docker cannot authenticate from standard input in non-tty environment. But, there must be a way to pass the secret or password to docker.

0

There are 0 answers