运行 "gcloud builds submit ./project-folder" 时是否需要将 node_modules 添加到 .gcloudignore?

Do I need to add node_modules to .gcloudignore when running "gcloud builds submit ./project-folder"?

这是我的项目结构:

project/
  node_modules/
  src/
  .gcloudignore
  cloudbuild.yaml
  Dockerfile
  package.json

以下是我的构建方式:

gcloud builds submit ./project --config=./project/cloudbuild.yaml --project=$PROJECT_ID   // AND SOME SUBSTITUTIONS

这是我的 cloudbuild.yaml 文件:

steps:
  # BUILD IMAGE
  - name: "gcr.io/cloud-builders/docker"
    args:
      - "build"
      - "--tag"
      - "gcr.io/$PROJECT_ID/$_SERVICE_NAME:$_TAG_NAME"
      - "."
    timeout: 180s

    # PUSH IMAGE TO REGISTRY
  - name: "gcr.io/cloud-builders/docker"
    args:
      - "push"
      - "gcr.io/$PROJECT_ID/$_SERVICE_NAME:$_TAG_NAME"
    timeout: 180s

    # DEPLOY CONTAINER WITH GCLOUD
  - name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
    entrypoint: gcloud
    args:
      - "run"
      - "deploy"
      - "$_SERVICE_NAME"
      - "--image=gcr.io/$PROJECT_ID/$_SERVICE_NAME:$_TAG_NAME"
      - "--platform=managed"
      - "--region=$_REGION"
      - "--port=8080"
      - "--allow-unauthenticated"
    timeout: 180s

# DOCKER IMAGES TO BE PUSHED TO CONTAINER REGISTRY
images: 
  - "gcr.io/$PROJECT_ID/$_SERVICE_NAME:$_TAG_NAME"

这是我的 Dockerfile:

FROM node:12-slim

WORKDIR /

COPY ./package.json ./package.json
COPY ./package-lock.json ./package-lock.json

COPY ./src ./src

RUN npm ci

从我的配置文件来看,由于没有任何内容被告知 copy node_modules 文件夹,因此似乎没有必要将 node_modules 添加到 .gcloudignore。但是是吗?

我问这个是因为我看到这个 answer 说:

When you run gcloud builds submit... you provide some source code and either a Dockerfile or a configuration file. The former is a simple case of the second, a configuration file containing a single step that runs docker build....

Configuration files (YAML) list a series of container images with parameters that are run in series. Initially Cloud Build copies a designated source (can be the current directory) to a Compute Engine VM (created by the service) as a directory (that's automatically mounted into each container) as /workspace.

如果它复制源代码,它也会复制 node_modules 吗?我应该将它添加到 .gcloudignore 还是不需要?

是的,您可以跳过节点模块,因为您不会在您的构建中使用它们(而且它又大又长,需要上传)。在你的命令 npm ci 中,我确定你下载了依赖项,所以,将 node_modules 添加到你的 .gcloudignore(还有 .gitignore