简体   繁体   English

无法使用 github 操作将 docker 图像推送到 github package

[英]Unable to push docker image to github package using github actions

Hi I am trying to push docker images to github packages using workflow.您好,我正在尝试使用工作流将 docker 个图像推送到 github 个包。 Below is my workflow.以下是我的工作流程。

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

This step passes and I am able to login.这一步通过了,我可以登录了。 Below is my next step.下面是我的下一步。

 - name: Extract metadata (tags, labels) for Docker
      id: meta
      uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
      with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

    - name: Build and push Docker image
      uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
      with:
          context: ./CharteringExecutionPlatform/
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

In this step I am successfully able to build docker image and tag it.在这一步中,我成功地构建了 docker 图像并对其进行了标记。 Workflow fails when pushing docker image to github package. I am getting below error将 docker 图像推送到 github package 时工作流程失败。出现以下错误

ERROR: denied: requested access to the resource is denied Error: buildx call failed with: ERROR: denied: requested access to the resource is denied错误:拒绝:请求访问资源被拒绝错误:buildx 调用失败:错误:拒绝:请求访问资源被拒绝

I am not sure what I am missing here.我不确定我在这里错过了什么。 Can someone help me?有人能帮我吗? Any help would be appreciated.任何帮助,将不胜感激。 Thank you谢谢

Solved by setting the correct tags in the extract metedata step通过在提取元数据步骤中设置正确的标签来解决

  docker:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    strategy:
      matrix:
        dotnet-version: ['6.0.x' ]

    steps:
      - uses: actions/checkout@v3

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
          tags: |
            type=ref,event=branch
            type=ref,event=pr
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}

      - name: Build and push Docker image
        uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
        with:
          context: .
          file: subdir/Dockerfile
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM