show log include yuh

勉強したことの復習を兼ねて、IT関係(ネットワーク/サーバ/アプリケーション)についてまとめてます。たまに趣味のこと

スポンサーリンク

コンテナをpushすると発生した denied: Permission "artifactregistry.repositories.uploadArtifacts" denied on resource

概要

Github ActionsでCloud RUNをデプロイしようとしたところ以下のエラーで動きませんでした。
エラー内容からサービスアカウントの権限を変えたりしていましたが実際は違う部分でした。

denied: Permission "artifactregistry.repositories.uploadArtifacts" denied on resource

以下の内容の続きになります。
yunabe.hatenablog.com

Configure Docker

実際は以下のコマンドが足りませんでした。
Artifact RegistryもGoogle Container Registry にpushするのと同じ感覚でいてドキュメントを見なかった反省...

      - name: Configure Docker
        run: gcloud auth configure-docker asia-northeast1-docker.pkg.dev

※ regionは東京の例
https://cloud.google.com/artifact-registry/docs/docker/authentication?hl=ja

Github Actions 例

name: Deploy backend to Cloud RUN with Workload Identity

on:
  push:
    branches:
      - <ブランチ名>

jobs:
  Deploy-Backend:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
    
      - id: 'auth'
        name: 'Authenticate to Google Cloud'
        uses: 'google-github-actions/auth@v1'
        with:
          workload_identity_provider: 'projects/${{ secrets.GCLOUD_PROJECT_NO }}/locations/global/workloadIdentityPools/${{ vars.GCLOUD_WORKLOADIDENTITYPOOL_ID }}/providers/${{ vars.GCLOUD_PROVIDER_ID }}'
          service_account: '${{ secrets.GCLOUD_SEVICE_ACCOUNT }}@${{ secrets.GCLOUD_PROJECT_ID }}.iam.gserviceaccount.com'

      - name: Configure Docker
        run: gcloud auth configure-docker asia-northeast1-docker.pkg.dev

      - name: Build container
        run: docker build --no-cache -t "asia-northeast1-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/container-repo/fastapi:latest" ./
        working-directory: ./fastapi/

      - name: Push container
        run: docker push "asia-northeast1-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/container-repo/fastapi:latest"
        working-directory: ./fastapi/
    
      - name: Deploy backend to Cloud Run
        run: |
          gcloud run deploy fastapi \
            --project=${{ secrets.GCLOUD_PROJECT_ID }} \
            --image=asia-northeast1-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/container-repo/fastapi:latest \
            --region=asia-northeast1 \
            --allow-unauthenticated
        working-directory: ./fastapi/