简体   繁体   中英

Setting up app.yaml file for Node.js and React.js deployment to App Engine

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

Server script of 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 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')));

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",

Most importantly, the 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

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM