duangan9251 2019-01-18 06:42
浏览 42
已采纳

Google Cloud Functions(Golang)和Terraform [关闭]

Go support for google cloud functions has just ben released top beta.

I have been searching for any examples / tutorials on using Google CloudFunctions (for golang specifically) with Terraform and the required workflow including using CloudBuild to build, test and deploy to GCP.

Does anyone know of such an example / blog on this and can share a link? I know go is newly beta so unlikely. Im a newbie to GCP toolchain (coming from AWS CloudFormation, Code Pipeline/Build and Lambda/Go) so keen to see the best practice setup for end to end workflow on GCP. Would be a great post if someone with the experience was keen!!

Thanks

  • 写回答

1条回答 默认 最新

  • dougai2427 2019-01-18 13:25
    关注

    I work at GCP and on Cloud Functions for Go.

    I haven't tested this full flow yet, but hopefully this points you in the right direction before getting a full walkthrough/blog post.

    You can create a Cloud Build trigger with the following snippet, from https://www.terraform.io/docs/providers/google/r/cloudbuild_trigger.html:

    resource "google_cloudbuild_trigger" "build_trigger" {
      project  = "my-project"
      trigger_template {
        branch_name = "master"
        project     = "my-project"
        repo_name   = "some-repo"
      }
      filename = "cloudbuild.yaml"
    }
    

    From that trigger, you can use this cloudbuild.yaml adapted from the example in https://cloud.google.com/functions/docs/bestpractices/testing#continuous_testing_and_deployment:

    steps:
    - name: 'gcr.io/cloud-builders/go:latest'
      args: ['test', '[YOUR_FUNCTION_PACKAGE]']
      env: 'GOPATH=.'
    - name: 'gcr.io/cloud-builders/gcloud'
      args: ['functions', 'deploy', '[YOUR_DEPLOYED_FUNCTION_NAME]', '[YOUR_FUNCTION_TRIGGER]', '--runtime', 'go111', '--entry-point', '[YOUR_FUNCTION_NAME_IN_CODE]']
      dir: 'functions/autodeploy'
    

    See https://github.com/GoogleCloudPlatform/cloud-builders/tree/master/go for examples of configuring Cloud Build for Go. This setup would deploy the function from Cloud Build rather than using google_cloudfunctions_function with Terraform.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料