如何在gcloud中从部署中排除文件?

iul*_*net 10 google-cloud-storage google-cloud-platform gcloud

我已经构建了一个Node.js应用程序,我要部署的是cd进入我项目的目录并运行gcloud preview app deploy.这是有效的,但在文件中我还有一个JSON文件,其作用类似于我的应用程序的数据库,我不希望在部署时在网站上更新.我似乎无法找到任何办法.如果不可能,能够远程查看JSON文件并将其数据复制到本地文件,然后部署一切也会对我有所帮助,但我似乎无法做到这一点.

rbe*_*nto 13

在这种情况下,.gcloudignore文件将有助于阻止任何文件或目录的上传。语法与.gitignore文件相同。

首先,您可以确保gcloudignore已启用:

gcloud config list
Run Code Online (Sandbox Code Playgroud)

如果不是,那么您可以启用它:

gcloud config set gcloudignore/enabled true
Run Code Online (Sandbox Code Playgroud)

一些gcloud命令gcloud functions deploy可能会自动生成一个.gcloudignore文件。

.gcloudignore文件必须位于项目根文件夹中。

这是命令.gcloudignore自动生成的gcloud function deploy

# 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

node_modules
Run Code Online (Sandbox Code Playgroud)

对于具有以下结构的 NodeJS 项目,这对我来说效果很好:

# 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

node_modules
Run Code Online (Sandbox Code Playgroud)

在这种情况下,如果没有.gcloudignore这就是部署的内容:

在此处输入图片说明

具有以下内容.gcloudignore

.gcloudignore
.git
.gitignore
.idea
node_modules
package-lock.json
Run Code Online (Sandbox Code Playgroud)

这是部署的内容:

在此处输入图片说明

请参阅有关此内容的更多信息


Mic*_*Coy 12

我相信您会想要在app.yaml中使用skip_files指令来排除您不想部署的路径或文件.

就像是:

skip_files:
  - ^your_data_dir/.*\.json?
Run Code Online (Sandbox Code Playgroud)

  • 实际上,“skip_files”链接指向 Python 2.7 文档;Python 3 版本表示该选项“Python 3.7 不支持”,而 Node 文档甚至没有列出它。正如另一个答案中提到的,应该使用“.gcloudignore”文件。 (6认同)

Chr*_*nav 11

您的app.yaml中有skip_files指令,用于排除您不想部署的路径或文件.

但是如果您正在处理node.js项目,则必须使用.gcloudignore将指定要排除的目录的文件.

这个.gcloudignore会阻止上传node_modules /目录以及以〜结尾的所有文件:

  node_modules/
  *~
Run Code Online (Sandbox Code Playgroud)

参考文献:
1. https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore
2. https://cloud.google.com/appengine/docs/standard/nodejs/config/appref(搜索'skip_files')