1
votes

I am setting up a Github action to push a Docker image to Docker Hub following Github official README.md for docker/build-push-action@v2.

This is my action inside directory .github/workflows/

name: Publish Docker image

on:
  push:
    branches: master

jobs:
  push_to_registry:
    name: Push Docker image to Docker Hub
    runs-on: ubuntu-latest
    steps:
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      -
        name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: user/app:latest
      -
        name: Image digest
        run: echo ${{ steps.docker_build.outputs.digest }}

Having tested the action worked in my fork branch I then merged the branch to the main repo. To my surprise the login step failed showing the following error inside Github actions log

Run docker/login-action@v1
  with:
    logout: true
Error: Username and password required

At first I thought I could have wrongly defined (or even not defined) the secrets inside the main repo but after a request with octokit I found out that they are there

{
  total_count: 2,
  secrets: [
    {
      name: 'DOCKER_PASSWORD',
      created_at: '2020-11-04T15:28:55Z',
      updated_at: '2020-11-16T13:11:27Z'
    },
    {
      name: 'DOCKER_USERNAME',
      created_at: '2020-11-04T15:28:55Z',
      updated_at: '2020-11-16T13:11:27Z'
    }
  ]
}

I guess that docker/login-action@v1 is not using username and password provided after the with: keyword. I am very puzzled by this as it did work on my fork branch and do not understand why with: is sending the keyword logout: true instead which I did not set.

Does someone have more insight into this ?

1
Works fine for me here. I also see logout: true in the outputs for that step, so presumably it's a default: github.com/textbook/salary-stats/runs/…, but the push succeeds anyway, I'd guess that's for the Post Run cleanup step. Are you sure it's running the workflow you think it is? - jonrsharpe
@jonrsharpe yes I am sure. This is the workflow that is running and this are the logs. - Diego Asterio
Weird, I don't know what to tell you - you can see it works fine for me with a very similar setup. - jonrsharpe
Curious if you found a solution? I'm having a very similar issue - Felipe Kettle

1 Answers

1
votes

Could you check that in the repository's settings the secrets are there like this:

enter image description here

Also, when you say

Having tested the action worked in my fork branch I then merged the branch to the main repo.

does this mean the main repo is also yours? Because secrets don't transfer between repos. If you've forked another user's repository and want to contribute workflow changes requiring secrets, the main repo's owner(s) will have to add secrets with the same name. Additionally, secrets aren't used in Pull Requests workflow runs. Hence you'll only see if it's working after the changes have been merged into the repository.