简体   繁体   English

NodeJS生产部署最佳实践

[英]NodeJS Production Deployment Best Practice

I'm looking for ways in which to deploy some web services into production in a consistent and timely manner. 我正在寻找以一致且及时的方式将某些Web服务部署到生产中的方法。

I'm currently implementing a deployment pipeline that will end with a manual deployment action of a specific version of the software to a number of virtual machines provisioned by Ansible. 我当前正在实施一个部署管道,该管道将以软件的特定版本到Ansible所配置的多个虚拟机的手动部署操作结束。 The idea is to provision x number of instances using version A whilst already having y number of instances running version B. Then image and flick the traffic over. 想法是使用版本A设置x个实例,而已经有y个实例运行版本B。然后对流量进行镜像和翻转。 The same mechanism should allow me to scale new vms in a set using the image I already made. 相同的机制应该允许我使用已经制作的映像在一组中扩展新的虚拟机。

I have considered the following options but was wondering if theres something I'm overlooking: 我考虑过以下选项,但想知道是否有我忽略的事情:

  1. TGZ TGZ

The CI environment would build a tarball from a project that has passed unit tests and integration tests. CI环境将从已经通过单元测试和集成测试的项目中构建一个tarball。 Optionally depednencies would be bundled (removing the need to run npm install on the production machine and relying on network connectivity to public or private npm repository). (可选)捆绑捆绑(消除了在生产计算机上运行npm install的需要,而依赖于与公共或私有npm存储库的网络连接)。

My main issue here is that any dependencies that depend on system libraries would be build on a different machine (albeit the same image). 我的主要问题是,依赖系统库的所有依赖项都将构建在不同的机器上(尽管具有相同的映像)。 I don't like this. 我不喜欢这样

  1. NPM NPM

The CI environment would publish to a private NPM repository and the Ansible deployment script would check out a specific version after provisioning. CI环境将发布到私有NPM存储库,而Ansible部署脚本将在配置后签出特定版本。 Again this suffers from a reliance on external services being available when you want to deploy. 同样,当您要部署时,这又依赖于可用的外部服务。 I dont like this. 我不喜欢这样。

  1. Git 混帐

Any system dependent modules become globally installed as part of provisioning and all other dependencies are checked into the repository. 作为供应的一部分,所有与系统相关的模块都将被全局安装,所有其他相关性都将检入到存储库中。 This gives me the flexibility of being able to do differential deployments whereby just the deltas are pushed and the application daemon can be restarted automatically by the process manager almost instantly. 这给了我灵活性,使其能够执行差异部署,从而仅压入增量,流程管理器几乎可以立即自动重启应用程序守护程序。 Dependencies are then absolutely locked down. 依赖关系然后被绝对锁定。

This would mean that theres no need to spinning up new VM unless to scale. 这意味着除非扩大规模,否则就无需扩展新的VM。 Deployments can be pushed straight to all active instances. 部署可以直接推送到所有活动实例。

First and foremost, regardless of the deployment method, you need to make sure you don't drop requests while deploying new code. 首先,无论采用哪种部署方法,都需要确保在部署新代码时不要丢弃请求。 One simple approach is removing the node from a load balancer prior to switchover. 一种简单的方法是在切换之前从负载均衡器中删除节点。 Before doing so, you may also want to try and evaluate if there are pending requests, open connections, or anything else negatively impacted by premature termination. 在执行此操作之前,您可能还想尝试评估是否有待处理的请求,打开的连接或其他任何因过早终止而带来负面影响的东西。 Or perhaps something like the up module. 或类似up模块的东西。

Most people would not recommend source controlling your modules. 大多数人不建议您对模块进行源代码控制。 It seems that a .tgz with your node_modules already filled in from an npm install while utilizing a bundledDependencies declaration in your package.json might cover all your concerns. 似乎在使用package.json中的bundledDependencies声明时,已经从npm install填充了node_modules的.tgz可能涵盖了您的所有问题。 With this approach, an npm install on your nodes will not download and install everything again. 使用这种方法,您节点上的npm install将不会再次下载并安装所有内容。 Though, it will rebuild node-gyp implementations which may cover your system library concern. 不过,它将重建node-gyp实现,这可能会涉及您的系统库问题。

You can also make use of git tags to more easily keep track of versions with specific dependencies and payloads. 您还可以使用git标签来更轻松地跟踪具有特定依赖项和有效负载的版本。 Manually deploying the code may get tedious, you may want to consider automating the routine while iterating over x amount of known server entries in a database from an interface. 手动部署代码可能会很乏味,您可能需要考虑自动执行例程,同时从接口迭代数据库中x数量的已知服务器条目。 docker.io may be of interest. docker.io可能很有趣。

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

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