【问题标题】:Can't build React app from inside Google App Engine无法从 Google App Engine 内部构建 React 应用程序
【发布时间】:2019-12-15 15:57:30
【问题描述】:

我正在尝试在 GAE 上部署后构建我的 React 应用程序 - 即通过将以下启动脚本放在我的 package.json 中来创建构建文件夹

“开始”:“反应脚本构建”

...但我似乎无法构建。

此外,我看到的每个教程都提到在部署到 GAE 之前先构建它。为什么部署后不构建?

我的 package.json

{
 "name": "@App/client",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.1",
    "redux": "^4.0.1"
  },
  "scripts": {
    "local": "react-scripts start",
    "start": "react-scripts build", 
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

我的 app.yaml 文件

runtime: nodejs10
instance_class: F2

env_variables:
  POSTGRES_HOST: /cloudsql/development-omix-platform:europe-west2:omixplatform
  INSTANCE_CONNECTION_NAME: development-omix-platform:europe-west2:omixplatform
  PORT: 8080
  DEBUG: graphile-build-pg
  FIREBASE_SERVICE_ACCOUNT_JSON_FILE_NAME: firebase-service-account.json

handlers:
  - url: /
    static_files: build/index.html
    upload: build/index.html

  - url: /api/.*
    script: auto

  - url: /graphql
    script: auto

  - url: /graphiql
    script: auto

  - url: /__postgraphql/.*
    script: auto

  - url: /(.*\..*)$
    static_files: client/\1
    upload: client/(.*)

  - url: /(.*)
    static_files: client/index.html
    upload: client/index.html

我希望为部署的新版本创建一个构建文件夹,但它没有发生。`

这是来自 GAE 的日志:

Updated my package.json to reflect correctly.I am using react-scripts build as the start script.Here is the log from the deployment: ````[
  {
    "protoPayload": {
      "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
      "status": {},
      "authenticationInfo": {
        "principalEmail": "siddiquisarik@gmail.com"
      },
      "requestMetadata": {
        "callerIp": "27.7.91.59",
        "callerSuppliedUserAgent": "google-cloud-sdk x_Tw5K8nnjoRAqULM9PFAC2b gcloud/257.0.0 command/gcloud.app.deploy invocation-id/3a31d2254493473dabd0906852ba7b57 environment/None environment-version/None interactive/True from-script/False python/2.7.13 term/ (Windows NT 10.0.17134),gzip(gfe)",
        "requestAttributes": {},
        "destinationAttributes": {}
      },
      "serviceName": "appengine.googleapis.com",
      "methodName": "google.appengine.v1.Versions.CreateVersion",
      "authorizationInfo": [
        {
          "resource": "apps/emaily-dev-229719/services/default/versions/20190808t113803",
          "permission": "appengine.versions.create",
          "granted": true,
          "resourceAttributes": {}
        }
      ],
      "resourceName": "apps/emaily-dev-229719/services/default/versions/20190808t113803",
      "serviceData": {
        "@type": "type.googleapis.com/google.appengine.v1.AuditData",
        "createVersion": {
          "request": {
            "parent": "apps/emaily-dev-229719/services/default",
            "version": {
              "id": "20190808t113803",
              "instanceClass": "F2",
              "runtime": "nodejs10",
              "envVariables": {
                "DEBUG": "graphile-build-pg",
                "FIREBASE_SERVICE_ACCOUNT_JSON_FILE_NAME": "firebase-service-account.json",
                "INSTANCE_CONNECTION_NAME": "development-omix-platform:europe-west2:omixplatform",
                "PORT": "8080",
                "POSTGRES_HOST": "/cloudsql/development-omix-platform:europe-west2:omixplatform"
              },
              "entrypoint": {
                "shell": ""
              }
            }
          }
        }
      },
      "resourceLocation": {
        "currentLocations": [
          "asia-south1"
        ]
      }
    },
    "insertId": "-f8xiere12hkk",
    "resource": {
      "type": "gae_app",
      "labels": {
        "version_id": "20190808t113803",
        "module_id": "default",
        "project_id": "emaily-dev-229719"
      }
    },
    "timestamp": "2019-08-08T06:08:11.156Z",
    "severity": "NOTICE",
    "logName": "projects/emaily-dev-229719/logs/cloudaudit.googleapis.com%2Factivity",
    "operation": {
      "id": "6b80dc4e-070d-4eea-99fe-0e22a25815a8",
      "producer": "appengine.googleapis.com/admin",
      "first": true
    },
    "receiveTimestamp": "2019-08-08T06:08:13.784603661Z"
  },
  {
    "protoPayload": {
      "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
      "authenticationInfo": {
        "principalEmail": "siddiquisarik@gmail.com"
      },
      "requestMetadata": {
        "requestAttributes": {},
        "destinationAttributes": {}
      },
      "serviceName": "appengine.googleapis.com",
      "methodName": "google.appengine.v1.Versions.CreateVersion",
      "resourceName": "apps/emaily-dev-229719/services/default/versions/20190808t113803",
      "resourceLocation": {
        "currentLocations": [
          "asia-south1"
        ]
      }
    },
    "insertId": "-6dlv9vdh0gm",
    "resource": {
      "type": "gae_app",
      "labels": {
        "project_id": "emaily-dev-229719",
        "version_id": "20190808t113803",
        "module_id": "default"
      }
    },
    "timestamp": "2019-08-08T06:09:45.201Z",
    "severity": "NOTICE",
    "logName": "projects/emaily-dev-229719/logs/cloudaudit.googleapis.com%2Factivity",
    "operation": {
      "id": "6b80dc4e-070d-4eea-99fe-0e22a25815a8",
      "producer": "appengine.googleapis.com/admin",
      "last": true
    },
    "receiveTimestamp": "2019-08-08T06:09:45.476924659Z"
  }
]

添加构建日志

starting build "0efe9d27-d864-455a-8319-2ddab8300544"

FETCHSOURCE
BUILD
Starting Step #0 - "fetcher"
Step #0 - "fetcher": Already have image (with digest): gcr.io/cloud-builders/gcs-fetcher
Step #0 - "fetcher": Fetching manifest gs://staging.emaily-dev-229719.appspot.com/ae/6b80dc4e-070d-4eea-99fe-0e22a25815a8/manifest.json.
Step #0 - "fetcher": Processing 14 files.
Step #0 - "fetcher": ******************************************************
Step #0 - "fetcher": Status: SUCCESS
Step #0 - "fetcher": Started: 2019-08-08T06:08:21Z
Step #0 - "fetcher": Completed: 2019-08-08T06:08:23Z
Step #0 - "fetcher": Requested workers: 200
Step #0 - "fetcher": Actual workers: 14
Step #0 - "fetcher": Total files: 14
Step #0 - "fetcher": Total retries: 0
Step #0 - "fetcher": GCS timeouts: 0
Step #0 - "fetcher": MiB downloaded: 0.44 MiB
Step #0 - "fetcher": MiB/s throughput: 0.26 MiB/s
Step #0 - "fetcher": Time for manifest: 899.39 ms
Step #0 - "fetcher": Total time: 2.59 s
Step #0 - "fetcher": ******************************************************
Finished Step #0 - "fetcher"
Starting Step #1 - "builder"
Step #1 - "builder": Pulling image: gcr.io/gae-runtimes/nodejs10_app_builder:nodejs10_20190602_10_16_0_RC00
Step #1 - "builder": nodejs10_20190602_10_16_0_RC00: Pulling from gae-runtimes/nodejs10_app_builder
Step #1 - "builder": Digest: sha256:8d016fee32b529f5e7083ad2c4e4d8f26b9b47d35db7102e3569791bcbb737ce
Step #1 - "builder": Status: Downloaded newer image for gcr.io/gae-runtimes/nodejs10_app_builder:nodejs10_20190602_10_16_0_RC00
Step #1 - "builder": 2019/08/08 06:08:26 Starting commonbuild with args [commonbuild --runtime=nodejs10 --entrypoint= --src=/workspace --config-file=/.gaeconfig/app_start.json -- ftl.par --name=asia.gcr.io/emaily-dev-229719/app-engine-tmp/app/ttl-2h:6b80dc4e-070d-4eea-99fe-0e22a25815a8 --directory=/workspace --destination=/srv --cache-repository=asia.gcr.io/emaily-dev-229719/app-engine-tmp/build-cache/ttl-7d --cache --additional-directory=/.gaeconfig --builder-output-path="" --base=asia.gcr.io/gae-runtimes/nodejs10:nodejs10_20190602_10_16_0_RC00].
Step #1 - "builder": 2019/08/08 06:08:26 No start command generator found for nodejs10, using default app start command "serve".
Step #1 - "builder": 2019/08/08 06:08:26 Writing configuration file "/.gaeconfig/app_start.json".
Step #1 - "builder": 2019/08/08 06:08:26 Invoking build command "ftl.par --name=asia.gcr.io/emaily-dev-229719/app-engine-tmp/app/ttl-2h:6b80dc4e-070d-4eea-99fe-0e22a25815a8 --directory=/workspace --destination=/srv --cache-repository=asia.gcr.io/emaily-dev-229719/app-engine-tmp/build-cache/ttl-7d --cache --additional-directory=/.gaeconfig --builder-output-path=\"\" --base=asia.gcr.io/gae-runtimes/nodejs10:nodejs10_20190602_10_16_0_RC00".
Step #1 - "builder": INFO FTL version node-v0.17.0
Step #1 - "builder": INFO Beginning FTL build for node
Step #1 - "builder": INFO FTL arg passed: exposed_ports None
Step #1 - "builder": INFO FTL arg passed: cache_repository asia.gcr.io/emaily-dev-229719/app-engine-tmp/build-cache/ttl-7d
Step #1 - "builder": INFO FTL arg passed: tar_base_image_path None
Step #1 - "builder": INFO FTL arg passed: export_cache_stats False
Step #1 - "builder": INFO FTL arg passed: builder_output_path ""
Step #1 - "builder": INFO FTL arg passed: name asia.gcr.io/emaily-dev-229719/app-engine-tmp/app/ttl-2h:6b80dc4e-070d-4eea-99fe-0e22a25815a8
Step #1 - "builder": INFO FTL arg passed: ttl 168
Step #1 - "builder": INFO FTL arg passed: global_cache False
Step #1 - "builder": INFO FTL arg passed: cache True
Step #1 - "builder": INFO FTL arg passed: upload True
Step #1 - "builder": INFO FTL arg passed: sh_c_prefix False
Step #1 - "builder": INFO FTL arg passed: fail_on_error True
Step #1 - "builder": INFO FTL arg passed: base asia.gcr.io/gae-runtimes/nodejs10:nodejs10_20190602_10_16_0_RC00
Step #1 - "builder": INFO FTL arg passed: output_path None
Step #1 - "builder": INFO FTL arg passed: cache_key_version v0.17.0
Step #1 - "builder": INFO FTL arg passed: cache_salt 
Step #1 - "builder": INFO FTL arg passed: directory /workspace
Step #1 - "builder": INFO FTL arg passed: entrypoint None
Step #1 - "builder": INFO FTL arg passed: additional_directory /.gaeconfig
Step #1 - "builder": INFO FTL arg passed: destination_path /srv
Step #1 - "builder": INFO FTL arg passed: verbosity NOTSET
Step #1 - "builder": INFO starting: full build
Step #1 - "builder": INFO starting: builder initialization
Step #1 - "builder": INFO Loading Docker credentials for repository 'asia.gcr.io/gae-runtimes/nodejs10:nodejs10_20190602_10_16_0_RC00'
Step #1 - "builder": INFO Loading Docker credentials for repository 'asia.gcr.io/emaily-dev-229719/app-engine-tmp/app/ttl-2h:6b80dc4e-070d-4eea-99fe-0e22a25815a8'
Step #1 - "builder": INFO builder initialization took 0 seconds
Step #1 - "builder": INFO starting: build process for FTL image
Step #1 - "builder": INFO starting: rm_node_modules
Step #1 - "builder": INFO rm_node_modules rm -rf /workspace/node_modules
Step #1 - "builder": INFO `rm_node_modules` stdout:
Step #1 - "builder": 
Step #1 - "builder": INFO rm_node_modules took 0 seconds
Step #1 - "builder": INFO using descriptor:yarn.lock
Step #1 - "builder": INFO using descriptor:package.json
Step #1 - "builder": INFO starting: checking_cached_packages_json_layer
Step #1 - "builder": DEBUG Checking cache for cache_key 2664c8e15d525a968e27ebe3bb094ddf40e661d41a9043edaf265ec95c055d29
Step #1 - "builder": INFO No cached base image found for entry: asia.gcr.io/emaily-dev-229719/app-engine-tmp/build-cache/ttl-7d/node-cache:2664c8e15d525a968e27ebe3bb094ddf40e661d41a9043edaf265ec95c055d29.
Step #1 - "builder": INFO Cache miss on local cache for asia.gcr.io/emaily-dev-229719/app-engine-tmp/build-cache/ttl-7d/node-cache:2664c8e15d525a968e27ebe3bb094ddf40e661d41a9043edaf265ec95c055d29
Step #1 - "builder": INFO No cached dependency layer for 2664c8e15d525a968e27ebe3bb094ddf40e661d41a9043edaf265ec95c055d29
Step #1 - "builder": INFO [CACHE][MISS] v0.17.0:NODE->2664c8e15d525a968e27ebe3bb094ddf40e661d41a9043edaf265ec95c055d29
Step #1 - "builder": INFO checking_cached_packages_json_layer took 0 seconds
Step #1 - "builder": INFO starting: building_packages_json_layer
Step #1 - "builder": INFO starting: yarn_install
Step #1 - "builder": INFO yarn_install yarn install --production
Step #1 - "builder": INFO `yarn_install` stdout:
Step #1 - "builder": yarn install v1.9.4
Step #1 - "builder": [1/4] Resolving packages...
Step #1 - "builder": [2/4] Fetching packages...
Step #1 - "builder": info fsevents@2.0.6: The platform "linux" is incompatible with this module.
Step #1 - "builder": info "fsevents@2.0.6" is an optional dependency and failed compatibility check. Excluding it from installation.
Step #1 - "builder": info fsevents@1.2.9: The platform "linux" is incompatible with this module.
Step #1 - "builder": info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
Step #1 - "builder": [3/4] Linking dependencies...
Step #1 - "builder": [4/4] Building fresh packages...
Step #1 - "builder": Done in 38.66s.
Step #1 - "builder": 
Step #1 - "builder": INFO `yarn_install` had stderr output:
Step #1 - "builder": warning "react-scripts > @typescript-eslint/eslint-plugin@1.6.0" has unmet peer dependency "typescript@*".
Step #1 - "builder": warning "react-scripts > @typescript-eslint/parser@1.6.0" has unmet peer dependency "typescript@*".
Step #1 - "builder": warning "react-scripts > ts-pnp@1.1.2" has unmet peer dependency "typescript@*".
Step #1 - "builder": warning "react-scripts > @typescript-eslint/eslint-plugin > @typescript-eslint/typescript-estree@1.6.0" has unmet peer dependency "typescript@*".
Step #1 - "builder": warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
Step #1 - "builder": 
Step #1 - "builder": INFO yarn_install took 39 seconds
Step #1 - "builder": INFO starting: tar_runtime_package
Step #1 - "builder": INFO tar_runtime_package tar -pcf /tmp/tmp14UUYM.tar --hard-dereference --transform flags=r;s,^,/srv/node_modules/, --exclude *.pyc .
Step #1 - "builder": INFO `tar_runtime_package` stdout:
Step #1 - "builder": 
Step #1 - "builder": INFO tar_runtime_package took 0 seconds
Step #1 - "builder": INFO starting: gzip_tar_runtime_package
Step #1 - "builder": INFO gzip_tar_runtime_package gzip /tmp/tmp14UUYM.tar -1
Step #1 - "builder": INFO `gzip_tar_runtime_package` stdout:
Step #1 - "builder": 
Step #1 - "builder": INFO gzip_tar_runtime_package took 2 seconds
Step #1 - "builder": INFO starting: rm_node_modules
Step #1 - "builder": INFO rm_node_modules rm -rf /workspace/node_modules
Step #1 - "builder": INFO `rm_node_modules` stdout:
Step #1 - "builder": 
Step #1 - "builder": INFO rm_node_modules took 0 seconds
Step #1 - "builder": INFO building_packages_json_layer took 43 seconds
Step #1 - "builder": INFO starting: uploading_packages_json_layer
Step #1 - "builder": INFO Layer sha256:770e78845ef75d41d0555b936a55cbecf2073d003fe4811284ef44d31054bbd1 pushed.
Step #1 - "builder": INFO Layer sha256:f341002bd84f37c2963472ebebea9d3c90ac6e2627b3fde7377a87e9f3e83c69 pushed.
Step #1 - "builder": INFO Finished upload of: asia.gcr.io/emaily-dev-229719/app-engine-tmp/build-cache/ttl-7d/node-cache:2664c8e15d525a968e27ebe3bb094ddf40e661d41a9043edaf265ec95c055d29
Step #1 - "builder": INFO uploading_packages_json_layer took 8 seconds
Step #1 - "builder": INFO starting: Building app layer
Step #1 - "builder": INFO starting: tar_runtime_package
Step #1 - "builder": INFO tar_runtime_package tar -pcf /tmp/tmp46oxw8.tar --hard-dereference --transform flags=r;s,^,/srv/, --exclude *.pyc .
Step #1 - "builder": INFO `tar_runtime_package` stdout:
Step #1 - "builder": 
Step #1 - "builder": INFO tar_runtime_package took 0 seconds
Step #1 - "builder": INFO starting: gzip_tar_runtime_package
Step #1 - "builder": INFO gzip_tar_runtime_package gzip /tmp/tmp46oxw8.tar -1
Step #1 - "builder": INFO `gzip_tar_runtime_package` stdout:
Step #1 - "builder": 
Step #1 - "builder": INFO gzip_tar_runtime_package took 0 seconds
Step #1 - "builder": INFO Finished gzipping tarfile.
Step #1 - "builder": INFO Building app layer took 0 seconds
Step #1 - "builder": INFO starting: Building app layer
Step #1 - "builder": INFO starting: tar_runtime_package
Step #1 - "builder": INFO tar_runtime_package tar -pcf /tmp/tmphzX880.tar --hard-dereference --transform flags=r;s,^,/.gaeconfig/, --exclude *.pyc .
Step #1 - "builder": INFO `tar_runtime_package` stdout:
Step #1 - "builder": 
Step #1 - "builder": INFO tar_runtime_package took 0 seconds
Step #1 - "builder": INFO starting: gzip_tar_runtime_package
Step #1 - "builder": INFO gzip_tar_runtime_package gzip /tmp/tmphzX880.tar -1
Step #1 - "builder": INFO `gzip_tar_runtime_package` stdout:
Step #1 - "builder": 
Step #1 - "builder": INFO gzip_tar_runtime_package took 0 seconds
Step #1 - "builder": INFO Finished gzipping tarfile.
Step #1 - "builder": INFO Building app layer took 0 seconds
Step #1 - "builder": INFO starting: Stitching layers into final image
Step #1 - "builder": INFO Stitching layers into final image took 0 seconds
Step #1 - "builder": INFO starting: Uploading final image
Step #1 - "builder": INFO starting: Pushing image to Docker registry
Step #1 - "builder": INFO Pushing final image...
Step #1 - "builder": INFO Layer sha256:f341002bd84f37c2963472ebebea9d3c90ac6e2627b3fde7377a87e9f3e83c69 exists, skipping
Step #1 - "builder": INFO Layer sha256:3c2cba919283a210665e480bcbf943eaaf4ed87a83f02e81bb286b8bdead0e75 exists, skipping
Step #1 - "builder": INFO Layer sha256:75c5cf2a0cfac9f36b9eff671bfb135c9e893bd126e3f1ca29880e094b71ef59 exists, skipping
Step #1 - "builder": INFO Layer sha256:517783fc8820a78d42a17058fb41d300464b2f57666b79b263b71473ce0add58 exists, skipping
Step #1 - "builder": INFO Layer sha256:3e6140238cb96ed591571804c4abc9935a800ddcc6661a89dda9d3917ae90f7a exists, skipping
Step #1 - "builder": INFO Layer sha256:992de7a46af205f308bbbe2a0438b371a5ab9bb1d367cad03c86dd3a34ee7442 exists, skipping
Step #1 - "builder": INFO Layer sha256:49e24c87983c8a9441263a3ae58c98691a0b0d228e7af0414a39d78638a10451 exists, skipping
Step #1 - "builder": INFO Layer sha256:4f083d4df15f0671110e16e80efc7d410e316f9f3ca549d4c532551b21a4fbde exists, skipping
Step #1 - "builder": INFO Layer sha256:deabf7bad5e7feeee5b21092bd193ecbd1b227d1fe1eae287fddb10c952e9e35 exists, skipping
Step #1 - "builder": INFO Layer sha256:729a2199e385e7c3b1d473adb6ad74f888d88537f3cb5fba50a2223e528f2af1 exists, skipping
Step #1 - "builder": INFO Layer sha256:c06ebd05b949f8c382380fa7b6cb45b9b39a9ca25ba3eb819803a9b5e08b8798 exists, skipping
Step #1 - "builder": INFO Layer sha256:a1fe0bd3e83030687176951a74a2bdfba3de9f032bf371412e9a9b0d646fe087 exists, skipping
Step #1 - "builder": INFO Layer sha256:3aed06531a572af8cda05edf7544b27c4d48572df65831e051c4cebdbdd7f253 mounted.
Step #1 - "builder": INFO Layer sha256:3aed06531a572af8cda05edf7544b27c4d48572df65831e051c4cebdbdd7f253 pushed.
Step #1 - "builder": INFO Layer sha256:ead752f81c3ec2c2a6ac6692c4c9df2e5e1389552ed0b79a48e2d595d122b8fa mounted.
Step #1 - "builder": INFO Layer sha256:ead752f81c3ec2c2a6ac6692c4c9df2e5e1389552ed0b79a48e2d595d122b8fa pushed.
Step #1 - "builder": INFO Layer sha256:0ab6231c1a046e6afdf063797ef9e7bec7b6f2bf0a706b673ece2ecbe49ba425 mounted.
Step #1 - "builder": INFO Layer sha256:0ab6231c1a046e6afdf063797ef9e7bec7b6f2bf0a706b673ece2ecbe49ba425 pushed.
Step #1 - "builder": INFO Layer sha256:6d78a22a5429819bb4c7c261fa2c8921ea24fc61c83f0ee58739112f660382e7 pushed.
Step #1 - "builder": INFO Layer sha256:e728a177ac564e7d9c355d434ce03da7f13874250554ef01186916a09fed9137 pushed.
Step #1 - "builder": INFO Layer sha256:20043117973e6f614d9ba35565716932fba47fecdcf13bc378b26c5de29ed6dd pushed.
Step #1 - "builder": INFO Finished upload of: asia.gcr.io/emaily-dev-229719/app-engine-tmp/app/ttl-2h:6b80dc4e-070d-4eea-99fe-0e22a25815a8
Step #1 - "builder": INFO Pushing image to Docker registry took 5 seconds
Step #1 - "builder": INFO Uploading final image took 5 seconds
Step #1 - "builder": INFO build process for FTL image took 59 seconds
Step #1 - "builder": INFO full build took 59 seconds
Finished Step #1 - "builder"
PUSH
DONE

【问题讨论】:

  • 你能分享你的GAE的日志吗?
  • 嗨,更新了我的 package.json 以正确反映。我使用 react-scripts build 作为启动脚本。添加了部署中的日志:
  • @sarik123,你有没有弄明白这个?我也面临同样的问题,希望能听到您的解决方案......

标签: javascript node.js reactjs google-app-engine


【解决方案1】:
# Dockerfile extending the generic Node image with application files for a
# single application.
FROM gcr.io/google_appengine/nodejs
COPY . /app/
# You have to specify "--unsafe-perm" with npm install
# when running as root.  Failing to do this can cause
# install to appear to succeed even if a preinstall
# script fails, and may have other adverse consequences
# as well.
# This command will also cat the npm-debug.log file after the
# build, if it exists.
RUN npm install --unsafe-perm || \
  ((if [ -f npm-debug.log ]; then \
      cat npm-debug.log; \
    fi) && false)
RUN npm install -g serve
RUN npm run-script build
CMD serve -s build

以前的提交

对于独立的 React 应用程序,您无需在部署到 Google App Engine Standard 之前进行构建。只要在本地运行npm start 可以正常工作,只要app.yaml 存在并且有效,您就可以在您的项目中运行gcloud app deploy,因为它是[1]。

话虽如此,您需要在部署之前在本地运行 npm run-script build,并且 package.json 中的“启动”脚本应保持为 react-scripts start

您还可以查看这篇文章 [2],它解决了与您的问题类似的问题。

[1]https://medium.com/tech-tajawal/deploying-react-app-to-google-app-engine-a6ea0d5af132
[2]https://medium.com/google-cloud/how-to-deploy-a-static-react-site-to-google-cloud-platform-55ff0bd0f509

【讨论】:

  • 感谢@JKleinne ...我实际上已经阅读了这些教程,我的问题可能不是最实用的一个..但是由于 GAE 默认运行 npm start 脚本,它是否应该创建构建文件夹如果 npm start 脚本包含构建命令。如果您查看提到的帖子,它们会先构建然后从那里提供服务。我有一个简单的问题,我们可以在部署到 GAE 之后构建(这似乎不会发生)然后从那里服务
  • App Engine Standard 启动应用程序的内部流程很遗憾是内部流程,因此我们无法确定是否确实发出了 npm start 命令来启动应用程序,或者它是否只是直接运行 @987654329 @。但是,这实际上可以通过指定 runtime: nodejs \n env: flex 或 aruntime: custom 来使用 App Engine Flex 观察到。无论您是使用 Google 提供的 Node.js 映像还是在指定自定义运行时时您自己的 Dockerfile,Flex 环境都会使用 Dockerfile。
  • 我鼓励您尝试使用 nodejs 运行时在 Flex 环境中部署一个基本的 HelloWorld 应用程序,并观察其中一个构建步骤将包含 CMD npm start 所以事实上,GAE 不会运行启动脚本从 package.json ......你的 docker 容器可以。如果您决定在自定义运行时创建自己的 Dockerfile,您可以修改这些构建步骤,让您的 React.js 产品在部署时构建,并通过 Dockerfile 的配置来提供所有服务。
  • 我将编辑我的答案以包含一个示例 Dockerfile,您可以将其用于您的特定情况:在部署时,创建一个生产 React.js 构建并提供服务。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-09
  • 2019-08-21
  • 1970-01-01
  • 1970-01-01
  • 2019-05-07
相关资源
最近更新 更多