build-push-action icon indicating copy to clipboard operation
build-push-action copied to clipboard

`fatal: Not a valid object name` during `load git source` triggered by `on: push:` (with self-hosted runner)

Open aderk opened this issue 1 year ago • 3 comments

Contributing guidelines

I've found a bug, and:

  • [X] The documentation does not mention anything about my problem
  • [X] There are no open or closed issues that are related to my problem

Description

[email protected] fails to get the ref during on: push: trigger (on: pull_request: works as expected). It then falls back to downloading cloning the entire repo (slow).

#1 [internal] load git source https://github.com/OWNER_NAME/REPO_NAME.git#SHA
#1 0.033 Initialized empty Git repository in /var/lib/buildkit/runc-overlayfs/snapshots/snapshots/1/fs/
#1 0.051 fatal: Not a valid object name SHA^{commit}
#1 331.5 From https://github.com/OWNER_NAME/REPO_NAME
#1 331.5  * [new branch]              BRANCH1
#1 331.5  * [new branch]              BRANCH2
...

Succinctly, [email protected] succeeds with refs of the form https://github.com/OWNER_NAME/REPO_NAME.git#refs/pull/PULL_NUMBER/merge and fails (with fallback to full clone) with the form https://github.com/OWNER_NAME/REPO_NAME.git#SHA

Expected behaviour

Only the ref w/ depth=1 is fetched (fast) as with on: pull_request: triggers.

Actual behaviour

The whole repo is cloned (slow). In my case it takes 8m instead of 1m

Repository URL

No response

Workflow run URL

No response

YAML workflow

- name: Build Source Image
        uses: docker/build-push-action@v5
        with:
          context: "{{defaultContext}}"
          cache-from: |
            type=registry,ref=REDACTED
            type=registry,ref=REDACTED
          cache-to: type=registry,ref=REDACTED,mode=max
          push: true
          tags: |
            REDACTED-${{ github.sha }}
            REDACTED-latest
          file: REDACTED/Dockerfile.build

Workflow logs

No response

BuildKit logs

No response

Additional info

https://github.com/docker/build-push-action/issues/638 is somewhat similar, in that the initial error log line is identical fatal: Not a valid object name

aderk avatar Mar 21 '24 23:03 aderk

More discussion here: https://stackoverflow.com/questions/72049008/docker-build-push-action-not-a-valid-object-name-outputs-all-branches-and-tag

aderk avatar Mar 22 '24 17:03 aderk

Can confirm that this is still a problem. Switching to file context is a workaround that removes this error.

major-mayer avatar Apr 24 '24 09:04 major-mayer

@aderk Sorry for the delay, do you have a link to your repo? Are you using submodules?

#1 0.051 fatal: Not a valid object name SHA^{commit}

Also this message should not fail your build and still fetch correctly per https://github.com/moby/buildkit/issues/2888.

crazy-max avatar Jun 12 '24 15:06 crazy-max