16

I have built a Node.js app and what I do to deploy is cd into my project's directory and run gcloud preview app deploy. This works, but in the files I also have a JSON file which acts like the database for my application, which I do not want updated on the site when I deploy.

I cannot seem to find any way of doing this.

Any idea?

4 Answers 4

22

In this case, a .gcloudignore file would help by preventing the upload of any file or directory. The syntax is the same as the .gitignore file.

First you could make sure gcloudignore is enabled:

gcloud config list

If it is not, then you may enable it:

gcloud config set gcloudignore/enabled true

Some gcloud commands like gcloud functions deploy may automatically generate a .gcloudignore file.

The .gcloudignore file must reside in the project root folder.

Here is the .gcloudignore that is automatically generated by the gcloud function deploy command:

# 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

This worked fine for me with a NodeJS project with the following structure:

~/Workspace/my-project $ tree -a
.
├── .idea
│   ├── func-project.iml
│   ├── misc.xml
│   ├── modules.xml
│   ├── vcs.xml
│   └── workspace.xml
├── .gcloudignore
├── index.js
├── package-lock.json
└── package.json

In this case, without the .gcloudignore this is what is deployed:

enter image description here

And with the following .gcloudignore:

.gcloudignore
.git
.gitignore
.idea
node_modules
package-lock.json

This is what is deployed:

enter image description here

See more on this.

3
  • 1
    The .gcloudignore file is respect by default if the gcloudignore/enabled config is not set, so it doesn't need to be enabled explicitly. See cloud.google.com/sdk/gcloud/reference/topic/gcloudignore Mar 22, 2021 at 10:57
  • @KlemensZleptnig Yes, I have this very same document at the end of my post. Although it is evaluated by default, it can be disabled. That is why I recommend checking the enabled flag status.
    – rbento
    Mar 22, 2021 at 11:50
  • I just wanted to clarify that the default value for it is true (because for some people like me it might not be included in the output of gcloud config list if it has never been set). Mar 23, 2021 at 12:21
19

There is skip_files directive in your app.yaml to exclude paths or files you do not want deployed.

But If you are working on a node.js project you would have to use .gcloudignore file which will specify which directories to exclude.

This .gcloudignore would prevent the upload of the node_modules/ directory and any files ending in ~:

  node_modules/
  *~

Reference to documentation:
1. https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore
2. https://cloud.google.com/appengine/docs/standard/nodejs/config/appref (search 'skip_files')

14

I believe you will want to use the skip_files directive in your app.yaml to exclude paths or files you do not want deployed.

Something like:

skip_files:
  - ^your_data_dir/.*\.json?
2
  • 6
    Actually, that skip_files link goes to Python 2.7 docs; the Python 3 version says the option is "not supported for Python 3.7", and the Node docs don't even list it. As mentioned in another answer, the .gcloudignore file should be used instead.
    – Peter W
    Oct 9, 2019 at 5:46
  • if I have two cloudbuild yaml files in the same directory, can I apply this .gcloudignore to only one of them? possibly can I give it a custom name then import it in the cloudbuild.yaml ? Aug 19, 2021 at 7:10
1

In the case for google compute engine run:

gcloud config set gcloudignore/enabled true

In the case of google app engine: create a file called .gcloudignore in root dir and add the folders or files to be ignored it acts just like .gitignore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.