【问题标题】:Setting up app.yaml file for Node.js and React.js deployment to App Engine为 Node.js 和 React.js 部署到 App Engine 设置 app.yaml 文件
【发布时间】:2020-07-10 09:40:59
【问题描述】:

我正在尝试部署具有服务器端目录和客户端的项目。我也在使用pm2来启动双方的服务...这是文件夹结构目录

MyProject
+-- server
|   --- app.js
|   --- app.yaml
|   --- package.json
+-- client
|   +-- build
|       --- index.html
|   --- package.json
|....
--- .gitignore

package.json 的服务器脚本

{...
"scripts": {
    "client": "npm start --prefix ../client",
    "deploy": "gcloud app deploy app.yaml",
    "dev": "concurrently \"npm run build\" \"npm run client\"",
    "start": "pm2 start app.config.json"
  },
...
}

app.config.json 文件,因为我使用的是 pm2:

{
    "apps" : [
        {
            "name"      : "clientApp",
            "script": "node",
            "args"    : "../client/scripts/start.js"
        },
        {
            "name"      : "serverApp",
            "script"    : "node",
            "args": "./bin/www"
        }
    ]
  }

app.js

app.use(express.static(path.join(__dirname, '../client/build')));

这是服务器的设置。现在这里是客户端。 包.json

"scripts": {
    "start": "pm2 start scripts/start.js --name clientApp",
    "build": "node scripts/build.js",
    "serve": "serve -s build -l 8080",
  },
  "proxy": "http://localhost:5000",

最重要的是,app.yaml

runtime: nodejs
env: flex

handlers:
  - url: /api/.*
    script: auto
  - url: /
    static_files: client/build/index.html
    upload: client/build/index.html
  - url: /
    static_dir: client/build
  - url: /static
    static_dir: client/build/static
  - url: /.*
    secure: always
    redirect_http_response_code: 301
    script: auto

manual_scaling:
  instances: 1

resources:
  cpu: 2
  memory_gb: 8.0
  disk_size_gb: 20

我得到的错误是应用程序启动错误!代码:APP_CONTAINER_CRASHED,为什么会这样?我是否在 app.yaml 中错误地获取了客户端目录???

ERROR: (gcloud.app.deploy) Error Response: [9] 
Application startup error! Code: APP_CONTAINER_CRASHED
yarn run v1.17.3
$ pm2 start app.config.json
...
...
...
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
[PM2][WARN] Applications clientApp, serverApp not running, starting...
[PM2] App [clientApp] launched (1 instances)
[PM2] App [serverApp] launched (1 instances)
┌─────┬──────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name         │ namespace   │ version │ mode    │ pid      │ uptime │ \u21ba    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼──────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ clientApp    │ default     │ N/A     │ fork    │ 50       │ 0s     │ 0    │ online    │ 0%       │ 28.2mb   │ root     │ disabled │
│ 1   │ serverApp    │ default     │ N/A     │ fork    │ 56       │ 0s     │ 0    │ online    │ 0%       │ 25.4mb   │ root     │ disabled │
└─────┴──────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Done in 2.05s.

error Command failed with exit code 1.

【问题讨论】:

    标签: node.js reactjs google-app-engine deployment pm2


    【解决方案1】:

    考虑到您所面临的错误以及用户面临与您的类似错误的其他情况(如在此其他社区帖子here 中),App Engine 似乎正在使用已弃用的方法。此方法称为single_from_classes,应将其替换为新方法 - 使用load_learner - 这样错误就会停止。

    我建议您检查提供的答案 here 并更改您的代码以不再使用此已弃用的方法,以便正确进行部署。

    如果这还不够,您可以尝试重新组织代码并以不同方式配置其结构。正如社区的另一个答案中提到的那样-可访问here-可能还需要进行一些软件包安装-例如,使用命令npm install --save @google-cloud/datastore-因此,检查官方文档可能是值得的Client Libraries 也是。

    如果这些信息对您有帮助,请告诉我!

    【讨论】:

      猜你喜欢
      • 2020-07-17
      • 2020-05-02
      • 2018-03-23
      • 1970-01-01
      • 2020-10-14
      • 2021-07-12
      • 2019-03-19
      • 2015-02-19
      • 1970-01-01
      相关资源
      最近更新 更多