云构建完成,状态为 FAILURE;其他问题如下

Cloud build completes with FAILURE status; other issues follow

我一直关注 video 来自 Google Tech Build youtube 频道的新“Serverless Expeditions”系列,这真的很棒而且很简洁。强烈推荐。

这是我第一次使用 GCP 进行试验,但在我遇到一个奇怪的错误之前一切都运行得很完美:

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
----------------------------------------------------------------------------------------------------------------------
ERROR: (gcloud.builds.submit) build 0caec01a-ba4e-4a58-afd3-5f646258ae72 completed with status "FAILURE"
Deploying container to Cloud Run service [test-api-service] in project [test-api] region [us-central1]
X Deploying... Image 'gcr.io/test-api/test-api-service' not found.                                               
  X Creating Revision... Image 'gcr.io/test-api/test-api-service' not found.                                     
  . Routing traffic...                                                                                               
  ✓ Setting IAM Policy...                                                                                            
Deployment failed                                                                                                    
ERROR: (gcloud.run.deploy) Image 'gcr.io/test-api/test-api-service' not found.

执行部署时 shell 脚本:

GOOGLE_PROJECT_ID=test-api
CLOUD_RUN_SERVICE=test-api-service
INSTANCE_CONNECTION_NAME=test-api:us-central-1:test-sql-instance
DB_USER=root
DB_PASS=testpw
DB_NAME=testdb

gcloud builds submit --tag gcr.io/$GOOGLE_PROJECT_ID/$CLOUD_RUN_SERVICE \
    --project=$GOOGLE_PROJECT_ID

gcloud run deploy $CLOUD_RUN_SERVICE \
    --image gcr.io/$GOOGLE_PROJECT_ID/$CLOUD_RUN_SERVICE \
    --add-cloudsql-instances $INSTANCE_CONNECTION_NAME \
    --update-env-vars INSTANCE_CONNECTION_NAME=$INSTANCE_CONNECTION_NAME,DB_PASS=$DB_PASS,DB_NAME=$DB_NAME,DB_USER=$DB_USER \
    --platform managed \
    --region us-central1 \
    --allow-unauthenticated \
    --project=$GOOGLE_PROJECT_ID

请注意,这是视频中技术演示者使用的部署脚本。我们正在使用 node.js 和 MySQL 构建 REST API。我环顾四周,似乎真的找不到解决这个问题的方法。也许一些外部帮助可能会阐明一些可能的解决方案。

提前致谢!

正如@JohnHanley 和@guillaumeblaquiere 在评论中提到的,问题是由 Dockerfile 引起的。

尽管此文件是必需的,但您完成的 tutorial 并未涵盖 Dockerfile 结构。

您可以使用 containerizing guide for Node.js 来完成您的配置。