简体   繁体   English

为什么nodejs实例无法在google app engine标准环境下启动成功?

[英]Why couldn't nodejs instance start successfully in google app engine standard environment?

I am deploying nextjs project to goole app engine standard environment.我正在将 nextjs 项目部署到 goole 应用引擎标准环境。

I got some inspiration from this discussion and structured my app based on this repo .我从这个讨论中得到了一些启发,并基于这个repo构建了我的应用程序。

(I tried to deploy this demo project to my app engine and confirmed it's working well) (我尝试将此演示项目部署到我的应用程序引擎并确认它运行良好)

However app engine shows 500 error after I deploy my project.但是,在我部署项目后,应用程序引擎显示 500 错误。

https://stars-website-nextjs.ue.r.appspot.com/ 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请求失败,因为实例无法成功启动

This is my app.yaml这是我的应用程序。yaml

env: standard
runtime: nodejs14
service: default

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

and my package.json file和我的 package.json 文件

... ...
"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"
  }
... ...

My understanding is that if I upload nextjs build dir to app engine, it will automatically run the "start" command in package.json.我的理解是,如果我将 nextjs 构建目录上传到应用引擎,它将自动运行 package.json 中的“启动”命令。

I deployed same project to vercel.com and it's working well https://stars-nextjs.vercel.app .我将相同的项目部署到 vercel.com 并且运行良好https://stars-nextjs.vercel.app

Why doesn't google app engine start my project successfully?为什么谷歌应用引擎没有成功启动我的项目?

Can I check nodejs instance logs somewhere?我可以在某处检查 nodejs 实例日志吗?

I am quite novice to app engine, so I am open to any other approachs for deploying nextjs project to app engine.我对应用引擎很陌生,所以我对将 nextjs 项目部署到应用引擎的任何其他方法持开放态度。 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.我还阅读了关于自动构建和部署的云构建和构建触发器,这听起来很吸引人,但不知道从哪里开始。

I would really appreciate any help.我真的很感激任何帮助。

not sure if you did it already, but you need to enable the App Engine API for your project first, setup required IAM permission for a service account that will run your deployment and trigger the project build on gcloud CLoud Shell.不确定您是否已经这样做了,但是您需要首先为您的项目启用 App Engine API,为将运行您的部署并触发在 gcloud CLoud Shell 上构建项目的服务帐户设置所需的 IAM 权限。

check this guide about Deploying to App Engine查看有关部署到 App Engine 的指南

and this one to double check the parameters included in your yaml and json files for your build configuration.这个是为了仔细检查 yaml 和 json 文件中包含的参数以进行构建配置。 Build configuration overview .构建配置概述

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 .当您的应用程序返回 500 错误时,请务必在 Stackdriver Logging 中查看应用程序的 stdout 和 stderr 日志,地址为https://console.cloud.google.com/logs/viewer Double check that you are looking at "GAE Application" resource picker.仔细检查您是否正在查看“GAE 应用程序”资源选择器。

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 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 update npm更新

npm i npm i

{To update the packages listed to the latest version) {将列出的软件包更新到最新版本)

Note: Also keep in mind that your package.json and package-lock.json should be in sync with the packages注意:还要记住,您的 package.json 和 package-lock.json 应该与包同步

I opened cloud console and enabled the following API:我打开云控制台并启用以下 API:

  1. App Engine API App Engine API

  2. Compute Engine API计算引擎 API

  3. Cloud Build API云构建 API

Also I granted these roles to my service account: App Engine Admin, Cloud Build Service account.我还将这些角色授予我的服务帐户:App Engine Admin、Cloud Build Service 帐户。

App Engine Admin role: Full management of app engine apps and not storage. App Engine Admin 角色:完全管理应用引擎应用而不是存储。

Cloud Build Service Account: Can perform builds. Cloud Build 服务帐号:可以执行构建。

Then I opened a new terminal in VSCode and ran the following commands:然后我在 VSCode 中打开一个新终端并运行以下命令:

  1. npm run dev npm 运行开发

  2. gcloud auth login gcloud 身份验证登录

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.我向 Google Cloud SDK 授予了允许权限。

  1. gcloud init gcloud初始化

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

[ii]Chose my service account [ii]选择我的服务帐号

[iii]Chose project-id [iii]选择项目ID

[iv]Chose us-central for the region where my app would be deployed. [iv]为我的应用程序将部署的区域选择 us-central。

  1. npm run build npm 运行构建

  2. npm run deploy npm 运行部署

  3. gcloud app browse gcloud 应用浏览

The issue seems to be happening on your end because you are using 'gcloud app deploy'.由于您使用的是“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.尝试运行 npm 运行构建,然后 npm 运行部署,如 package.Z466DEEC76ECDF24FCA6D38 脚本中所述,看看它是否解决了您的问题。 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.同时启用我列出的所有 API,并将角色授予您的云构建服务帐户。 If the problem still persists, let me know.如果问题仍然存在,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用NodeJ运行App Engine标准环境 - Run App Engine standard environment with NodeJs 如何为React应用配置Google App Engine nodejs8标准环境? - How to configure a Google App Engine nodejs8 Standard Environment for React app? Google App Engine 标准上的 Nodejs 版本 - Nodejs version on Google App Engine standard 无法从 App Engine Node JS 标准环境连接 Google Cloud MySQL 实例 - Not able to connect Google Cloud MySQL Instance from App Engine Node JS standard environment 将节点应用程序部署到Google App Engine标准环境 - Deploy node application to Google App Engine standard environment Google App Engine 和 Travis CI 上的 NodeJS 环境变量 - NodeJS environment variables on Google App Engine and Travis CI Google App Engine灵活环境中的多个NodeJS服务/模块 - Multiple NodeJS Services/Modules on Google App Engine Flexible Environment 如何在 Google App Engine 标准环境中使用 Google Cloud Build 或其他方法设置环境变量? - How to set environment variables using Google Cloud Build or other method in Google App Engine Standard Environment? 在Google App Engine中处理/ _ah / start路由NodeJ - Handling /_ah/start route NodeJs at Google App Engine 在Compute Engine上连接Redis时,Google Cloud App Engine标准环境节点JS连接超时 - Google Cloud App Engine Standard Environment Node JS connection timeout when connecting Redis on Compute Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM