duanlongnao0028 2018-08-31 14:54
浏览 36
已采纳

使用Cloud Build部署App Engine go应用

Goal:

Using Cloud Build configuration - build an app into an artifact that can be deployed to app engine.

Solution that's not working:

This is cloudbuild.yaml:

steps:
- name: 'gcr.io/cloud-builders/go'
  args: ['get']
  env: ['PROJECT_ROOT=project-name']
- name: 'gcr.io/cloud-builders/go'
  args: ['build', '.']
  env: ['PROJECT_ROOT=project-name']
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['app', 'deploy']
timeout: '1600s'

artifacts:
  objects:
    location: 'gs://project-artifacts/'
    paths: ['project-name']

App Engine config app.yaml:

runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app

And finally main.go: https://github.com/GoogleCloudPlatform/golang-samples/blob/master/appengine/helloworld/hello.go

I do understand that the deploy step is now very naive and doesn't even need the previous 2 steps. Consulting the cloud app help, I wasn't able to see whether the deploy step can accept external artifact.

The deploy step fails with:

failed analyzing /workspace: cannot find package "google.golang.org/appengine" in any of:
    ($GOROOT not set)
    /builder/home/go/src/google.golang.org/appengine (from $GOPATH)
GOPATH: /builder/home/go

I'm looking for 2 solutions:

  1. Ideally being able to build artifacts into project-artifacts bucket and deploy them using the deploy step
  2. If that's not possible I at least need to know how to run gcloud components install app-engine-go within the deploy container so it doesn't fail with missing dependency.
  • 写回答

1条回答 默认 最新

  • dounabi6295 2018-09-13 07:46
    关注

    Use a GOPATH outside of your build directory (/workspace). For example, /gopath.

    Additionally, because by default only /workspace is preserved between Cloud Build steps, you must put your GOPATH in a volume.

    The following complete example works for me:

    steps:
    
    - name: 'gcr.io/cloud-builders/go'
      args: ['get', '-d', './...']
      env: ['GOPATH=/gopath']
      volumes:
      - name: 'go'
        path: '/gopath'
    
    - name: 'gcr.io/cloud-builders/gcloud'
      args: ['app', 'deploy']
      env: ['GOPATH=/gopath']
      volumes:
      - name: 'go'
        path: '/gopath'
    

    Additionally, I had to grant the App Engine Admin role to the Cloud Build service account in IAM for the gcloud app deploy step to succeed within Cloud Build.

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

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