How do I select which files to deploy to a Standard Environment AppEngine in Google Cloud?

558 views Asked by At

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). The rest of the source files (vendored code and handler implementation) is in a directory parallel to the main.go:

$GOPATH
├── web       << "gcloud app deploy" runs from here
│   ├── main.go
│   ├── .gcloudignore
│   └── html
│       └── index.html
├── handler
│   └── implementation
├── cloud.google.com
│   ├── datastore
:   :

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.

src        << "gcloud app deploy" runs from here
├── go.mod
├── .gcloudignore
├── web
│   ├── main.go
│   └── html
│       └── index.html
├── handler
│   └── implementation
├── vendor 
│   └── cloud.google.com
│       ├── datastore
:       :

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).

My .gcloudignore file is the standard one generated by gcloud, with a few minor additions (comment lines stripped for brevity):

.gcloudignore
.git
.gitignore
.gitrepo
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
Makefile
web
*.sh

Here is a snippet from app.yaml:

runtime: go119
app_engine_apis: true
default_expiration: "1d"
env_variables:
  GCE_METADATA_HOST: "169.254.169.254"

handlers:
- url: /
  login: required
  script: auto
  secure: always
  redirect_http_response_code: 301

- url: /robots.txt
  static_files: robots.txt
  upload: robots.txt

- url: /favicon.ico
  static_files: html/favicon.ico
  upload: html/favicon.ico

- url: /api/?.*
  script: auto
  secure: always

- url: /ping/?.*
  script: auto
  secure: always

- url: /offline.js
  login: optional
  static_files: html/offline.js
  upload: html/offline.js
  secure: always

- url: /_ah/queue/go/delay
  script: auto
  secure: always
  login: admin
1

There are 1 answers

9
Roopa M On

You can prevent unnecessary files from being deployed by using the app.yaml option skip_files

The skip_files element specifies which files in the application directory are not to be uploaded to App Engine. The value is either a regular expression, or a list of regular expressions. Any filename that matches any of the regular expressions is omitted from the list of files to upload when the application is uploaded. Filenames are relative to the project directory.