运行`gcloud app deploy`时如何忽略文件?

Lar*_*erg 6 python google-app-engine google-app-engine-python

当我跑步

gcloud app deploy app.yaml
Run Code Online (Sandbox Code Playgroud)

实际上传了哪些文件?

项目文件夹包含文件夹和文件,如.git.git_ignoreMakefilevenv不相关的部署的应用程序。

如何gcloud app deploy确定上传哪些文件?

dal*_*ler 13

tl; dr:您应该使用.gcloudignore文件,而不是skip_files中的文件app.yaml

而前两个答案skip_filesapp.yaml文件中使用。现在.gcloudignore,使用gcloud deployupload命令时会创建一个。默认值取决于您使用的检测到的语言,但是会自动创建.gcloudignore在Python项目中找到的语言:

# 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__/
Run Code Online (Sandbox Code Playgroud)

注意:当两个命令都skip_files定义并且.gcloudignore同时存在时,这些命令将不起作用。skip_files definition of theapp.yaml`参考中未提及此内容。

gcloud命令之间具有全球公认的标准似乎更好,并且.gcloudignoreskip_files仅在没有App Engine时才有意义的相比,采用vs 有意义。此外,它的工作原理很像.gitignore参考文件中提到的文件:

.gcloudignore的语法大量来自.gitignore的语法;有关完整参考,请参见https://git-scm.com/docs/gitignore或man gitignore。

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


Chr*_*ris 10

编辑2018年8月:自从Google引入以来.gcloudignore,现在是首选,请参见dalanmiller的答案。


它们都已上传,除非您使用中的skip_files说明app.yaml.git默认情况下会忽略带有点的文件。如果要添加更多内容,请注意,您要覆盖这些默认值,并且几乎可以肯定要保留这些默认值。

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

还请注意,如果您使用静态处理程序,它们会上传到其他位置。静态文件被发送到CDN,并且在您的语言运行时不可用(尽管也有解决方法)。

确保阅读文档:

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