简体   繁体   English

将项目启动到云/生产(Node.js + Vue.js)

[英]Launching project to cloud/production (Node.js + Vue.js)

A while ago, I started a project with Node.js on the back end and Vue.js on the front end.前段时间,我开始了一个项目,后端是 Node.js,前端是 Vue.js。 I never saw any difficulties in executing my project in development.在开发中执行我的项目时,我从未见过任何困难。

I know that with Vue.js it is possible to generate a dist folder, but I don't understand how to use it.我知道使用 Vue.js 可以生成 dist 文件夹,但我不明白如何使用它。

Now I'm trying to create a docker image with my project and I was in doubt as to how its structure should work, I should create an image for the Back-end and another for the Front-end, and even if it is possible it is recommended to to do?现在我正在尝试用我的项目创建一个 docker 图像,我怀疑它的结构应该如何工作,我应该为后端创建一个图像,为前端创建另一个图像,即使它是可能的建议做什么? With the docker image I intend to launch the project on Google Cloud.使用 docker 映像,我打算在 Google Cloud 上启动该项目。

I also have doubts on the question of the database, whether it should also be in the same docker image or should I separate it from the Back-end?我对数据库的问题也有疑问,是否也应该在同一个 docker 映像中,还是应该将它与后端分开?

This is my project structure这是我的项目结构

It depends on your expected traffic.这取决于您的预期流量。 If you expect a higher load, horizontal scaling would suggest to put them in separate images because then you can scale out the frontend and the backend separately.如果您期望更高的负载,水平缩放建议将它们放在单独的图像中,因为这样您可以分别扩展前端和后端。

frontend前端

Whether you use CI/CD or not, when building your frontend image you want to use a web server around the frontend, there are options, pick your best known (Apache httpd or Nginx... etc).无论您是否使用 CI/CD,在构建前端映像时,您想在前端周围使用 web 服务器,有一些选项,选择您最知名的(Apache httpd 或 Nginx...等)。 Make sure that if you are using vue-router you configure your rewrites to send everything to the index.html, otherwise your routing will not work.确保如果您使用的是 vue-router,则配置您的重写以将所有内容发送到 index.html,否则您的路由将无法正常工作。 To finish up within the dockerfile you copy the dist output to your html root.要在 dockerfile 中完成,请将 dist output 复制到 html 根目录。

database数据库

Regarding the database, putting it in the same container would mean that if the backend or frontend fails for any reason your database goes down as well.关于数据库,将它放在同一个容器中意味着如果后端或前端由于任何原因出现故障,您的数据库也会出现故障。 Don't do that.不要那样做。

Having it within the same image but running as a separate container might work, though probably very tedious to achieve this, I don't really see the point to be honest.将它放在同一个映像中但作为单独的容器运行可能会起作用,尽管实现这一点可能非常乏味,但老实说,我真的不明白这一点。 Just use a dedicated database image and deploy it separately.只需使用专用的数据库映像并单独部署即可。

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

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