Docker build-push-action“不是有效的对象名称”;输出仓库的所有分支和标签

Nic*_*ick 5 git github docker github-actions buildx

在 GitHub Action Workflow 中运行我们的 docker 构建时,docker/build-push-action@v2不断输出以下错误。这是在运行 Dockerfile 中的任何命令之前:

Run docker/build-push-action@v2
  with:
    file: packages/api/Dockerfile
    tags: us.gcr.io/org-blahblah-shared/project-api:v7.9914
    push: true
    cache-from: type=gha
    cache-to: type=gha,mode=max
    load: false
    no-cache: false
    pull: false
    github-token: ***
  env:
    MAJOR_VERSION: v7
    DOCKER_REGISTRY: us.gcr.io
    GCP_PROJECT_ID: org-blahblah-shared
    TAG: v7.9914
Docker info
/usr/bin/docker buildx build --cache-from type=gha --cache-to type=gha,mode=max --file packages/api/Dockerfile --iidfile /tmp/docker-build-push-vytgyS/iidfile --secret id=GIT_AUTH_TOKEN,src=/tmp/docker-build-push-vytgyS/tmp-2350-NvWl1QbeU577 --tag us.gcr.io/org-blahblah-shared/project-api:v7.9914 --metadata-file /tmp/docker-build-push-vytgyS/metadata-file --push https://github.com/org/project.git#abc123
#1 [internal] load git source https://github.com/org/project.git#123abc
#1 0.176 hint: Using 'master' as the name for the initial branch. This default branch name
#1 0.176 hint: is subject to change. To configure the initial branch name to use in all
#1 0.176 hint: of your new repositories, which will suppress this warning, call:
#1 0.176 hint: 
#1 0.176 hint:  git config --global init.defaultBranch <name>
#1 0.176 hint: 
#1 0.176 hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
#1 0.176 hint: 'development'. The just-created branch can be renamed via this command:
#1 0.176 hint: 
#1 0.176 hint:  git branch -m <name>
#1 0.177 Initialized empty Git repository in /var/lib/buildkit/runc-overlayfs/snapshots/snapshots/1/fs/
#1 0.259 fatal: Not a valid object name 123abc^***commit***
#1 6.346 From https://github.com/org/project
#1 6.346  * [new branch]          blah
#1 6.346  * [new branch]          blah2
#1 6.347  * [new branch]          ...
#1 6.363  * [new tag]             v1
#1 6.363  * [new tag]             v2
#1 6.363  * [new tag]             ...
Run Code Online (Sandbox Code Playgroud)

这输出了大约 3000 行无用的输出,并且似乎是一些配置错误。我怎样才能解决这个根本问题,或者至少控制输出?

它似乎与命令的最后部分相关docker buildx build--push https://github.com/org/project.git#abc123但这似乎不在我们的任何配置中直接控制。

Nic*_*ick 2

结果 build-push-action默认在“GitHub”上下文中运行。至少,这意味着将您的存储库作为预 Dockerfile 命令的一部分进行拉取。

您可以使用以下命令将其更改为“文件”上下文:

      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          tags: user/app:latest
Run Code Online (Sandbox Code Playgroud)

由于我们之前在签出操作中删除了存储库,因此这是多余的。