May 2025
Beginner to intermediate
430 pages
4h 37m
Chinese
Content preview from 基础设施即代码,第2版
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,







O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
第 9 章 测试基础架构栈 测试基础设施堆栈
本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com
本章将持续测试和交付代码的核心实践应用于基础架构栈。它使用 ShopSpinner 示例来说明如何测试堆栈项目。这包括使用在线和离线测试阶段,以及利用测试夹具将堆栈与依赖关系解耦。
基础设施实例
ShopSpinner 团队使用可重复使用的堆栈项目(参见"模式:可重复使用的堆栈"),为每个客户创建一致的应用基础架构实例。团队还可以利用它在管道中创建基础架构的测试实例。
这些示例的基础设施是一个标准的三层系统。每层基础设施包括
- 网络服务器容器集群
-
团队为每个区域和每个测试环境运行一个网络服务器容器集群。区域或环境中的应用程序共享该群集。本章示例的重点是每个客户专用的基础架构,而不是共享基础架构。因此,共享集群在此处的示例中是一个依赖项。有关如何在此基础架构中协调和测试变更的详细信息,请参阅第 17 章。
- 应用服务器
-
每个应用实例的基础架构包括虚拟机、持久磁盘卷和网络。Network+ 包括地址块、网关、网络端口服务器路由和网络访问规则。
- 数据库
-
ShopSpinner使用其供应商的DBaaS(参见"存储资源"),为每个客户应用实例运行一个单独的数据库实例。ShopSpinner 的基础架构代码还定义了地址块、路由、数据库验证和访问规则。
示例堆栈
首先,我们可以定义一个可重复使用的堆栈,其中包含除网络服务器群集之外的所有基础架构。项目结构如例 9-1 所示。
例 9-1. ShopSpinner 客户应用程序的堆栈项目
stack-project/└── src/├── appserver_vm.infra├── appserver_networking.infra├── database.infra└── database_networking.infra
在该项目中,appserver_vm.infra文件包含的代码与例 9-2 中所示的内容大致相同。
例 9-2. appserver_vm.infra 的部分内容
virtual_machine:name:appserver-${customer}-${environment}ram:4GBaddress_block:ADDRESS_BLOCK.appserver-${customer}-${environment}storage_volume:STORAGE_VOLUME.app-storage-${customer}-${environment}base_image:SERVER_IMAGE.shopspinner_java_server_imageprovision:tool:servermakerparameters:maker_server:maker.shopspinner.xyzrole:appservercustomer:${customer}environment:${environment}storage_volume:id:app-storage-${customer}-${environment}size:80GBformat:xfs
团队成员或自动化流程可以通过运行堆栈工具来创建或更新堆栈实例。他们使用第 7 章中的一种模式向实例传递值。
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access