5

I am trying to run within my github action a docker push since like to use the same image as part of different repos. The code I am using is the following:

  docker build . --pull --rm --file "$GITHUB_WORKSPACE/${{ matrix.path }}/Dockerfile" --tag ${{ matrix.name }}
  echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

  IMAGE_ID=ghcr.io/${{ github.repository }}/${{ matrix.name }}
  # Strip git ref prefix from version
  VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
  echo IMAGE_ID=$IMAGE_ID
  echo VERSION=$VERSION
  docker tag ${{ matrix.name }} $IMAGE_ID:$VERSION
  docker push $IMAGE_ID:$VERSION

The error I am getting is related to permissions:

  denied: installation not allowed to Create organization package"

Any suggestion what is missing from my permissions.

Tobias Bruckert
  • 348
  • 2
  • 12

3 Answers3

3

thanks all for your hints it was a combination of the missing PAT rules and the wrong format. The following code works now:

      docker build . --pull --rm --file "$GITHUB_WORKSPACE/${{ matrix.path }}/Dockerfile" --tag ${{ matrix.name }}
      echo "${{ secrets.GIT_DOCKER_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

      IMAGE_ID=ghcr.io/${{ github.actor }}/${{ matrix.name }}
      # Change all uppercase to lowercase
      IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
      # Strip git ref prefix from version
      VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
      echo IMAGE_ID=$IMAGE_ID
      echo VERSION=$VERSION
      docker tag ${{ matrix.name }} $IMAGE_ID:$VERSION
      docker push $IMAGE_ID:$VERSION

The PAT has the following permissions:

enter image description here

Tobias Bruckert
  • 348
  • 2
  • 12
2

I wasted two hours trying to figure out why I got this error message. It turns out that workflows have read access only by default. You must go to github.com/organizations/yourorganization/settings/actions and grant write access.

Simon de Lorean
  • 2,045
  • 1
  • 13
  • 9
1

I am facing the same issue when push docker image into GitHub Container Registry, setting the permission like this:

build_and_push:
    name: Build image & push
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

works, this is the official document: https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages

Dolphin
  • 29,069
  • 61
  • 260
  • 539