如何在云函数中定义源代码库中的目录

huangapple go评论62阅读模式
英文:

How can I define a directory in the source repository in a cloud function

问题

定义存储源代码的目录在源代码库中

嗨,我正在创建第二代云函数,并且正在使用来自另一个源代码库的代码。
我正在使用Terraform和模块"google_cloudfunctions2_function"。在"repo_source"中,我想定义一个目录"dir",其中包含我的"main"存储的位置。该文件存储在根目录中,然后在文件夹"parse_json"中。我的Terraform代码片段如下所示:

repo_source = {
  project_id  = var.project_id
  repo_name = "MY_REPO"
  branch_name   = "master"
  dir = "parse_json/"
}

无论如何,源函数仍然指向根目录,并且无法识别文件夹"parse_json"。
当我的代码不在根目录时,"dir"的语法是什么?

英文:

Define the directory where source code is stored in the source repository

Hi, I am creating a cloud function 2nd generation and I am using code from another source repository.
I am using Terraform and the module "google_cloudfunctions2_function". In the "repo_source" I want to define a directory in "dir" where my main is stored. The file is stored in the root and then in the folder parse_json. My terraform piece of code for this looks as follows:

repo_source = {

  project_id  = var.project_id

  repo_name = "MY_REPO"

  branch_name   = "master"

  dir = "parse_json/"
}

Anyway, the source function is still pointing to the root and it is not recognising the folder parse_json.
What is the syntax for "dir" when my code is not in the root?

答案1

得分: 1

"repo_source" 模块中的 "dir" 参数用于指定存储在源代码库中的主代码所在的目录。在您的情况下,如果您的代码位于存储库中的 "parse_json" 文件夹中,您应该将 "dir" 参数设置如下:

repo_source = {
  project_id   = var.project_id
  repo_name    = "MY_REPO"
  branch_name  = "master"
  dir          = "parse_json"
}

请注意,您不需要在目录路径中包含尾随斜杠 ("/")。在您的原始代码中,尾随斜杠可能导致源函数仍然指向根目录的问题。

通过将 "dir" 参数设置为 "parse_json",Terraform 将在指定存储库的 "parse_json" 目录中查找主代码文件。确保代码文件的命名符合预期(例如,main.py),并直接放置在存储库的 "parse_json" 文件夹中。

如果您已经进行了这些更改,但源函数仍然无法识别该文件夹,请确保存储库和分支名称正确,并且存储库中的文件结构与预期的目录结构匹配。

英文:

The "dir" parameter in the "repo_source" block of the "google_cloudfunctions2_function" module in Terraform is used to specify the directory where your main code is stored within the source repository. In your case, if your code is located in the "parse_json" folder within the repository, you should set the "dir" parameter as follows:

repo_source = {
  project_id   = var.project_id
  repo_name    = "MY_REPO"
  branch_name  = "master"
  dir          = "parse_json"
}

Note that you don't need to include the trailing slash ("/") in the directory path. In your original code, the trailing slash might be causing the issue where the source function is still pointing to the root.

By setting the "dir" parameter to "parse_json", Terraform will look for the main code file within the "parse_json" directory of the specified repository. Make sure the code file is named appropriately (e.g., main.py) and placed directly within the "parse_json" folder in the repository.

If you've made these changes and the source function still doesn't recognize the folder, ensure that the repository and branch names are correct, and the file structure in the repository matches the expected directory structure.

答案2

得分: 0

云函数 v2 目前实际上还不支持 Cloud Source Repositories。

您可以在此文档中查看相关信息。Google Cloud Functions 文档

英文:

The cloud functions v2 actually there is no support for Cloud Source Repositories yet.

Will be able to see it on this doc. Google Cloud Functions Documenation

huangapple
  • 本文由 发表于 2023年6月1日 22:20:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76382900.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定