mr-smithers-excellent / docker-build-push

Docker Build & Push GitHub Action
MIT License
287 stars 61 forks source link

Not working with Artifact Registry #227

Closed Dev-Destructor closed 8 months ago

Dev-Destructor commented 8 months ago

I have using it for the past few months. I was GCR previously but now it's being deprecated I had to switch. This is the code I am using

name: Upload to Google Artifact Registry

on:
  push:
    tags:
      - "*"

jobs:
  setup-build-push:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

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

      - name: Configure Docker to use GCR
        uses: google-github-actions/setup-gcloud@v0.2.1
        with:
          project_id: ${{ secrets.GCP_PROJECT_ID }}
          service_account_key: ${{ secrets.GCP_GCR_KEY }}
          export_default_credentials: true

      - name: Login to Google Container Registry
        run: gcloud auth configure-docker

      - name: Build and push Docker image to GCR
        uses: docker/build-push-action@v2
        with:
          context: .
          file: ./Dockerfile
          push: true
          tags: asia-south2-docker.pkg.dev/***
          cache-from: type=gha
          cache-to: type=gha,mode=max

And getting error

Error: buildx failed with: ERROR: failed to solve: failed to push asia-south2-docker.pkg.dev/***: failed to authorize: failed to fetch anonymous token: unexpected status from GET request to https://asia-south2-docker.pkg.dev/v2/token?scope=repository***&service=asia-south2-docker.pkg.dev: 403 Forbidden

but using the similar script instead of asia-south2-docker.pkg.dev if I use gcr.io it works

Note:- To check if it is an issue with my GCP service account I used it on my docker locally and I was working. Permissions:-

Artifact Registry Writer Artifact Registry Reader Artifact Registry Repository Administrator Artifact Registry Administrator

mr-smithers-excellent commented 8 months ago

@Dev-Destructor - doesn't look like the workflow you shared uses this action (mr-smithers-excellent/docker-build-push). Can you confirm you're using this action?

Dev-Destructor commented 8 months ago

I fixed the issue, never mind, turned out it was with Artifact Registry itself.