运行`gcloud app deploy`时如何忽略文件?
我跑步时
gcloud app deploy app.yaml
实际上上传了哪些文件?
which files actually get uploaded?
项目文件夹包含与已部署的应用程序无关的文件夹和文件,例如.git
,.git_ignore
,Makefile
或venv
.
The project folder contains folders and files such as .git
, .git_ignore
, Makefile
or venv
that are irrelevant for the deployed application.
gcloud app deploy
如何决定上传哪些文件?
How does gcloud app deploy
decide which files get uploaded?
tl; dr:dr:您应该使用.gcloudignore
文件,而不是app.yaml
中的skip_files
.
tl;dr: you should use a .gcloudignore
file, not skip_files
in app.yaml
.
尽管前两个答案使用了app.yaml
文件中的skip_files
.现在,使用gcloud deploy
或upload
命令时会创建一个.gcloudignore
.默认值取决于您使用的检测到的语言,但是这里是在我的Python项目中自动创建的.gcloudignore
:
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__/
注意:当同时定义了skip_files
和.gcloudignore
时,这些命令将不起作用. skip_files definition of the
app.yaml`参考中未提及.
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 the
app.yaml` reference.
在gcloud
命令中具有全球公认的标准似乎更好,并且与仅在不使用App Engine时才有用的skip_files
相比,采用.gcloudignore
更有意义.此外,它的工作原理很像参考文献中提到的.gitignore
文件:
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:
.gcloudignore的语法从.gitignore的语法中大量借用; 请参阅 https://git-scm.com/docs/gitignore 或man 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