25

When I run

gcloud app deploy app.yaml

which files actually get uploaded?

The project folder contains folders and files such as .git, .git_ignore, Makefile or venv that are irrelevant for the deployed application.

How does gcloud app deploy decide which files get uploaded?

Lars Blumberg
  • 19,326
  • 11
  • 90
  • 127

3 Answers3

44

tl;dr: you should use a .gcloudignore file, not skip_files in app.yaml.

While the prior two answers make use of skip_files in the app.yaml file. There is now a .gcloudignore that is created when using gcloud deploy or upload commands. The default will depend on the detected language that you are using but here is automatically created .gcloudignore that I found in my Python project:

# This file specifies files that are *not* uploaded to Google Cloud Platform 
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
#   $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below: 
.git 
.gitignore

# Python pycache:
__pycache__/

Note: These commands will not work when both skip_files is defined and .gcloudignore is present. This is not mentioned in the skip_filesdefinition of theapp.yaml` reference.

It seems better to have a globally recognized standard across gcloud commands and makes more sense to adopt the .gcloudignore versus using the skip_files which is only relevant without App Engine. Additionally, it works pretty much like a .gitignore file which the reference mentions:

The syntax of .gcloudignore borrows heavily from that of .gitignore; see https://git-scm.com/docs/gitignore or man gitignore for a full reference.

https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore

dalanmiller
  • 3,467
  • 5
  • 31
  • 38
12

EDIT Aug 2018: Google has since introduced .gcloudignore, which is now preferred, see dalanmiller's answer.


They're all uploaded, unless you use the skip_files instruction in app.yaml. Files with a dot like .git are ignored by default. If you want to add more, beware that you're overriding these defaults and almost certainly want to keep them around.

skip_files:
  - ^Makefile$
  - ^venv$
  # Defaults
  - ^(.*/)?#.*#$
  - ^(.*/)?.*~$
  - ^(.*/)?.*\.py[co]$
  - ^(.*/)?.*/RCS/.*$
  - ^(.*/)?\..*$

Note also that they are uploaded to different places if you use a static handler. Static files are sent to a CDN and are not available to your language run time (although there are ways around that, too).

Make sure to read the docs:

https://cloud.google.com/appengine/docs/standard/python/config/appref#skip_files

Chris
  • 6,805
  • 3
  • 35
  • 50
  • Thanks. Is there a way to `ls` which files got uploaded? So I can retrofit that `skip_files` setting. – Lars Blumberg Sep 26 '17 at 19:28
  • Not sure. They keep adding features, I think there are some things available in the cloud console that allow you to inspect deployed code, but I've never used them. – Chris Sep 26 '17 at 19:29
  • @Chris Careful with that example - it overwrites the `skip_files` defaults, which can cause problems, see: https://stackoverflow.com/questions/46311440/appengine-no-module-named-pyasn1-compat-binary?noredirect=1#comment79607866_46311440 – Dan Cornilescu Sep 26 '17 at 19:31
  • Bonus question: I'm using a "flexible environment". So my static files get deployed to the same computing instance and not CDN, right? Is that fine? Or should I take action? – Lars Blumberg Sep 26 '17 at 19:34
  • This covers it: https://cloud.google.com/appengine/docs/flexible/python/serving-static-files – Lars Blumberg Sep 26 '17 at 19:50
2

How does gcloud app deploy decide which files get uploaded?

It doesn't. It uploads everything by default. As mentioned in another response you can use the skip_files section in app.yaml as follows:

skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
- ^(.*/)?\.bak$
- ^\.idea$
- ^\.git$

You can also use the --verbosity param to see what files are being deployed, i.e. gcloud app deploy app.yaml --verbosity=debug or gcloud app deploy app.yaml --verbosity=info per docs.

Mihail Russu
  • 2,526
  • 1
  • 17
  • 27