How can I exclude a file from deploy in gcloud?

后端 未结 3 1393
情话喂你
情话喂你 2021-01-11 13:29

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 fil

3条回答
  •  甜味超标
    2021-01-11 14:27

    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:

    And with the following .gcloudignore:

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

    This is what is deployed:

    See more on this.

提交回复
热议问题