12要素应用程序方法论:使用AppFog在自己的应用程序中实现它

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

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

In today’s world of SaaS products, a common methodology has emerged with the purpose of providing an outline for building well structured and scalable applications. It’s called the “12-Factor App” methodology, and it’s about to change the way you approach the architecture of your next app.

在当今的SaaS产品世界中,出现了一种通用方法,旨在为构建结构合理且可扩展的应用程序提供轮廓。 它被称为“十二要素应用程序”方法,它将改变您处理下一个应用程序的体系结构的方式。

If you’ve had a lot of experience deploying applications, then you may be well aware that the deployment process can be complicated and extensive to say the least. Virtualization, networking, and setting up runtime environments are just a few of the headaches involved. The 12-Factor App methodology doesn’t eliminate the complexity altogether, but it does create a framework for organizing the process in order to maintain a healthy and scaleable application.

如果您有很多部署应用程序的经验,那么您可能会清楚地知道,至少可以说部署过程可能很复杂且很广泛。 虚拟化,联网和设置运行时环境只是其中的一些麻烦。 12要素应用程序方法并没有完全消除复杂性,但是它确实创建了一个框架来组织流程以维护健康且可扩展的应用程序。

But how should these difficult architecture necessities be handled, in such a way that each of the 12-Factor App principles can be met? The following paragraphs explain how you can meet the standards of the 12-Factor App methodology, while easily overcoming the difficult realities involved in your application infrastructure and deployment setup.

但是,应该如何处理这些困难的体系结构必需品,以使其能够满足12要素App的每个原理? 以下各段说明如何满足12要素App方法的标准,同时轻松克服应用程序基础结构和部署设置中涉及的困难现实。

A key tool in this process is AppFog, a Platform-as-a-Service product offered by CenturyLink Cloud to allow application developers to build software without having to focus on infrastructure.

此过程中的关键工具是AppFog,这是CenturyLink Cloud提供的一种平台即服务产品,它使应用程序开发人员无需集中精力于基础架构即可构建软件。

12个因素 (The 12 Factors)

As made apparent by the title, the 12-Factor App methodology is a list of principles, each explaining the ideal way to handle a subset of your application. The 12 factors are as follows:

如标题所示,“十二要素应用程序”方法是一系列原则,每个原则都说明了处理应用程序子集的理想方法。 12个因素如下:

1.代码库–在修订控制中跟踪一个代码库,许多部署 (1. Codebase – One codebase tracked in revision control, many deploys)

The first principle of the 12-Factor App methodology is related to your application’s codebase. The most important point here is to ensure that your application is tracked with revision control, and that it sits in a central repository that is accessible to your developers. This is most commonly handled by using Git or SVN to store your code.

12因素应用程序方法的第一个原理与您的应用程序的代码库有关。 这里最重要的一点是确保使用版本控制来跟踪您的应用程序,并将其放置在开发人员可以访问的中央存储库中。 这通常通过使用Git或SVN来存储代码来处理。

2.依赖关系–明确声明和隔离依赖关系 (2. Dependencies – Explicitly declare and isolate dependencies)

There is no room for assumptions when it comes to dependencies. Anything your applications rely on to run should be controlled and managed to minimize — if not completely eliminate — conflicts.

关于依赖项,没有任何假设的余地。 您的应用程序依赖于运行的任何内容都应得到控制和管理,以最大程度地减少(如果不能完全消除)冲突。

3.配置–将配置存储在环境中 (3. Configuration – Store config in the environment)

Configuration, as it relates to API keys, services, and database credentials, should never be hardcoded. This prevents your application from being at risk from both production data leaks and production errors. Instead of hardcoding this information, rely on environment variables to handle this sensitive information.

与API密钥,服务和数据库凭据有关的配置,绝对不应进行硬编码。 这样可以防止您的应用程序受到生产数据泄漏和生产错误的威胁。 无需对这些信息进行硬编码,而是依靠环境变量来处理此敏感信息。

4.支持服务–将支持服务视为附加资源 (4. Backing Services – Treat backing services as attached resources)

