使用源存储库从命令行重新部署 Google Cloud Function

Redeploy Google Cloud Function from command line using Source Repositories

我有一个相当简单的 Google Cloud Function,我正在从 Cloud Source Repositories 部署。

我正在使用 Google 云 Shell 作为我的开发机器。

当我在开发过程中对函数进行更新时,我使用 CLI 将更新推送到我的源存储库。但是,运行从命令行执行 gcloud functions deploy ... 命令似乎不会 强制 GCF 引入最新的源代码。

有时,推送新源代码后的 deploy 命令会简单地显示 "Nothing to update."(这是不正确的。)

更常见的是,它会经历部署过程,但功能仍会 运行 以前版本的代码。

发生这种情况时,我可以更新功能的唯一方法是使用仪表板,"Edit" 功能,然后点击“部署”按钮(即使我没有进行任何更改。)

我是不是忘了做一些必要的版本控制或标记?有没有办法强制 CLI 从源代码库中提取最新的提交?

我认为您正在寻找 --source=SOURCE gcloud functions deploy 选项来指向源存储库而不是当前目录(默认):

--source=SOURCE

Location of source code to deploy. Location of the source can be one of the following three options:

  • Source code in Google Cloud Storage (must be a .zip archive),
  • Reference to source repository or,
  • Local filesystem path (root directory of function source).

Note that if you do not specify the --source flag:

  • Current directory will be used for new function deployments.
  • If the function is previously deployed using a local filesystem path, then function's source code will be updated using the current directory.
  • If the function is previously deployed using a Google Cloud Storage location or a source repository, then the function's source code will not be updated.

The value of the flag will be interpreted as a Cloud Storage location, if it starts with gs://.

The value will be interpreted as a reference to a source repository, if it starts with https://.

Otherwise, it will be interpreted as the local filesystem path. When deploying source from the local filesystem, this command skips files specified in the .gcloudignore file (see gcloud topic gcloudignore for more information). If the .gcloudignore file doesn't exist, the command will try to create it.

The minimal source repository URL is: https://source.developers.google.com/projects/${PROJECT}/repos/${REPO}

By using the URL above, sources from the root directory of the repository on the revision tagged master will be used.

If you want to deploy from a revision different from master, append one of the following three sources to the URL:

  • /revisions/${REVISION},
  • /moveable-aliases/${MOVEABLE_ALIAS},
  • /fixed-aliases/${FIXED_ALIAS}.

If you'd like to deploy sources from a directory different from the root, you must specify a revision, a moveable alias, or a fixed alias, as above, and append /paths/${PATH_TO_SOURCES_DIRECTORY} to the URL.

Overall, the URL should match the following regular expression:

  ^https://source\.developers\.google\.com/projects/
  (?<accountId>[^/]+)/repos/(?<repoName>[^/]+)
  (((/revisions/(?<commit>[^/]+))|(/moveable-aliases/(?<branch>[^/]+))|
  (/fixed-aliases/(?<tag>[^/]+)))(/paths/(?<path>.*))?)?$

An example of a validly formatted source repository URL is:

  https://source.developers.google.com/projects/123456789/repos/testrepo/
  moveable-aliases/alternate-branch/paths/path-to=source