Google Cloud Build Error: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1

Google Cloud Build Error: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1

注意:关于此问题有类似的 post,但它涉及 CI/CD 工作流程和相当复杂的 Dockerfile。所提供的解决方案似乎不适用于我的情况。

Per Google documentation 我正在尝试通过 运行ning gcloud run deploy 在我的 Dockerfile 中提到的文件所在的目录中构建图像。 Dockerfile 显示为:

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"]

我收到构建失败的消息,在检查日志时我看到以下内容:

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

任何人都可以解释这个错误的原因吗?我怀疑这与文件复制到映像的方式有关,但我能够在我的本地机器上毫无问题地构建和 运行 这个容器。知道为什么这在 Cloud 运行 Build 中失败了吗?

运行宁ls -la在我所在目录运行gcloud run deployreturns:

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

.gitignore 的内容:

Dockerfile
venv
*.gz
*.tar
*.pem

尝试两步构建时的完整控制台输出(见评论):

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"

我已将 Dockerfile 添加到 .gitignore,因为它包含 API 存储为环境变量的密钥。从 .gitignore 中删除 Dockerfile 解决了问题。