4

I am attempting to use google cloud build triggers build my docker containers. Unfortunately the build is not finding my docker file. It isn't at the root of my repository but I thought that I could specify a relative path. Clearly I misconfigured something. Below is my cloudbuild.yaml and the output logs.

And if it matters - my code is in github but I configured the trigger to pull from that repo.

steps:
- name: 'gcr.io/cloud-builders/docker'
  args:
  - 'build'
  - '--tag=gcr.io/$PROJECT_ID/domain-session-test:$TAG_NAME'
  - '--file=session_server/deployments/DockerFiles/minimal.Dockerfile'
  - '.'
- name: 'gcr.io/cloud-builders/docker'
  args: ['run', 'gcr.io/$PROJECT_ID/domain-session-test:$TAG_NAME', 'go', 'test']
- name: 'gcr.io/cloud-builders/gsutil'
  args: ['cp', '-r', 'k8s/*', 'gs://$PROJECT_ID-kubernetes-manifests']
images: ['gcr.io/$PROJECT_ID/domain-session-test:$TAG_NAME']

Logs:

starting build "1c4ee154-2c29-4e81-b884-d64c54841d71"    
    FETCHSOURCE
    Initialized empty Git repository in /workspace/.git/
    From https://source.developers.google.com/p/MYURL
    * branch c2d8260a49d9972d1b0882c1676184be35b4c33c -> FETCH_HEAD
    HEAD is now at c2d8260 triggering a build
    BUILD
    Starting Step #0
    Step #0: Already have image (with digest): gcr.io/cloud-builders/docker
    Step #0: unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /workspace/Dockerfile: no such file or directory
    Finished Step #0
    ERROR
    ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1
mornindew
  • 1,993
  • 6
  • 32
  • 54
  • Check this post: https://stackoverflow.com/questions/35511604/docker-unable-to-prepare-context-unable-to-evaluate-symlinks-in-dockerfile-pat ;) – debiasej Dec 16 '19 at 11:02

1 Answers1

3

I ran into something similar when using a . for the Docker context.

I was getting this error...

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

...when using a cloudbuild.yaml similar to this:

steps:
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/[PROJECT_ID]/[IMAGE]', '.']
# Push the image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
  args: ['push', 'gcr.io/[PROJECT_ID]/[IMAGE]']
# Deploy image to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
  args:
  - 'run'
  - 'deploy'
  - '[SERVICE_NAME]'
  - '--image'
  - 'gcr.io/[PROJECT_ID]/[IMAGE]'
  - '--region'
  - '[REGION]'
  - '--platform'
  - 'managed'
images:
- gcr.io/[PROJECT_ID]/[IMAGE]

The issue was that my cloudbuild.yaml assumed the working directory would be the same dir that contains the cloudbuild.yaml and Dockerfile.

While my Cloud Build Trigger definition knew where to find the cloudbuild.yaml file, it apparently executes that with a working dir that is in the root of the repo, and the root of the repo doesn't contain the Dockerfile.


If I use a build step similar to the one below, the issue is resolved.

# Build the container image
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/[PROJECT_ID]/[IMAGE]', '<DIR_CONTAINING_DOCKERFILE>']
derekbaker783
  • 8,109
  • 4
  • 36
  • 50
  • Hello derekbaker... so glad i found your post as i have been stuck on this for a while. However, i am wondering how will it work if i use eg a dockerfile called Dockerfile_abcde. I am attempting to use the following command - name: gcr.io/cloud-builders/docker args: [ 'build' , '--tag=gcr.io/$PROJECT_ID/$_IMAGE_NAME' , '--file=Dockerfile_pipeline' , './dataflow/pipeline/' ] but it does not seem to work. My project is here https://github.com/mmistroni/GCP_Experiments/tree/master/dataflow/pipeline appreciate your help – user1068378 Aug 05 '21 at 07:12