将 Strapi 部署到弹性豆茎 [英] Deploy strapi to elastic beanstalk

查看:37
本文介绍了将 Strapi 部署到弹性豆茎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以提供有关如何将trapi部署到aws弹性豆茎的信息吗?我搜索了很多资源,如何在 DO、heroku 等许多不同的地方部署 Strapi,但我很好奇如何将 Strapi 部署到 EB 是可能的,我该怎么做.

can someone please give information how to deploy strapi to aws elastic beanstalk? I have searching many resources how about strapi deployed on many different place such on DO, heroku but i very curious how about deploy strapi to EB is that possible and how can I do with that.

推荐答案

首先你需要一个 EBS 应用程序 &运行 Node 版本 12(截至目前)的环境(Web 服务器).您还需要更改 Strapi 项目中的 package.json 并更新 engines 部分,如下所示(主要版本必须匹配 EBS 节点版本):

First you need an EBS application & environment (Web Server) running Node version 12 (as of now). You'll also need to change the package.json in your Strapi project and update the engines part, like this (major version must match EBS Node version):

"engines": {
  "node": "12.X.Y", // minor (X) & patch (Y) versions are up to you
   ...
},

您必须将您的项目切换为使用 NPM 而不是 Yarn(EBS 目前仅支持开箱即用的 NPM),为此我推荐一个类似 synp.

You must switch your project to use NPM instead of Yarn (EBS currently only supports NPM out-of-the-box), to do this I recommend a tool like synp.

然后创建一个 Procfile,它将描述您希望 EBS 如何运行您的应用程序:

Then create a Procfile which will describe how you want EBS to run your app:

web: npm run start

然后手动部署,您可以首先(在项目根目录中)运行 npm install,然后运行 ​​npm run build 来构建 Strapi Admin (React) 应用程序.构建 Strapi Admin 后,确保删除 node_modules 文件夹,因为 EBS 会自动为您安装依赖项.(*)

Then to deploy manually, you could first (in the project root) run npm install, then npm run build to build the Strapi Admin (React) application. After the Strapi Admin has been built, make sure to remove the node_modules folder, because EBS will automatically install dependencies for you. (*)

最后一步是压缩整个项目(同样,在项目根目录中,运行:zip -r application.zip .),将 zip 上传到 AWS EBS &让它发挥它的魔力.希望它然后应该安装依赖项并自动启动您的应用程序.

Last step is to zip the whole project (again, in project root, run: zip -r application.zip .), upload the zip to AWS EBS & let it do it's magic. Hopefully it should then install dependencies and start your application automatically.

附注:在您的项目中使用某些特定依赖项时(一个示例是 sharp),EBS 可能无法安装您的依赖项,要解决此问题,请添加一个.npmrc 文件到您的项目根目录,内容如下:

Side note: When using some specific dependencies in your project (one example is sharp), the EBS may fail to install your dependencies, to fix this, add a .npmrc file to your project root with the following contents:

unsafe-perm=true


旁注 #2:您需要在 EBS 配置面板中设置一些环境变量,以便 Strapi 工作(例如数据库凭据等).


Side note #2: You need to set some environment variables in the EBS configuration panel in order for Strapi to work (like database credentials etc.).

(*) 虽然你可以在你的应用程序中包含 node_modules 并压缩它并上传到 EBS(这可以工作),但有时压缩 node_modules 可能会破坏一些依赖项,所以我建议删除它并让 EBS 为您安装依赖项.

(*) Although you could include node_modules in your app and zip it and upload to EBS (which could work), sometimes zipping node_modules may break some dependencies, so I recommend removing it and let EBS install dependencies for you.

这篇关于将 Strapi 部署到弹性豆茎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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