tech2023-03-06  1

This article was sponsored by AppFog. Thank you for supporting the sponsors who make SitePoint possible.

本文由AppFog赞助。 感谢您支持使SitePoint成为可能的赞助商。

There are several steps involved in building a large scale web application. One of the most notoriously difficult steps of that process is deployment. Your engineering team will often face situations where code needs to be shipped quickly, and your production environment needs to update as soon as possible. In such an environment, the deployment process must be smooth enough to avoid disrupting user experience, but rapid enough to avoid downtime and preserve business goals.

构建大型Web应用程序涉及几个步骤。 该过程中最臭名昭著的困难步骤之一就是部署。 您的工程团队经常会遇到需要快速交付代码且生产环境需要尽快更新的情况。 在这样的环境中,部署过程必须足够流畅,以避免破坏用户体验,但又要足够快速,以避免停机并保留业务目标。

The team at AppFog understands how important it is to have a strong architecture to support maintaining and scaling out your application, which is why they’ve built a tool that allows you to focus on writing code, while they handle the infrastructure related details. With AppFog, things like run time environments, load balancing, and reporting are no longer issues that require so much of your time. AppFog can even help you deploy your application seamlessly, regardless of how many users you have, or how big your deployments usually are.

AppFog的团队了解拥有一个强大的体系结构来支持维护和扩展应用程序的重要性,这就是为什么他们构建了一个工具,使您可以专注于编写代码,同时处理与基础结构相关的细节的重要性。 使用AppFog,不再需要运行时间环境,负载平衡和报告之类的事情。 AppFog甚至可以帮助您无缝地部署应用程序,而不管您有多少用户,或通常有多大的部署。

If you’ve ever found yourself struggling to provide your engineering team with an effortless deployment strategy, then a Blue-Green deployment methodology provided by AppFog may be right for you and your team.


什么是蓝绿色部署方法? (What is the Blue-Green Deployment Methodology?)

A known challenge involved in automated deployment is often referred to as “the cutover”, which refers to taking software from the final stage of testing to live production. The cutover needs to happen quickly, so that downtime is prevented or at least minimized. A Blue-Green deployment strategy allows for safe deployments by ensuring that your application has two separate production environments, as close to identical as possible. At any time, one of these environments is live, while the other receives no user traffic. If your ‘Blue’ environment is live, then your pre-deployment testing will take place on your ‘Green’ environment. Once your tests pass on the Green environment, you reroute your traffic from the Blue environment to the Green environment which now has the updated code that has passed all QA and other testing.

自动化部署中涉及的一个已知挑战通常称为“转换”,是指将软件从测试的最后阶段转移到实际生产中。 切换需要Swift进行,以防止停机时间或至少将停机时间减至最少。 蓝绿色部署策略通过确保您的应用程序具有两个尽可能接近相同的独立生产环境,来进行安全部署。 这些环境中的任何一个在任何时间都处于活动状态,而其他环境则不接收用户流量。 如果您的“蓝色”环境处于活动状态,则部署前测试将在“绿色”环境中进行。 一旦测试通过了绿色环境,就可以将流量从蓝色环境重新路由到绿色环境,绿色环境现在具有通过所有质量检查和其他测试的更新代码。

The Blue-Green deployment strategy allows for immediate rollbacks in case an error is found in the live environment, since you can simply reroute your traffic to whichever of your two identical production environments is inactive. You can read more about the Blue-Green deployment methodology here.

蓝绿色部署策略允许即时回滚,以防在实时环境中发现错误,因为您可以简单地将流量重新路由到两个完全相同的生产环境中的任何一个处于非活动状态。 您可以在此处阅读有关蓝绿色部署方法的更多信息。

如何开始使用AppFog (How to Get Started with AppFog)

As outlined in our previous article covering AppFog and the 12 Factor App Methodology, AppFog is a product for managing network resources, middleware, operating systems, virtualization, servers, storage, and the runtime. All you need to do is focus on writing your code. AppFog is built by CenturyLinkand relies on the versatile open source Cloud Foundry platform.

正如我们在上一篇涵盖AppFog和12因子App方法论的文章中所概述的那样 ,AppFog是用于管理网络资源,中间件,操作系统,虚拟化,服务器,存储和运行时的产品。 您需要做的只是专注于编写代码。 AppFog由CenturyLink构建,并依赖于通用的开源Cloud Foundry平台。

To enable AppFog in your CenturyLink control panel, Go to https://control.ctl.io, login, and you will see “AppFog” listed in the drop down navigation bar:

要在CenturyLink控制面板中启用AppFog,请转至https://control.ctl.io ,登录,然后您将在下拉导航栏中看到“ AppFog”列表:

Then, enable deployment to AppFog regions, US East and/or US West. Each region has its own “add region” button to enable it in your AppFog:

然后,启用部署到AppFog地区,美国东部和/或美国西部。 每个区域都有自己的“添加区域”按钮以在您的AppFog中启用它:

Once you have AppFog enabled on your account you can manage membership to regions and spaces, login from the terminal, and deploy an application.


Using the Cloud Foundry CLI, deploying is as easy as navigating to the directory where your source code is located and running:

使用Cloud Foundry CLI,部署就像导航到源代码所在的目录并运行一样容易:

cf push [name of app]

Updating that application while following a Blue-Green deployment strategy requires a few extra steps.


After the initial deployment of your application, an update to your application can be deployed by running the command:


cf push myapp-Green -n myapp-temp

This command tells Cloud Foundry to push your code to a temporary route rather than your main route, and assuming that your application was in AppFog’s east region, the URL to access this temporary path would be:

此命令告诉Cloud Foundry将您的代码推送到临时路径,而不是主路径,并假设您的应用程序位于AppFog的东部地区,则用于访问此临时路径的URL为:


So far, we have a Blue environment, which is the application that is currently active and has not been updated, and a Green environment, which is the temporary environment that has just been deployed.


Now that the two environments exist, we can put the temporary environment into rotation, which means it will be automatically load balanced by AppFog, so that traffic will be delivered to one of the two environments.


To do this, we would run:


cf map-route myapp-Green useast.appfog.ctl.io -n myapp

Once the new updated version of the application is behaving as expected, we can divert all traffic to that version, which in Blue-Green deployment terms, would mean diverting traffic from the Blue environment, to the recently updated Green environment:


cf unmap-route myapp-Blue useast.appfog.ctl.io -n myapp.

After the Blue-Green switch has been made, we can remove the temporary route by running:


cf unmap-route myapp-Green useast.appfog.ctl.io -n myapp-temp

To see more on Blue-Green deployments with AppFog, see their documentation. In particular, read up on the considerations that should be made when working with data services or services that provide state — this is a complex issue that should approached with care.

要了解有关使用AppFog进行蓝绿色部署的更多信息,请参阅其文档 。 特别是,请阅读使用数据服务或提供状态的服务时应考虑的注意事项-这是一个复杂的问题,应谨慎对待。

结论 (Conclusion)

While there are plenty of challenges involved in running a successful large scale web application, deployment does not need to be one of them. A successful Blue-Green deployment methodology can make the difference between a successful product with zero downtime and one with issues. AppFog’s tools will get you to a Blue-Green deployment in just four commands, so you can get back to building an amazing product.

尽管运行成功的大型Web应用程序涉及很多挑战,但部署并不一定是其中之一。 成功的蓝绿色部署方法可以使成功的产品(零停机时间)和有问题的产品有所不同。 AppFog的工具将使您仅用四个命令即可进行蓝绿色部署,因此您可以重新构建出色的产品。

翻译自: https://www.sitepoint.com/set-blue-green-deployment-methodology-appfog/