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.

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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看