设置app.yaml文件以将Node.js和React.js部署到App Engine [英] Setting up app.yaml file for Node.js and React.js deployment to App Engine

查看:91
本文介绍了设置app.yaml文件以将Node.js和React.js部署到App Engine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to deploy my project which has a server-side directory and a client-side. I'm also using pm2 to boot up the services for both sides... Here is the folder structure directory:

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:

app.config.json file because I'm using 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')));

这是服务器的设置.现在是客户端.package.json

This is the setup for the Server. Now here is the Client side. package.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中错误地提供了客户端目录?

The error I'm getting is Application startup error! Code: APP_CONTAINER_CRASHED, why is this happening? Did i source the client side directory incorrectly in the 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.

推荐答案

考虑到您所面临的错误,以及在其他情况下用户遇到与您类似的错误-如本社区文章

Considering the error that you are facing and as per other cases where users faced similar error to yours - as in this other Community post here - it seems that App Engine is using a method that is deprecated. This method is called single_from_classes and it should be replaced by a new one - use the load_learner - so the error would stop.

我建议您检查此处,并更改您的代码以不再使用此不推荐使用的方法,以使部署正确进行.

I would recommend you to check the answer provided here and change your code to not use this deprecated method anymore, for the deploy to occur correctly.

如果这还不够,您可以尝试重新组织代码并以不同的方式配置其结构.如该社区的其他答案所述-在此处可访问-可能还需要安装一些软件包-为了例如,使用命令 npm install --save @ google-cloud/datastore -因此,值得从

In case this isn't enough, you can try to reorganize your code and configure the structure of it differently. As mentioned in this other answer from the Community - accessible here - it might be necessary to do some package install as well - for example, using the command npm install --save @google-cloud/datastore - so, it might be worth it to check the official documentation from Client Libraries too.

让我知道信息是否对您有帮助!

Let me know if the information helped you!

这篇关于设置app.yaml文件以将Node.js和React.js部署到App Engine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