A backing service is one that requires a network connection to run. This is a very popular paradigm found in modern application development, especially prevalent with the rise in popularity of microservice architecture. The 12-Factor App methodology advises developers to treat these services agnostically, meaning changes or modifications should occur without having to make any code changes.

支持服务是一种需要网络连接才能运行的服务。 这是在现代应用程序开发中发现的一种非常流行的范例,尤其是随着微服务体系结构的流行而盛行。 12要素应用程序方法建议开发人员以不可知论的方式对待这些服务,这意味着无需更改任何代码即可进行更改或修改。

Typically, this factor is best handled by calling each backing service through an API, with credentials stored in a configuration file that lives in your runtime environment.

通常,通过使用API​​调用每个支持服务来最好地处理此因素,凭据存储在运行时环境中的配置文件中。

5.构建,发布,运行–严格分开的构建和运行阶段 (5. Build, release, run – Strictly separate build and run stages)

Build, release, and run stages should be treated as completely distinct from one another. Automation and tooling will help to make this principle simpler. This can be accomplished by using existing tools to fully automate your build process. A tool like Github can be used to tag your latest build, while Jenkins can be used to automate your release stage.

构建,发布和运行阶段应被视为彼此完全不同。 自动化和工具将有助于简化此原理。 这可以通过使用现有工具完全自动化您的构建过程来完成。 像Github这样的工具可以用来标记您的最新版本,而Jenkins可以用来自动化发布阶段。

6.流程–将应用作为一个或多个无状态流程执行 (6. Processes – Execute the app as one or more stateless processes)

Stateless applications are designed to degrade gracefully. That means if a dependency fails, the app itself does not become a failure. Single points of failure may be difficult, but not impossible, to avoid. The 12-Factor App methodology recommends storing data outside of running code in order to prevent operational headaches and debugging nightmares.

无状态应用程序旨在正常降级。 这意味着,如果依赖项失败,则应用程序本身不会失败。 单点故障可能很难避免,但并非不可能。 12要素应用程序方法建议将数据存储在运行代码之外,以防止操作麻烦和调试噩梦。

7.端口绑定–通过端口绑定导出服务 (7. Port binding – Export services via port binding)

All application services should be accessible via a URL. For web applications, this process happens automatically. This enables 12-Factor Apps to be fully self-contained, avoiding the need to rely on various methods of runtime injection in order to create web facing services.

所有应用程序服务应可通过URL访问。 对于Web应用程序,此过程会自动发生。 这使12要素应用程序完全独立,从而无需依赖各种运行时注入方法来创建面向Web的服务。

8.并发性–通过流程模型进行横向扩展 (8. Concurrency – Scale out via the process model)

Every process inside your application should be treated as a first-class citizen. That means that each process should be able to scale, restart, or clone itself when needed. This approach will improve the sustainability and scalability of your application as a whole.

应用程序中的每个进程都应被视为一流的公民。 这意味着每个进程都应能够在需要时扩展,重新启动或克隆自身。 这种方法将改善整个应用程序的可持续性和可扩展性。

9.易用性–快速启动和正常关闭可最大程度地提高鲁棒性 (9. Disposability – Maximize robustness with fast startup and graceful shutdown)

As noted in the previous factor, treating processes as first-class citizens translates to an easier startup and shutdown process. Compare this to an application where all process are bundled together, where startup and shutdown processes can take up to several minutes depending on their size.

如前一个因素所述,将流程视为一流的公民意味着可以更轻松地启动和关闭流程。 将此与将所有进程捆绑在一起的应用程序进行比较,在该应用程序中,启动和关闭进程最多可能需要几分钟,具体取决于它们的大小。

To ensure your startup and shutdown processes remain seamless, reach for tried and true services that are optimized for speed and performance. Databases and caches like RabbitMQ, Redis, Memcached, and CenturyLink’s own Orchestrate are just a few services that are built to help with this factor.

为了确保您的启动和关闭过程保持无缝连接,请访问针对速度和性能进行了优化的可靠服务。 诸如RabbitMQ,Redis,Memcached和CenturyLink自己的Orchestrate之类的数据库和缓存只是为解决这一问题而构建的一些服务。

