Home > Back-end >  Docker build-push-action "Not a valid object name"; outputs all branches and tags for repo
Docker build-push-action "Not a valid object name"; outputs all branches and tags for repo

Time:05-03

When running our docker build in a GitHub Action Workflow, the docker/build-push-action@v2 keeps outputting this error below. This is prior to running any of the commands in our 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]             ...

This outputs some 3000 lines of useless output, and appears to be some misconfiguration. How can I fix this root issue, or at least get the output under control?

It appears to be related to the last part of the docker buildx build command: --push https://github.com/org/project.git#abc123, but that does not seem to be within direct control in any of our configs.

CodePudding user response:

Turns out the build-push-action runs in a "GitHub" context by default. At the very least, it means pulling down your repository as part of pre-Dockerfile command.

You can change it to the "file" context by using:

      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          tags: user/app:latest

Since we take down the repository as part of a checkout action earlier, it was redundant.

  • Related