为什么nodejs实例无法在google app engine标准环境下启动成功? [英] Why couldn't nodejs instance start successfully in google app engine standard environment?

查看:28
本文介绍了为什么nodejs实例无法在google app engine标准环境下启动成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 nextjs 项目部署到 goole 应用引擎标准环境.

I am deploying nextjs project to goole app engine standard environment.

我从这个讨论中获得了一些灵感,并根据这个 repo.

I got some inspiration from this discussion and structured my app based on this repo.

(我尝试将此演示项目部署到我的应用引擎并确认它运行良好)

(I tried to deploy this demo project to my app engine and confirmed it's working well)

但是在我部署项目后应用引擎显示 500 错误.

However app engine shows 500 error after I deploy my project.

https://stars-website-nextjs.ue.r.appspot.com/

当我检查应用引擎日志时,它会显示此消息.

As I check the app engine log, it shows this message.

请求失败,因为实例无法成功启动

The request failed because the instance could not start successfully

这是我的 app.yaml

This is my app.yaml

env: standard
runtime: nodejs14
service: default

handlers:
  - url: /.*
    secure: always
    script: auto

还有我的 package.json 文件

and my package.json file

... ...
"scripts": {
    "dev": "next -p 3030",
    "start": "next start -p 8080",
    "serve": "next start -p 8080",
    "gcp-predeploy": "find ./build -name '\[...*' -exec bash -c 'mv "$1" "${1/.../@@@}"' -- {} \;",
    "gcp-build": "find ./build -name '\[@@@*' -exec bash -c 'mv "$1" "${1/@@@/...}"' -- {} \;",
    "build": "rm -rf ./build && next build",
    "deploy": "npm run build && npm run gcp-predeploy && gcloud app deploy",
    "test": "echo "Error: no test specified" && exit 1"
  }
... ...

我的理解是,如果我将 nextjs 构建目录上传到应用引擎,它将自动运行启动".package.json 中的命令.

My understanding is that if I upload nextjs build dir to app engine, it will automatically run the "start" command in package.json.

我将相同的项目部署到 vercel.com,它运行良好 https://stars-nextjs.vercel.app.

I deployed same project to vercel.com and it's working well https://stars-nextjs.vercel.app.

为什么谷歌应用引擎没有成功启动我的项目?

Why doesn't google app engine start my project successfully?

我可以在某处查看 nodejs 实例日志吗?

Can I check nodejs instance logs somewhere?

我对应用引擎还是个新手,所以我愿意接受任何其他将 nextjs 项目部署到应用引擎的方法.我还阅读了关于自动构建和部署的云构建和构建触发器,这听起来很吸引人,但不知道从哪里开始.

I am quite novice to app engine, so I am open to any other approachs for deploying nextjs project to app engine. I also read about cloud build and build-trigger for automatic build and deploy and it sounds fasinating, but not sure where to get started.

非常感谢任何帮助.

推荐答案

当您的应用程序返回 500 错误时,请务必在 Stackdriver Logging 中查看应用程序的 stdout 和 stderr 日志 https://console.cloud.google.com/logs/viewer.仔细检查您是否正在查看GAE 应用程序".资源选择器.

When your application is returning 500 errors, make sure to look at the stdout and stderr logs of your application in Stackdriver Logging at https://console.cloud.google.com/logs/viewer. Double check that you are looking at "GAE Application" resource picker.

我还复制了您的问题,使用了您正在使用的相同 package.json 和 app.yaml 文件,并克隆了您所说的用于构建应用程序的 Git Hub 存储库文件.我正在详细描述我在初始设置后采取的步骤:

I also replicated your issue, used the same package.json and app.yaml file you were using and cloned the Git Hub repo files you said you used to structure your application. I am giving a detailed description of what steps I took after the initial setup:

npm 更新

npm i

{将列出的软件包更新到最新版本)

{To update the packages listed to the latest version)

注意:还要记住你的 package.json 和 package-lock.json 应该与包同步

Note : Also keep in mind that your package.json and package-lock.json should be in sync with the packages

我打开了云控制台并启用了以下 API:

I opened cloud console and enabled the following API :

  1. App Engine API

  1. App Engine API

计算引擎 API

云构建 API

我还向我的服务帐户授予了这些角色:App Engine Admin、Cloud Build Service 帐户.

Also I granted these roles to my service account : App Engine Admin, Cloud Build Service account.

App Engine Admin 角色:完全管理应用引擎应用而非存储.

App Engine Admin role : Full management of app engine apps and not storage.

Cloud Build 服务帐户:可以执行构建.

Cloud Build Service Account : Can perform builds.

然后我在 VSCode 中打开一个新终端并运行以下命令:

Then I opened a new terminal in VSCode and ran the following commands:

  1. npm run dev

gcloud auth 登录

此命令将我带到一个登录页面,我在该页面上登录了上述服务帐户.我向 Google Cloud SDK 授予了允许权限.

This command took me to a sign in page where I logged in to the above mentioned service account. I gave allow permissions to Google Cloud SDK.

  1. gcloud 初始化

[i]重新初始化现有配置

[i]Reinitialised existing configuration

[ii]选择我的服务帐号

[ii]Chose my service account

[iii]选择项目 ID

[iii]Chose project-id

[iv]为我的应用部署的区域选择 us-central.

[iv]Chose us-central for the region where my app would be deployed.

  1. npm 运行构建

npm run deploy

gcloud 应用浏览

由于您使用的是gcloud app deploy",因此问题似乎发生在您这边.尝试运行 npm run build ,然后按照 package.json 脚本中的说明运行 npm run deploy ,看看它是否能解决您的问题.该命令在进行实际上传之前首先进行构建.同时启用我列出的所有 API,并将角色授予您的云构建服务帐户.如果问题仍然存在,请告诉我.

The issue seems to be happening on your end because you are using ‘gcloud app deploy’. Try running npm run build and then npm run deploy as stated in your package.json script and see if it solves your problem. That command first does a build before doing the actual upload. Also enable all the APIs I listed and grant the roles to your cloud build service account. If the problem still persists, let me know.

这篇关于为什么nodejs实例无法在google app engine标准环境下启动成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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