10.开发/产品奇偶校验–保持开发,暂存和生产尽可能相似 (10. Dev/prod Parity – Keep development, staging, and production as similar as possible)

Consistency is key for meeting this factor. When your environments are similar, testing and developing gets much simpler. Similar environments means ensuring that areas such as your infrastructure stack, config management processes, software and runtime versions and deployment tools are the same everywhere.

一致性是满足此因素的关键。 当您的环境相似时,测试和开发变得更加简单。 相似的环境意味着确保诸如基础架构堆栈,配置管理过程,软件和运行时版本以及部署工具之类的区域到处都是相同的。

With this approach, fewer bugs will find their way into your production environment, since your test cases can be applied on production-level data.

使用这种方法,由于可以将测试用例应用于生产级数据,因此将更少的bug引入生产环境。

11.日志–将日志视为事件流 (11. Logs – Treat logs as event streams)

Logging is important for debugging and checking up on the general health of your application. At the same time, your application shouldn’t concern itself with the storage of this information. Instead, these logs should be treated as a continuous stream that is captured and stored by a separate service.

日志对于调试和检查应用程序的总体运行状况非常重要。 同时,您的应用程序不必关心此信息的存储。 相反,应将这些日志视为由单独的服务捕获和存储的连续流。

12.管理流程–将管理/管理任务作为一次性流程运行 (12. Admin processes – Run admin/management tasks as one-off processes)

One-off admin processes are essentially data collection jobs that are used to gather key information about your application. This information will be needed to asses the state of your production environment, so it’s important to ensure these one-off processes occur in your production environment. That way there can be no discrepancies between the data you need and the data coming from the visible long running production application.

一次性管理流程本质上是数据收集作业,用于收集有关您的应用程序的关键信息。 需要此信息来评估生产环境的状态,因此确保这些一次性过程在生产环境中发生非常重要。 这样,您所需的数据和来自可见的长期运行的生产应用程序的数据之间就不会有差异。

On the 12-Factor App methodology site, each of these factors links to a section where an in-depth topic overview is available. While it’s impressive to see how well thought out the 12-Factor methodology is, there’s little information regarding how exactly one might best go about setting up an infrastructure that can best handle such rigorous requirements.

12要素App方法论站点上 ,这些因素中的每一个都链接到提供深入主题概述的部分。 尽管看到“十二因素”方法的思想是多么令人印象深刻,但关于如何最好地建立能够最好地处理这种严格要求的基础设施的信息却很少。

But there is a way to do this efficiently with a tool built with the 12-Factor App methodology in mind: AppFog

但是,有一种方法可以有效利用使用12要素App方法构建的工具来做到这一点:AppFog

AppFog,App和您 (AppFog, Apps, and You)

AppFog is a PaaS designed to provide you with the tools you need to satisfy the 12-Factor App methodology. AppFog manages network resources, middleware, operating systems, virtualization, servers, storage, and the runtime. All you need to do is focus on writing your code. Offered by CenturyLink Cloud, AppFog relies on the versatile open source Cloud Foundry platform.

AppFog是一款PaaS,旨在为您提供满足12要素App方法论所需的工具。 AppFog管理网络资源,中间件,操作系统,虚拟化,服务器,存储和运行时。 您需要做的只是专注于编写代码。 AppFog由CenturyLink Cloud提供,它依赖于通用的开源Cloud Foundry平台。

Getting started with AppFog is as simple as signing into your CenturyLink Control Panel and enabling the AppFog service by adding a region that defines where your code will be hosted. From there, you can deploy your application to AppFog using the Cloud Foundry CLI.

AppFog入门非常简单,只需登录CenturyLink控制面板并通过添加一个定义代码将在何处托管的区域来启用AppFog服务。 从那里,您可以使用Cloud Foundry CLI 将应用程序部署到AppFog

Cloud Foundry then manages your applications’ runtime, middleware, and O/S environments. Additionally, tasks like load balancing, application runtimes, and streaming app logging are abstracted away from the development process and handled entirely by the cloud infrastructure that Cloud Foundry provides.

然后,Cloud Foundry将管理您的应用程序的运行时,中间件和O / S环境。 此外,诸如负载平衡,应用程序运行时和流式应用程序日志记录之类的任务会从开发过程中抽象出来,并完全由Cloud Foundry提供的云基础架构来处理。

That is the entire process. Once your application has been deployed to AppFog, all of your infrastructure headaches are over. You’re now free to focus on the application’s codebase.

那就是整个过程。 将您的应用程序部署到AppFog之后,所有基础架构的麻烦都结束了。 现在,您可以将精力集中在应用程序的代码库上。

将AppFog绑定到12要素App方法论中 (Tying AppFog into the 12-Factor App Methodology)

Your Codebase, Dependencies, Configuration, and Backing Services are 12-Factor principles related to your application and its data. This means they are best managed by you, the developer.

您的代码库,依赖项,配置和支持服务是与应用程序及其数据相关的12要素原则。 这意味着它们最好由开发人员您来管理。

Almost everything else about your app can be handled through AppFog, since AppFog has been built with the 12-Factor Application methodology in mind. For example, Concurrency, Disposability and Logging are all managed by AppFog automatically, once you’ve deployed your codebase. In fact, AppFog manages all hardware, software patching, updates, the physical and software security, and any day-to-day, routine operational tasks.

由于AppFog是在考虑了12要素应用程序方法的基础上构建的,因此几乎所有与您的应用程序有关的所有其他事情都可以通过AppFog处理。 例如,一旦部署了代码库,并发性,可分发性和日志记录都将由AppFog自动管理。 实际上,AppFog管理所有硬件,软件修补程序,更新,物理和软件安全性以及任何日常的日常操作任务。

While some of the 12-Factor App principles may require a small amount of thought and configuration to set up, the majority are handled seamlessly when you deploy your application to AppFog. Not only does AppFog make this process a lot easier, the team offers plenty of documentation and support for any questions you might have. You can find all of the relevant documentation on CenturyLink’s Knowledge Base.

虽然12要素App原则中的某些原则可能需要少量的思想和配置来设置,但是当您将应用程序部署到AppFog时,大多数原则都是无缝处理的。 AppFog不仅使此过程变得更加简单,而且团队会为您可能遇到的任何问题提供大量文档和支持。 您可以在CenturyLink的知识库中找到所有相关文档。

Building 12-Factor applications can be a challenging process, but AppFog has done the majority of the hard work for you. All that’s left for you to do is write your code and deploy.

构建12因子应用程序可能是一个具有挑战性的过程,但是AppFog已经为您完成了大部分艰苦的工作。 剩下要做的就是编写代码并进行部署。

For additional resources on the 12-Factor App Methodology and how AppFog makes it easier, be sure to review AppFog’s in-depth explanation.

有关12要素App方法论的其他资源以及AppFog如何使其变得更容易,请确保查看AppFog的深入说明

结论 (Conclusion)

The 12-Factor App Methodology is an exceptional blueprint that provides every necessary step to deploying a reliable SaaS product. While managing all of those steps (and choosing the correct services that do so) can be overwhelming, AppFog PaaS makes the process smoother, taking care of aspects of your app like Concurrency and Disposability so you can focus on writing good code that offers something special to your users.

“十二要素应用程序方法”是一个出色的蓝图,它提供了部署可靠的SaaS产品所需的每个必要步骤。 虽然管理所有这些步骤(并选择正确的服务)可能会令人不知所措,但AppFog PaaS可以使流程更流畅,并照顾到应用程序的诸如并发性和可分发性等方面,因此您可以专注于编写具有特殊功能的良好代码给您的用户。

Wouldn’t you rather focus on building your app and delivering “delight” to your clients, and let AppFog take care of the rest?

您是否愿意专注于构建应用程序并为客户提供“愉悦”的服务,而让AppFog负责其余工作?

翻译自: https://www.sitepoint.com/12-factor-apps-methodology-implement-apps-appfog/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值