How do I limit the files deployed to the AppEngine instances?
I am updating a Google AppEngine Standard Environment deployment from 1.11 to the 1.12+ environment. To be able to compile, I need to create a go.mod in the top-level directory of the project. The project builds and deploys just fine.
Previously, only the files relative to the directory the gcloud app deploy command was run is was available in the container, so my versions were around 20 megabyte (binary, some static HTML files, and apparently the main package go source, for some reason).
Now, all files from the go.mod and down are deployed, including all packages and all the vendored third-party source code, resulting in a 250 megabyte deployed image.
I am trying to find any documentation on how to limit which files get deployed to the versioned instance, but fall short. The .gcloudignore file drops some files from the upload, but if I add the sources here the project, quite obviously, cannot build. I cannot find anything in the app.yaml reference on how to limit the list of deployed files (I was under the impression it would only include the files listed as upload clauses, but that is quite apparently incorrect).
Hi @nafmo,
Welcome to Google Cloud Community!
Based on this documentation on Go 1.12+ Runtime Environment, you can add the runtime in your app.yaml file:
runtime: go120
If you want to deploy a specific yaml file, you must deploy your app based on this documentation on defining runtime settings:
gcloud app deploy name-of-your-app.yaml
I think you misunderstood the question, so let me try to clarify: I am trying to control which files are in the bundle that is deployed on AppEngine. It deploys the code from the "app" directory and down, and without go.mod I can get away with having only the main.go file (defining the handlers), and unfortunately that source file is in the deployed image, but nothing else.
When I add a go.mod file, I have to put that at the top of my app structure, which is one level above the main.go file. Now the bundle contains all the source files, my entire application and all the vendored dependencies, none of which are needed there.
I need to upload everything in the "gcloud deploy" so that AppEngine can compile my application, but I cannot seem to control the next step, where it creates the container that is run on AppEngine.
I understand the scenario. I already replicate similar scenario and I noticed that there's an increase of size when using the following versions:
go 1.12
go 1.13
go 1.14
I also used the following versions and their sizes are similar and much smaller:
go 1.15
go 1.16
go 1.18
go 1.19
go 1.20 (preview)
Please try testing using the versions that I used where the size is smaller.
I do get a slightly smaller deployed build with go 1.20 than I did with go 1.11, but that is probably because I had to remove one of the entry points as it used an API not supported by the appengine/v2 legacy packages that was necessary for 1.12+.
I don't think the size of the actual binary differs at all between a regular build and the go.mod-based build, however, it is that the deployed bundle contains the entire source tree, which the "legacy" build mode doesn't.