【问题标题】:Cannot push Docker images to GCP from Github Action无法从 Github Action 将 Docker 映像推送到 GCP
【发布时间】:2022-01-27 02:47:48
【问题描述】:

我有以下 Github Actions 脚本,我在这里使用的 JSON 密钥文件对 GCP 项目具有所有者权限。我无法将图像推送到 GCP 工件 docker repo。

steps:
    - name: Checkout
      uses: actions/checkout@v2
  
    - name: Authenticate to Google Cloud
      uses: google-github-actions/auth@v0.4.3
      with:
        project_id: something-dev-tooling
        credentials_json: '${{ secrets.GCP_JSON }}'
        
    - name: Configure GCloud Auth provider with Docker
      run: |
            gcloud auth configure-docker australia-southeast1-docker.pkg.dev

    - name: Build Tag & Push Container
      run: | 
              tagname="${{github.ref_name}}"
              docker build -t test-signup-api --target prod .
              docker tag test-signup-api australia-southeast1-docker.pkg.dev/something-docker/test-signup-api:$tagname
              docker push australia-southeast1-docker.pkg.dev/something-docker/test-signup-api:$tagname      

这会产生以下错误:

成功标记 test-signup-api:latest 推送指 存储库 [澳大利亚-southeast1-docker.pkg.dev/something-docker/test-signup-api] 123f04c654be:准备 1d4281763c85:准备 4251fe09055f: 准备 a057xxef5483:准备 c6323d11ce20:准备 b4c1ae489097:准备 07d2d7aa362e:准备 7c1610cf2397: 准备 16427a3bb904:准备 449a28044116:准备 f11bbd657c82:准备 b4c1ae489097:等待 07d2d7aa362e:等待 7c1610cf2397:等待 16427a3bb904:等待 449a28044116:等待 f11bbd657c82:等待被拒绝:权限 “artifactregistry.repositories.downloadArtifacts”资源被拒绝 “项目/something-docker/locations/australia-southeast1/repositories/test-signup-api” (或者它可能不存在)

谁能帮忙?

【问题讨论】:

    标签: docker google-cloud-platform github-actions


    【解决方案1】:

    我不确定您是否只是用不同的名称编辑了 project_id,但乍一看,您似乎没有使用正确的项目 ID 标记 Docker 映像,因此它试图推送到一个不存在的项目。

    在“使用 gcloud 进行身份验证”步骤中,您已将项目 ID 定义为: project_id: something-dev-tooling

    所以将 docker 标签更改为正确的项目 ID,它将是:

    docker tag test-signup-api australia-southeast1-docker.pkg.dev/something-dev-tooling/test-signup-api:$tagname
    docker push australia-southeast1-docker.pkg.dev/something-dev-tooling/test-signup-api:$tagname
    

    现在,如果您要推送到不同的项目 ID(而不是您通过 gcloud 进行身份验证的那个),您的服务帐户将需要具有跨项目的权限才能从不同的项目推送/下载图像。

    【讨论】:

      猜你喜欢
      • 2021-11-22
      • 2019-09-05
      • 2021-12-03
      • 1970-01-01
      • 2021-05-13
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多