【发布时间】:2018-03-08 03:19:45
【问题描述】:
当我跑步时
gcloud app deploy app.yaml
实际上传了哪些文件?
项目文件夹包含与部署的应用程序无关的文件夹和文件,例如.git、.git_ignore、Makefile 或venv。
gcloud app deploy 如何决定上传哪些文件?
【问题讨论】:
标签: python google-app-engine google-app-engine-python
当我跑步时
gcloud app deploy app.yaml
实际上传了哪些文件?
项目文件夹包含与部署的应用程序无关的文件夹和文件,例如.git、.git_ignore、Makefile 或venv。
gcloud app deploy 如何决定上传哪些文件?
【问题讨论】:
标签: python google-app-engine google-app-engine-python
tl;dr:你应该使用.gcloudignore 文件,而不是app.yaml 中的skip_files。
虽然前两个答案在app.yaml 文件中使用了skip_files。现在有一个.gcloudignore 是在使用gcloud deploy 或upload 命令时创建的。默认值取决于您使用的检测到的语言,但这里是自动创建的 .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__/
注意:当skip_files 已定义且.gcloudignore 存在时,这些命令将不起作用。 skip_filesdefinition of theapp.yaml` reference中没有提到这一点。
在gcloud 命令之间拥有一个全球公认的标准似乎更好,并且采用.gcloudignore 与使用skip_files 相比更有意义,skip_files 仅在没有 App Engine 的情况下相关。此外,它的工作方式非常类似于参考文献中提到的.gitignore 文件:
.gcloudignore 的语法大量借鉴了 .gitignore 的语法; 请参阅 https://git-scm.com/docs/gitignore 或 man gitignore 获取完整信息 参考。
https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore
【讨论】:
2018 年 8 月编辑:Google 此后推出了 .gcloudignore,现在是首选,请参阅 dalanmiller 的回答。
它们都已上传,除非您使用 app.yaml 中的 skip_files 指令。默认情况下会忽略带有.git 之类的点的文件。如果您想添加更多内容,请注意您正在覆盖这些默认值,并且几乎肯定希望保留它们。
skip_files:
- ^Makefile$
- ^venv$
# Defaults
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
还要注意,如果您使用静态处理程序,它们会被上传到不同的地方。静态文件被发送到 CDN,并且对您的语言运行时不可用(尽管也有解决方法)。
请务必阅读文档:
https://cloud.google.com/appengine/docs/standard/python/config/appref#skip_files
【讨论】:
ls 上传了哪些文件?所以我可以改造 skip_files 设置。
skip_files 默认值,这可能会导致问题,请参阅:stackoverflow.com/questions/46311440/…
gcloud app deploy 如何决定上传哪些文件?
它没有。它默认上传所有内容。正如另一个回复中提到的,您可以使用 app.yaml 中的skip_files 部分,如下所示:
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
- ^(.*/)?\.bak$
- ^\.idea$
- ^\.git$
您还可以使用--verbosity 参数查看正在部署的文件,即gcloud app deploy app.yaml --verbosity=debug 或gcloud app deploy app.yaml --verbosity=info per docs。
【讨论】: