简体   繁体   English

Dockerized ReactJS & Express on Elastic Beanstalk

[英]Dockerized ReactJS & Express on Elastic Beanstalk

I'm working with a startup to build an app.我正在与一家初创公司合作构建应用程序。 I've been studying CS for 2 years, so I'm new to lots of things.我学习 CS 已经 2 年了,所以我对很多东西都很陌生。 For our app we have a ReactJS front-end, Express back-end, and MySQL database.对于我们的应用程序,我们有一个 ReactJS 前端、Express 后端和 MySQL 数据库。 Currently it's deployed on AWS Elastic Beanstalk in a NodeJS environment.目前,它部署在 NodeJS 环境中的 AWS Elastic Beanstalk 上。 I configured it to run react-scripts build after it's been deployed.我将其配置为在部署后运行react-scripts build It's serving the static React-generated files through the Express server (bad idea, I know).它通过 Express 服务器为 static React 生成的文件提供服务(我知道这是个坏主意)。 This has worked for a while, but now the instance is running out of memory when trying to build.这已经工作了一段时间,但现在实例在尝试构建时用完了 memory。

I've been looking into Docker as a better solution (I've never used Docker before this week), and now I have a local development setup with 3 containers: a MySQL container, a Node container running the backend, and an Alpine container just running react-scripts start .我一直在研究 Docker 作为更好的解决方案(本周之前我从未使用过 Docker),现在我有一个包含 3 个容器的本地开发设置:一个 MySQL 容器、一个运行后端的 Node 容器和一个 Alpine 容器只是运行react-scripts start The front-end is using a proxy to connect to the backend.前端使用代理连接到后端。 This is all working fine locally (except that my backend container can't connect to the Inte.net so an external API is broken), but I have no idea how to deploy this correctly to AWS.这在本地一切正常(除了我的后端容器无法连接到 Inte.net,因此外部 API 已损坏),但我不知道如何将其正确部署到 AWS。

With Elastic Beanstalk is there a way for me to build and deploy a single Docker container with the pre-built React front-end, configure Nginx to serve those static files, and then pass all /api requests to the Express server?使用 Elastic Beanstalk 有没有办法让我使用预构建的 React 前端构建和部署单个 Docker 容器,配置 Nginx 来服务那些 static 文件,然后将所有/api请求传递给 Express 服务器? I'm using RDS for the database, so I don't feel like I need to deploy another container for MySQL.我正在为数据库使用 RDS,所以我觉得我不需要为 MySQL 部署另一个容器。

I don't expect you guys to solve my problem, but I'd appreciate being pointed in the right direction.我不希望你们解决我的问题,但我很感激被指出正确的方向。 Maybe I'm going about this completely the wrong way.也许我会以完全错误的方式解决这个问题。

React App:反应应用程序:

I suggest you deploy your react application on AWS Amplify.我建议您在 AWS Amplify 上部署您的 React 应用程序。 you can find resources on how to deploy on the inte.net very easily.您可以很容易地在 inte.net 上找到有关如何部署的资源。

MySQL MySQL

You can host your MySQL database on an EC2 instance or use any other hosted service for the database.您可以在 EC2 实例上托管您的 MySQL 数据库,或使用任何其他托管服务作为数据库。

Express App快递应用

Now you can host your express app on EBS using the docker platform.现在,您可以使用 docker 平台在 EBS 上托管您的 Express 应用程序。 You can also get the resources for this on the inte.net.您还可以在 inte.net 上获取相关资源。

=========================================================================== ================================================ =========================

Now add your express app endpoint in AWS Amplify's environment to use it with react app.现在,在 AWS Amplify 的环境中添加您的 Express 应用端点,以将其与 React 应用一起使用。 Add MySQL URL to EBS's environment to use it with Express App.将 MySQL URL 添加到 EBS 的环境中,以便与 Express App 一起使用。

Note: AWS amplify serves your app on HTTPS so you have to enable SSL on EBS also.注意: AWS amplify 在 HTTPS 上为您的应用程序提供服务,因此您还必须在 EBS 上启用 SSL。 You can do it with the AWS certificate manager by getting an SSL certificate and attaching it to the EBS.您可以通过获取 SSL 证书并将其附加到 EBS 来使用 AWS 证书管理器来完成此操作。

It will be easy if the domain is handled by Route53 but again you can also achieve this with any domain service provider.如果域由 Route53 处理,这将很容易,但您也可以通过任何域服务提供商实现这一点。

It is recommended that you should migrate your domain to Route 53, as you will get more control and also many other benefits.建议您将域迁移到 Route 53,因为您将获得更多控制权以及许多其他好处。 Refer this answer: https://stackoverflow.com/a/38225802/9323655参考这个答案: https://stackoverflow.com/a/38225802/9323655

Hope my answer will guide you in the right direction.希望我的回答能引导您朝着正确的方向前进。

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

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