使用 Cloud Build 从 git 持续部署

Continuous deployment from git using Cloud Build

我正在尝试使用 this tutorial 为 Cloud 运行 创建一个构建触发器, 但我收到以下错误消息:

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: step exited with non-zero status: 1

有人知道为什么吗?

编辑:我的项目回购分为前端和后端文件夹。我只是想部署我的后端文件夹,其中包含一个 go api.

错误显示 /workspace/Dockerfile: no such file or directory

我想您的存储库在其根目录中不包含 Dockerfile

我按照您提供的教程进行操作,但遇到了相同的错误消息。

似乎 cloudbuild.yaml 文件中指定的步骤需要在存储库根文件夹中创建 Dockerfile。准确地说,以下说明是在您的 . 文件夹中构建图像。

- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/$PROJECT_ID/[SERVICE-NAME]:$COMMIT_SHA', '.']

您的问题有两种解决方案。如果您需要构建 docker 图像,只需创建 Dockerfile 即可解决您的问题。另一种解决方案是不使用自定义图像。为了成功部署,我使用了以下 cloudbuild.yaml 文件:

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  args:
  - 'run'
  - 'deploy'
  - '[SERVICE-NAME]'
  - '--image'
  - 'gcr.io/cloudrun/hello'
  - '--region'
  - '[REGION]'
  - '--platform'
  - 'managed'

请注意我仍在使用容器映像 (gcr.io/cloudrun/hello)。

-- 编辑

正如@guillaume-blaquiere 所解释的那样,本教程理所当然地认为您的存储库已经在云端运行 运行。你应该在这个之前检查一个Cloud Run tutorial

-- 编辑 2

适用于 OP 的第三个解决方案是在构建指令中指定 Dockerfile 的路径。这是通过更改包含 Dockerfile.

的相对目录的 . 目录来完成的