Felix
Felix

Reputation: 332

GCP Cloud Build via trigger: Dockerfile not found

I attempt to trigger building a Docker image on GCP Cloud Build via webhook called from Gitlab. The webhook works, but the build process stops when I run docker build with this error:

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /workspace/Dockerfile: no such file or directory

The YAML for this step is:

  - name: gcr.io/cloud-builders/docker
    args:
      - build
      - '-t'
      - '${_ARTIFACT_REPO}'
      - .

where I later supply the variable _ARTIFACT_REPO via substitutions.

My Gitlab repo includes the Dockerfile on the root level. So the repo structure is:

app/
.gitignore
Dockerfile
README.md
requirements.txt

The error message indicates that the Dockerfile cannot be found, but I do not understand why this is the case. Help is much appreciated!

Upvotes: 1

Views: 489

Answers (1)

Felix
Felix

Reputation: 332

Just solved the issue:

I followed the GCP docs (link) where they include these two steps in the cloudbuild:

- name: gcr.io/cloud-builders/git
  args:
    - clone
    - '-n'
    - '[email protected]/GITLAB_REPO'
    - .
  volumes:
    - name: ssh
      path: /root/.ssh
- name: gcr.io/cloud-builders/git
  args:
    - checkout
    - $_TO_SHA

As I did not require a specific checkout, I deleted the second step of those but I overlooked the -n flag in the first step that prevents checking out the cloned repo.

So I just deleted the - '-n' and issue solved.

Upvotes: 1

Related Questions