运行 `gcloud app deploy` 时如何忽略文件?
How to ignore files when running `gcloud app deploy`?
当我运行
gcloud app deploy app.yaml
实际上传了哪些文件?
项目文件夹包含与部署的应用程序无关的文件夹和文件,例如 .git
、.git_ignore
、Makefile
或 venv
。
gcloud app deploy
如何决定上传哪些文件?
编辑 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
How does gcloud app deploy decide which files get uploaded?
没有。它默认上传所有内容。如另一个回复中所述,您可以使用 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.
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 the
app.yaml` reference.
中没有提到这个
在 gcloud
命令中采用全球公认的标准似乎更好,采用 .gcloudignore
与使用仅在没有 App Engine 的情况下相关的 skip_files
更有意义。此外,它的工作方式非常类似于参考文献中提到的 .gitignore
文件:
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
当我运行
gcloud app deploy app.yaml
实际上传了哪些文件?
项目文件夹包含与部署的应用程序无关的文件夹和文件,例如 .git
、.git_ignore
、Makefile
或 venv
。
gcloud app deploy
如何决定上传哪些文件?
编辑 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
How does gcloud app deploy decide which files get uploaded?
没有。它默认上传所有内容。如另一个回复中所述,您可以使用 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.
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 the
app.yaml` reference.
在 gcloud
命令中采用全球公认的标准似乎更好,采用 .gcloudignore
与使用仅在没有 App Engine 的情况下相关的 skip_files
更有意义。此外,它的工作方式非常类似于参考文献中提到的 .gitignore
文件:
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