gperdomor / nx-tools

Nx Workspaces builders and tools
MIT License
348 stars 53 forks source link

Push to github registry failed. insufficient_scope: authorization failed #723

Open NcadoUatechPeople opened 1 year ago

NcadoUatechPeople commented 1 year ago

I've trying to push my images to github registry And faced error > NX buildx failed with: ERROR: failed to solve: failed to push backend:main: server message: insufficient_scope: authorization failed My github action


name: Node.js Package

on:
  push:
    branches: [ "main" ]
env:
  REGISTRY: ghcr.io

jobs:
  build:
    runs-on: ubuntu-latest
    steps:

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - uses: actions/checkout@v3
        name: Checkout
        with:
          fetch-depth: 0

      - name: Log in to the Container registry
        uses: docker/login-action@v2
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: 'Install Dependencies'
        run: yarn install

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v4
        with:
          images: ${{ env.REGISTRY }}/vyzl
          tags: |
           type=semver,pattern={{version}}
           type=raw,value=latest
           type=sha,prefix=sha-

      - name: 'nx build'
        env:
           INPUT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: INPUT_GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} npx nx run-many --target=container,containerWorker --projects=vyzl-backend,vyzl-frontend

I successfully login into GitHub

image

My project target


"container": {
      "executor": "@nx-tools/nx-container:build",
      "options": {
        "file": "apps/vyzl-backend/backend.Dockerfile",
        "engine": "docker",
        "push": true,
        "context": ".",
        "metadata": {
          "images": [
            "UATechPeople/vyzl-backend"
          ],
          "tags": [
            "type=ref,event=branch",
            "type=ref,event=tag",
            "type=ref,event=pr",
            "type=semver,pattern={{version}}",
            "type=semver,pattern={{major}}.{{minor}}",
            "type=semver,pattern={{major}}",
            "type=sha,prefix=sha-",
            "ghcr.io/UATechPeople/vyzl-backend:latest",
            "ghcr.io/UATechPeople/vyzl-backend:v1"
          ]
        }
      }
    },
ayadagain commented 5 days ago

Hey @NcadoUatechPeople, did you fix it?

gperdomor commented 5 days ago

@NcadoUatechPeople @ayadagain Hi folks... If you want to use metadata, in order to work you must update the config to:

"metadata": {
    "images": [
        "ghcr.io/UATechPeople/vyzl-backend"
    ],
    "tags": [
        "type=ref,event=branch",
        "type=ref,event=tag",
        "type=ref,event=pr",
        "type=semver,pattern={{version}}",
        "type=semver,pattern={{major}}.{{minor}}",
        "type=semver,pattern={{major}}",
        "type=sha,prefix=sha-",
    ]
}

Also remove this from GitHub workflow, that is handled internally by nx-container

- name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v4
        with:
          images: ${{ env.REGISTRY }}/vyzl
          tags: |
           type=semver,pattern={{version}}
           type=raw,value=latest
           type=sha,prefix=sha-