pythongoogle-app-enginegoogle-app-engine-python

How to ignore files when running `gcloud app deploy`?


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?


Solution

  • 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