简体   繁体   English

使用自定义启动命令将 NodeJS 应用程序部署到 GCP AppEngine

[英]Deploy NodeJS app to GCP AppEngine with customize start command

Here is my package.json这是我的 package.json

"scripts": {
    "start": "react-scripts start",
    "start:develop": "env-cmd -f env/.env.develop react-scripts start",
    "start:stage": "env-cmd -f env/.env.stage react-scripts start",
    ...
}

env folder structure env 文件夹结构

env
├─ .env.develop (env=develop)
├─ .env.stage   (env=stage)

When run on local (MacOS)在本地 (MacOS) 上运行时

  • "yarn start" runs NodeJS app on local with default "env" = local (which is defined in other file) "yarn start" 在本地运行 NodeJS 应用程序,默认 "env" = local(在其他文件中定义)
  • "yarn start:develop" runs NodeJS app on local with "env" = develop “yarn start:develop” 在本地运行 NodeJS 应用程序,“env”=develop

But now when I want to deploy this to GCP AppEngine, it's always deploy with "start" command (equivalent to "yarn start" on local)但是现在当我想将它部署到 GCP AppEngine 时,它总是使用“start”命令部署(相当于本地的“yarn start”)

How can I deploy "yarn start:develop" to AppEngine without declaring more environment variables in app.yaml?如何在 app.yaml 中声明更多环境变量的情况下将“yarn start:develop”部署到 AppEngine?

From the documentation about what happens when you deploy your program,从有关部署程序时发生的情况的文档中,

Node.js modules are installed in the cloud as listed in your package.json and package-lock.json files and your service is started by using npm start . Node.js modules are installed in the cloud as listed in your package.json and package-lock.json files and your service is started by using npm start .

I interpret the above to mean your project on the cloud is always run with start script and GAE will not/does not know how to use another script.我将上述解释为意味着您在云上的项目始终使用start脚本运行,而 GAE 不会/不知道如何使用另一个脚本。

A possible workaround could be to deploy your app using a different version name eg dev ie you have一种可能的解决方法是使用不同的版本名称部署您的应用程序,例如您拥有的dev ie

  1. Your default version with "start": "react-scripts start"您的default版本带有"start": "react-scripts start"
  2. dev version with "start": "env-cmd -f env/.env.develop react-scripts start"带有“start”的dev版本"start": "env-cmd -f env/.env.develop react-scripts start"

Both of your versions use only the start script but they do different things你的两个版本都只使用start脚本,但他们做不同的事情

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

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