Docs mention that to deploy an image to the App Engine you need the following step:
- name: 'gcr.io/cloud-builders/gcloud'
args:
- app
- deploy
- --image-url=gcr.io/[PROJECT-ID]/[IMAGE]:[TAG]
I have the cloudbuild.yaml that successfully builds a Docker image and then pushes it to gcr.io.
The step where it fails is running gcloud app deploy (fails due to the missing go source):
Step #2 - "deploy-to-app-engine": $ gcloud app deploy --image-url=gcr.io/redacted/redacted:9fac08d0e0f4421e1acdd66c88ac52c8ae7afdd8 --quiet
Step #2 - "deploy-to-app-engine":
Step #2 - "deploy-to-app-engine": ERROR: (gcloud.app.deploy) Staging command [/builder/google-cloud-sdk/platform/google_appengine/go-app-stager /workspace/app.yaml /workspace /tmp/tmp60W74I/tmpyoUm6x] failed with return code [1].
Step #2 - "deploy-to-app-engine":
Step #2 - "deploy-to-app-engine": ------------------------------------ STDOUT ------------------------------------
Step #2 - "deploy-to-app-engine": ------------------------------------ STDERR ------------------------------------
Step #2 - "deploy-to-app-engine": 2018/01/19 11:56:34 staging for go1.9
Step #2 - "deploy-to-app-engine": 2018/01/19 11:56:34 failed analyzing /workspace: cannot find package "bitbucket.org/redacted/redacted/redacted" in any of:
Step #2 - "deploy-to-app-engine": ($GOROOT not set)
Step #2 - "deploy-to-app-engine": /builder/home/go/src/bitbucket.org/redacted/redacted/redacted (from $GOPATH)
Step #2 - "deploy-to-app-engine": GOPATH: /builder/home/go
Step #2 - "deploy-to-app-engine": --------------------------------------------------------------------------------
I guess that gcloud app deploy command does some source checks for Go. Given that source is not available in this last step (part of it is in /workspace, part installed through dep) is it really necessary to do code analysis of local source when you are providing --image-url with a baked image that has all dependencies?
Even tried changing the deploy step based on this comment.
- name: 'gcr.io/cloud-builders/gcloud'
id: 'deploy-to-app-engine'
env:
- 'GOPATH=/go'
entrypoint: 'bash'
args:
- '-c'
- |
gcloud components install app-engine-go
mkdir -p /go/src/bitbucket.org/redacted/redacted
cp -R . /go/src/bitbucket.org/redacted/redacted
gcloud app deploy --image-url=gcr.io/$PROJECT_ID/redacted:$REVISION_ID --quiet
which then fails due to some other dependencies:
Step #3 - "deploy-to-app-engine": 2018/01/19 16:26:19 failed analyzing /go/src/bitbucket.org/readacted/readacted: cannot find package "github.com/gobuffalo/buffalo" in any of:
Step #3 - "deploy-to-app-engine": ($GOROOT not set)
Step #3 - "deploy-to-app-engine": /go/src/github.com/gobuffalo/buffalo (from $GOPATH)
Step #3 - "deploy-to-app-engine": GOPATH: /go
I was even trying to build my own image based on cloud-builders/gcloud, which additionally bundles Go and some dependencies, but that doesn't sound right. All I need is app deploy command for the published image.
Is there any way to deploy a Docker image to Flexible app engine environment for Go (via cloud builder)?
Thanks
What's the env: section of your app.yaml?
I believe you need to specify env: flex in order for the --image-url flag to work.
For example, the go/examples/hello_world_app specifies env: flex and deploys without this error.
I'll make a change to clarify this requirement in our docs.
It is flex.
Note: when I manually run the command from my laptop, the image is deployed to GAE.
It's even built well in the first step of container builder. And then pushed in the second.
The problem is with the gcloud app deploy. When running through container builder it doesn't have the source in the $GOPATH, because that doesn't exist anymore (in step 3). The only source that's passed through the steps is in /workspace, which is fine except when you need to build the go code. Expected behaviour would be that cloud-builders/gcloud (and gcloud app deploy command behind it) doesn't do extra code checks when image url flag is provided.
I don't know the internals here, so I'm not aware is there a reason behind it.
If source needs to be checked again, that means I have to create a separate image that would contain all my source again and bundle it with cloud-builders/gcloud. Basically duplicating build just for the deploy purpose.
The example you gave doesn't have publishing to the app engine. Just building the artifact and pushing to gcr.io. That works well for me.
When deploying using --image-url, make sure your app.yaml does not contain runtime: go. Seems like gcloud is invoking the Go stager because of runtime: go in your app.yaml.
Thanks @cybrcodr. That worked. I'm closing this.
If folks at GCP think that skipping Go stager when --image-url is provided (for runtime: go) they can open the internal ticket.
Most helpful comment
When deploying using --image-url, make sure your app.yaml does not contain
runtime: go. Seems like gcloud is invoking the Go stager because ofruntime: goin your app.yaml.