nx-tools icon indicating copy to clipboard operation
nx-tools copied to clipboard

Docker images don't push to the GitHub registry

Open Ncado opened this issue 2 years ago • 3 comments

I've been trying to push my images to GitHub registry. I have no-monorepo with two projects Example of my project target inside project.json

"container": {
      "executor": "@nx-tools/nx-container:build",
      "options": {
        "file": "apps/vyzl-frontend/frontend.Dockerfile",
        "engine": "docker",
        "metadata": {
          "images": [
            "frontend"
          ],
          "load": true,
          "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/"organization-name"/vyzlFrontend:latest",
            "ghcr.io/"organization-name"vyzlFrontend:v1"
          ]
        }
      }
    },```
    
    

Ncado avatar Jan 15 '23 12:01 Ncado

Hi... Change load: true for push: true 😃

gperdomor avatar Jan 15 '23 13:01 gperdomor

Hi... Change load: true for push: true` 😃

Thank you, but I am faced with the following problem

> NX buildx failed with: ERROR: failed to solve: failed to push backend:main: server message: insufficient_scope: authorization failed

example of 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

But I successfully login into GitHub

image

UPD: project targets the same, but I add push: true

Ncado avatar Jan 17 '23 12:01 Ncado

You configured the imagename wrong, you are pushing to Docker Hub without authorization to a scope you have no access to. Also the latest and v1 tags are wrong, besides latest is handled automatically.

    "container": {
      "executor": "@nx-tools/nx-container:build",
      "options": {
        "file": "apps/vyzl-frontend/frontend.Dockerfile",
        "engine": "docker",
        "metadata": {
          "images": [
            "ghcr.io/ncado/vyzlFrontend"
          ],
          "load": true,
          "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-",
            "type=semver,pattern=v{{major}}",
          ]
        }
      }
    },

microwavekonijn avatar Feb 12 '23 23:02 microwavekonijn