Note: There is a similar post regarding this issue but it involves a CI/CD workflow and a considerably more complicated Dockerfile. The solutions presented do not seem to apply to my situation.
Per Google documentation I am attempting to build an image by running gcloud run deploy
in the directory where the files mentioned in my Dockerfile are located. The Dockerfile appears as:
FROM python:3.9-alpine
WORKDIR /app
COPY main.py /app/main.py
COPY requirements.txt /tmp/requirements.txt
RUN pip3 install -r /tmp/requirements.txt
CMD ["python3", "main.py"]
I receive a message that the build failed, and when checking the logs I see the following:
starting build "..."
FETCHSOURCE
Fetching storage object: gs://my-app_cloudbuild/source/....
Copying gs://my-app_cloudbuild/source/...
/ [0 files][ 0.0 B/ 1.5 KiB]
/ [1 files][ 1.5 KiB/ 1.5 KiB]
Operation completed over 1 objects/1.5 KiB.
BUILD
Already have image (with digest): gcr.io/cloud-builders/docker
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /workspace/Dockerfile: no such file or directory
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
Can anyone explain the reason for this error? I suspect it has to do with how files are copied to the image, but I was able to build and run this container without problem on my local machine. Any idea why this fails in Cloud Run Build?
Running ls -la
in the directory where I ran gcloud run deploy
returns:
drwxr-xr-x 9 user staff 288 May 20 16:04 .
drwxr-xr-x 6 user staff 192 May 20 13:35 ..
drwxr-xr-x 14 user staff 448 May 20 16:06 .git
-rw-r--r-- 1 user staff 27 May 20 15:06 .gitignore
-rw-r--r-- 1 user staff 424 May 20 16:54 Dockerfile
-rw-r--r-- 1 user staff 3041 May 20 15:55 main.py
-rw-r--r-- 1 user staff 144 May 19 09:42 requirements.txt
drwxr-xr-x 6 user staff 192 May 19 09:09 venv
Contents of .gitignore
:
Dockerfile
venv
*.gz
*.tar
*.pem
Full console output when attempting two-step build (see comments):
user@users-MacBook-Pro TwitterBotAQI % gcloud builds submit --tag gcr.io/missoula-aqi/aqi
Creating temporary tarball archive of 2 file(s) totalling 3.1 KiB before compression.
Some files were not included in the source upload.
Check the gcloud log [/Users/user/.config/gcloud/logs/2022.05.20/18.40.53.921436.log] to see which files and the contents of the
default gcloudignore file used (see `$ gcloud topic gcloudignore` to learn
more).
Uploading tarball of [.] to [gs://missoula-aqi_cloudbuild/source/1653093653.998995-48d4ba15b3274455a21e16b7abc7d65b.tgz]
Created [https://cloudbuild.googleapis.com/v1/projects/missoula-aqi/locations/global/builds/0c22d976-171e-4e7b-92d8-ec91704d6d52].
Logs are available at [https://console.cloud.google.com/cloud-build/builds/0c22d976-171e-4e7b-92d8-ec91704d6d52?project=468471228522].
------------------------------------------------------------------------------------ REMOTE BUILD OUTPUT -------------------------------------------------------------------------------------
starting build "0c22d976-171e-4e7b-92d8-ec91704d6d52"
FETCHSOURCE
Fetching storage object: gs://missoula-aqi_cloudbuild/source/1653093653.998995-48d4ba15b3274455a21e16b7abc7d65b.tgz#1653093655000531
Copying gs://missoula-aqi_cloudbuild/source/1653093653.998995-48d4ba15b3274455a21e16b7abc7d65b.tgz#1653093655000531...
/ [1 files][ 1.5 KiB/ 1.5 KiB]
Operation completed over 1 objects/1.5 KiB.
BUILD
Already have image (with digest): gcr.io/cloud-builders/docker
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /workspace/Dockerfile: no such file or directory
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BUILD FAILURE: Build step failure: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
ERROR: (gcloud.builds.submit) build 0c22d976-171e-4e7b-92d8-ec91704d6d52 completed with status "FAILURE"
I had added Dockerfile
to .gitignore
as it contained API keys stored as environment variables. Removing Dockerfile
from .gitignore
resolved the issue.