【微服务】.netCore eShopOnContainers 部署实践《一》

官方说明文档

--------------------------------------------------------------

# eShopOnContainers - Microservices Architecture and Containers based Reference Application (**BETA state** - Visual Studio 2017 and CLI environments compatible)
Sample .NET Core reference application, powered by Microsoft, based on a simplified microservices architecture and Docker containers.

微服务框架基于 Visual Studio 2017 和 CLI 兼容模式

## IMPORTANT NOTES!
**The current supported Visual Studio version for eShopOnContainers is Visual Studio 2017 15.7** ([GA/RTM since May 8th 2018](https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes)) or later version.

**Note for Pull Requests (PRs)**: We accept pull request from the community. When doing it, please do it onto the **DEV branch** which is the consolidated work-in-progress branch. Do not request it onto Master branch, if possible.

**NEWS / ANNOUNCEMENTS**
Do you want to be up-to-date on .NET Architecture guidance and reference apps like eShopOnContainers? --> Subscribe by "WATCHING" this new GitHub repo: https://github.com/dotnet-architecture/News

Visual Studio 版本必须 2017 15.7.* 以上

支持推送develop 分支

更多.Net 框架项目参考  https://github.com/dotnet-architecture/News


## Updated for .NET Core 2.0 "wave" of technologies
eShopOnContainers is updated to .NET Core 2.0 "wave". Not just compilation but also new recommended code in EF Core 2.0, ASP.NET Core 2.0, and other new related versions.

The **dockerfiles** in the solution have also been updated and now support [**Docker Multi-Stage**](https://blogs.msdn.microsoft.com/stevelasker/2017/09/11/net-and-multistage-dockerfiles/) since mid-December 2017.

For a list on the new .NET Core 2.0 related implemented features, see this [blog post](https://blogs.msdn.microsoft.com/dotnet/2017/08/02/microservices-and-docker-containers-architecture-patterns-and-development-guidance/).

>**PLEASE** Read our [branch guide](./branch-guide.md) to know about our branching policy

建议使用.NET Core2.0、 EF Core2.0、ASP .NET Core 2.0及以上版本

dockerfiles 于2017.12月中旬开始更新  地址 https://blogs.msdn.microsoft.com/stevelasker/2017/09/11/net-and-multistage-dockerfiles

.NET Core 新特性以及依赖 参考 https://blogs.msdn.microsoft.com/dotnet/2017/08/02/microservices-and-docker-containers-architecture-patterns-and-development-guidance/


> ### DISCLAIMER 免责声明
> **IMPORTANT:** The current state of this sample application is **BETA**, because we are constantly evolving towards new released technologies. Therefore, many areas could be improved and change significantly while refactoring current code and implementing new features. Feedback with improvements and pull requests from the community will be highly appreciated and accepted.
项目仅为了演示,很多模块可能重构或者引用新的依赖
> This reference application proposes a simplified microservice oriented architecture implementation to introduce technologies like .NET Core with Docker containers through a comprehensive application. The chosen domain is an eShop/eCommerce but simply because it is a well-know domain by most people/developers.

通过一个应用来演示 .NET Core 和Docker容器技术
However, this sample application should not be considered as an "eCommerce reference model", at all. The implemented business domain might not be ideal from an eCommerce business point of view. It is neither trying to solve all the problems in a large, scalable and mission-critical distributed system. It is just a bootstrap for developers to easily get started in the world of Docker containers and microservices with .NET Core.

仅仅是简单演示程序,不能作为真的电子商务系统,不解决其它高并发、高可用等问题
> <p>For example, the next step after running the solution in the local dev PC and understanding Docker containers and microservices development with .NET Core, is to select a microservice cluster/orchestrator like Kubernetes in Azure (AKS) or Azure Service Fabric, both environments tested and supported by this solution.
> Additional steps would be to move your databases to HA cloud services (like Azure SQL Database), or switch your EventBus to use Azure Service Bus (instead of bare-bone RabbitMQ) or any other production ready Service Bus in the market.

![image](https://user-images.githubusercontent.com/1712635/40397331-059a7ec6-5de7-11e8-8542-a597eca16fef.png)

> Read the planned <a href='https://github.com/dotnet/eShopOnContainers/wiki/01.-Roadmap-and-Milestones-for-future-releases'>Roadmap and Milestones for future releases of eShopOnContainers</a> within the Wiki for further info about possible new implementations and provide feedback at the  <a href='https://github.com/dotnet/eShopOnContainers/issues'>ISSUES section</a> if you'd like to see any specific scenario implemented or improved. Also, feel free to discuss on any current issue.
计划  里程碑 https://github.com/dotnet/eShopOnContainers/wiki/01.-Roadmap-and-Milestones-for-future-releases

问题  https://github.com/dotnet/eShopOnContainers/issues
### Architecture overview
This reference application is cross-platform at the server and client side, thanks to .NET Core services capable of running on Linux or Windows containers depending on your Docker host, and to Xamarin for mobile apps running on Android, iOS or Windows/UWP plus any browser for the client web apps.
The architecture proposes a microservice oriented architecture implementation with multiple autonomous microservices (each one owning its own data/db) and implementing different approaches within each microservice (simple CRUD vs. DDD/CQRS patterns) using Http as the communication protocol between the client apps and the microservices and supports asynchronous communication for data updates propagation across multiple services based on Integration Events and an Event Bus (a light message broker, to choose between RabbitMQ or Azure Service Bus, underneath) plus other features defined at the <a href='https://github.com/dotnet/eShopOnContainers/wiki/01.-Roadmap-and-Milestones-for-future-releases'>roadmap</a>.
<p>
<img src="img/eshop_logo.png">
<img src="https://user-images.githubusercontent.com/1712635/38758862-d4b42498-3f27-11e8-8dad-db60b0fa05d3.png">
<p>
跨平台,建议使用微服务自治结构,使用Http通讯协议,数据更新使用事件或事件总线
> ### Important Note on API Gateways and published APIs
> Since April 2018, we have introduced the implementation of the [API Gateway pattern](http://microservices.io/patterns/apigateway.html) and [Backend-For-Front-End (BFF) pattern](https://samnewman.io/patterns/architectural/bff/) in eShopOnContainers architecture, so you can filter and publish simplified APIs and URIs and apply additional security in that tier while hiding/securing the internal microservices to the client apps or outside consumers. These sample API Gateways in eShopOnContainers are based on [Ocelot](https://github.com/ThreeMammals/Ocelot), an OSS lightweight API Gateway solution explained [here](http://threemammals.com/ocelot). The deployed API Gateways are autonomous and can be deployed as your own custom microservices/containers, as it is currently done in eShopOnContainers, so you can test it even in a simple development environment with just Docker engine or deploy it into orchestrators like Kubernetes in AKS or Service Fabric.
API网关  http://microservices.io/patterns/apigateway.html    BFF    https://samnewman.io/patterns/architectural/bff/      Ocelot  https://github.com/ThreeMammals/Ocelot    OSS lightweight API Gateway solution  http://threemammals.com/ocelot

优先开始部署API网关
> For your production-ready architecture you can either keep using [Ocelot](https://github.com/ThreeMammals/Ocelot) which is simple and easy to use and used in production by significant companies or if you need further functionality and a much richer set of features suittable for commercial APIs, you can also substitute those API Gateways and use [Azure API Management](https://azure.microsoft.com/en-us/services/api-management/) or any other commercial API Gateway, as shown in the following image.

> The sample code in this repo is NOT making use of Azure API Management in order to be able to provide an "F5 experience" in Visual Studio (or CLI) of the sample with no up-front dependencies in Azure. But you could evaluate API Gateways alternatives when building for production.

> ### Internal architecture and design of the microservices

> The microservices are different in type, meaning different internal architecture pattern approaches depending on its purpose, as shown in the image below.


> ### Important Note on Database Servers/Containers
> In this solution's current configuration for a development environment, the SQL databases are automatically deployed with sample data into a single SQL Server container (a single shared Docker container for SQL databases) so the whole solution can be up and running without any dependency to any cloud or specific server. Each database could also be deployed as a single Docker container, but then you'd need more than 8GB of RAM assigned to Docker in your development machine in order to be able to run 3 SQL Server Docker containers in your Docker Linux host in "Docker for Windows" or "Docker for Mac" development environments.
> <p> A similar case is defined in regard to Redis cache running as a container for the development environment. Or a No-SQL database (MongoDB) running as a container.
> <p> However, in a real production environment it is recommended to have your databases (SQL Server, Redis, and the NO-SQL database, in this case) in HA (High Available) services like Azure SQL Database, Redis as a service and Azure CosmosDB instead the MongoDB container (as both systems share the same access protocol). If you want to change to a production configuration, you'll just need to change the connection strings once you have set up the servers in a HA cloud or on-premises.
SQL数据库自动依赖,可以不需要任何云数据库和特别服务器,就可以运行,如果要依赖数据库需要至少8G内存,运行3个数据库
## Related documentation and guidance
While developing this reference application, we've been creating a reference <b>Guide/eBook</b> focusing on <b>architecting and developing containerized and microservice based .NET Applications</b> (download link available below) which explains in detail how to develop this kind of architectural style (microservices, Docker containers, Domain-Driven Design for certain microservices) plus other simpler architectural styles, like monolithic apps that can also live as Docker containers.
<p>
There are also additional eBooks focusing on Containers/Docker lifecycle (DevOps, CI/CD, etc.) with Microsoft Tools, already published plus an additional eBook focusing on Enterprise Apps Patterns with Xamarin.Forms.
You can download them and start reviewing these Guides/eBooks here:
<p>

电子书下载

https://aka.ms/microservicesebook (Architecting & Developing) 推荐

https://aka.ms/dockerlifecycleebook  (Containers Lifecycle & CI/CD)

https://aka.ms/xamarinpatternsebook (App patterns with Xamarin.Forms)



However, we encourage to download and review the [Architecting and Developing Microservices eBook](https://aka.ms/microservicesebook) because the architectural styles and architectural patterns and technologies explained in the guidance are using this reference application when explaining many pattern implementations, so you'll understand much better the context, design and decisions taken in the current architecture and internal designs.

## Overview of the application code
In this repo you can find a sample reference application that will help you to understand how to implement a microservice architecture based application using <b>.NET Core</b> and <b>Docker</b>.

The example business domain or scenario is based on an eShop or eCommerce which is implemented as a multi-container application. Each container is a microservice deployment (like the basket-microservice, catalog-microservice, ordering-microservice and the  identity-microservice) which are developed using ASP.NET Core running on .NET Core so they can run either on Linux Containers and Windows Containers.
The screenshot below shows the VS Solution structure for those microservices/containers and client apps.
基本结构

Finally, those microservices are consumed by multiple client web and mobile apps, as described below.


## Setting up your development environment for eShopOnContainers
### Visual Studio 2017 and Windows based
This is the more straightforward way to get started:
https://github.com/dotnet-architecture/eShopOnContainers/wiki/02.-Setting-eShopOnContainers-in-a-Visual-Studio-2017-environment

### CLI and Windows based
For those who prefer the CLI on Windows, using dotnet CLI, docker CLI and VS Code for Windows:
https://github.com/dotnet/eShopOnContainers/wiki/03.-Setting-the-eShopOnContainers-solution-up-in-a-Windows-CLI-environment-(dotnet-CLI,-Docker-CLI-and-VS-Code)

### CLI and Mac based
For those who prefer the CLI on a Mac, using dotnet CLI, docker CLI and VS Code for Mac:
https://github.com/dotnet-architecture/eShopOnContainers/wiki/04.-Setting-eShopOnContainer-solution-up-in-a-Mac,-VS-for-Mac-or-with-CLI-environment--(dotnet-CLI,-Docker-CLI-and-VS-Code)

## Orchestrators: Kubernetes and Service Fabric
See at the [Wiki](https://github.com/dotnet-architecture/eShopOnContainers/wiki) the posts on setup/instructions about how to deploy to Kubernetes or Service Fabric in Azure (although you could also deploy to any other cloud or on-premises).

## Sending feedback and pull requests
As mentioned, we'd appreciate your feedback, improvements and ideas.
You can create new issues at the issues section, do pull requests and/or send emails to **eshop_feedback@service.microsoft.com**

## Questions
[QUESTION] Answer +1 if the solution is working for you (Through VS2017 or CLI environment):
https://github.com/dotnet/eShopOnContainers/issues/107

 

转载于:https://www.cnblogs.com/bindot/p/eShopOnContainers_1.html

基于简化的微服务架构和Docker容器的Microsoft由Microsoft提供的示例.NET Core参考应用程序。   免责声明 重要说明:此示例应用程序的当前状态是ALPHA,认为这是版本0.1版本的基础,因此,很多方面还有待改进和改变显著而重构当前的代码和实现新的功能。对社区的改进和反馈将受到高度的赞赏和接受。 该参考应用程序提出了一个简化的面向服务的体系结构实现,通过综合应用程序引入诸如.NET Core与Docker容器之类的技术。然而,这个引用应用程序并不是要解决大型和关键任务的分布式系统中的所有问题,只是让开发人员轻松开始使用.NET Core的Docker容器和微服务器的开始。 例如,在了解Docker容器和使用.NET Core开发微服务器之后,下一步(eShopOnContainers还没有涵盖),就是选择像Docker Swarm,Kubernetes或DC / OS(Azure容器服务)或Azure中的微服务集群/协调器在大多数情况下,服务结构将需要对应用程序的配置进行额外的部分更改(尽管当前体系结构应适用于大多数具有较小更改的业务流程)。或将数据库移动到HA云服务,或者在Azure Service Bus或任何其他生产就绪的服务总线市场上实施EventBus。 在将来,我们可能会分配此项目,并针对特定的微服务集群/协调者加上多个版本,并使用额外的云基础架构。 有关可能的新实施的更多信息,请阅读Wiki中未来版本的eShopOnContainers的计划路线图和里程碑,并在ISSUES部分提供反馈,如果您希望看到任何特定的方案得到实施或改进。此外,请随时讨论任何当前的问题。 架构概述:本参考应用程序是在服务器端和客户端的跨平台两种,由于能够根据您的码头工人主机上的Linux或Windows容器运行的.NET的核心服务,并为Xamarin的Android,iOS或正在运行的移动应用Windows / UWP加上客户端网络应用程序的任何浏览器。该架构提出了一种简化的面向服务的架构实现,其中包含多个自主的微服务器(每个拥有自己的数据/ db),并使用Http作为当前的通信协议,在每个微服务器(简单的CRUD vs. DDD / CQRS模式)中实现不同的方法。 它还支持异步通信,用于基于集成事件和事件总线以及路线图中定义的其他功能的多个服务的数据更新传播。 微服务的类型不同,这意味着不同的内部架构模式取决于其目的,如下图所示。   最终将添加与其他框架和No-SQL数据库的其他miroservice样式。这是一个很好的机会,来自社区的拉动请求,例如使用Nancy的新微服务,或者甚至其他语言,如Node,Go,Python或具有MongoDB Azure DocDB兼容性的数据容器,PostgreSQL,RavenDB,Event Store,MySql等。) 数据库服务器/容器的重要说明 在该解决方案当前的开发环境配置中,SQL数据库将自动部署样本数据到单个SQL Server for Linux容器(SQL数据库的单一共享Docker容器),因此整个解决方案可以启动并运行,而无需任何依赖任何云或特定的服务器。每个数据库也可以部署为单个Docker容器,但是在开发机器中,您需要将8GB或更多的内存RAM分配给Docker才能在Docker Linux主机中运行3个SQL Server Docker容器, Docker for Windows“或”Docker for Mac“开发环境。 在将Redis缓存作为开发环境的容器运行时,定义了类似的情况。 但是,在实际的生产环境中,建议您将数据库(在本例中为SQL Server和Redis)设置为HA(高可用性)服务,如Azure SQL数据库,Redis服务或任何其他集群系统。如果要更改为生产配置,只需在HA云或内部部署服务器后更改连接字符串即可。 相关文档和指导 在开发这个参考应用,我们正在创造一个参考指南/电子书名为“构建和开发集装箱和微服务基于.NET应用程序”,其详细阐述了如何开发这种建筑风格(微服务,多克尔容器,领域驱动设计某些微服务)以及其他更简单的架构风格,如可以作为Docker容器生活的单片应用程序。 还有其他电子书专注于容器/ Docker生命周期(DevOps,CI / CD等)与Microsoft Tools,已经发布,另外还有一本关于使用Xamarin.Forms的企业应用程序模式的电子书。您可以下载它们,并在这里开始审查这些指南/电子书:   建筑与发展 集装箱生命周期和CI / CD 应用程序模式与Xamarin.Forms 下载(初稿,在进行的工作) 下载(自2016年后期第一版) 下载(初稿,在进行的工作) 发送反馈给cesardl@microsoft.com 然而,我们鼓励下载和审查“架构与开发电子书”,因为在指导中解释的架构风格和架构模式和技术在解释许多模式实现时使用此参考应用程序,因此您将更好地了解上下文,设计以及在当前架构和内部设计中采取的决策。 应用程序代码概述 在这种回购,你可以找到一个样本参考应用,将帮助您了解如何实现用微服务架构的应用.NET的核心和多克。 示例业务域或场景基于作为多容器应用实现的eShop或电子商务。每个容器都是使用.NET Core运行的ASP.NET Core开发的一个微服务部署(如basket-microservice,catalog-microservice,ordering-microservice和identity-microservice),因此可以在Linux Containers和Windows Containers 。下面的屏幕截图显示了这些微服务器/容器和客户端应用程序的VS Solution结构。 (推荐入门时)开放eShopOnContainers-ServicesAndWebApps.sln为仅包含相关的微服务和Web应用程序的服务器端项目的解决方案。 开放eShopOnContainers-MobileApps.sln为仅包含所述客户端的移动应用项目的解决方案(仅Xamarin移动应用)。它也是基于mocks独立工作的。 打开eShopOnContainers.sln包含所有项目(所有的客户端应用和服务)的解决方案。 最后,这些微服务由多个客户端网络和移动应用程序消耗,如下所述。 MVC应用程序(ASP.NET核心):它的一个MVC应用程序,你可以找到关于如何消费有趣的场景基于HTTP的从C#在服务器端运行的微服务,因为它是一个典型的ASP.NET MVC的核心应用。由于它是一个服务器端应用程序,因此内部Docker Host网络内部名称解析可以访问其他容器/微服务器。 SPA(单页应用):提供了类似的“网上商店的业务功能”,而是开发了角2,打字稿及轻微使用ASP.NET MVC的核心。这是客户端Web应用程序的另一种方法,当您希望拥有更现代的客户端行为时,其行为与每个操作上的典型浏览器往返行为不同,但表现为类似于单页应用程序的单页面应用程序桌面应用使用体验。基于HTTP的微服务的消耗由客户端浏览器中的TypeScript / JavaScript完成,因此客户端调用微服务器来自Docker Host内部网络(从您的网络甚至从互联网)。 Xamarin移动应用(对于iOS,Android和Windows / UWP) :这是一个客户端移动应用程序支持最常见的移动操作系统平台(的iOS,Android和Windows / UWP)。在这种情况下,微服务的消耗是从C#完成的,但是在客户端设备上运行, 为eShopOnContainers设置开发环境 Visual Studio 2017和Windows 这是更直接的入门方式:https://github.com/dotnet/eShopOnContainers/wiki/02.-Setting-eShopOnContainer-solution-up-in-a-Visual-Studio-2017- environment  CLI和Windows 对于喜欢Windows的CLI的用户,使用dotnet CLI,Docker CLI和Windows的VS代码: https://github.com/dotnet/eShopOnContainers/wiki/03.-Setting-the-eShopOnContainers-solution-up-in-a-Windows-CLI-environment-(dotnet-CLI,-Docker-CLI-and-VS-Code) CLI和Mac 对于那些喜欢在Mac上使用CLI的用户,使用dotnet CLI,Docker CLI和VS代码(说明仍然TBD,但类似于Windows CLI):https://github.com/dotnet/eShopOnContainers/wiki/04.-设置eShopOnContainer-in-a-Mac,-VS-Code-and-CLI-environment - (dotnet-CLI,-Docker-CLI-and-VS-Code) 关于测试的Docker容器/图像的注意事项 大部分项目的开发和测试的是(如三月初2017)完成对码头工人的Linux容器在开发机器与“泊坞的Windows”运行,默认是“泊坞的Windows”已安装的Hyper-V的Linux VM(MobiLinuxVM) 。该窗口的容器方案,目前正在实施/测试还没有。应用程序应该能够在基于不同Docker基础映像的Windows Nano Containers上运行,因为.NET Core服务也已经在普通Windows(没有Docker)上运行。该应用程序也使用安装了.NET Core和VS代码的开发MacOS机器在“Docker for Mac”中进行了部分测试,这仍然是使用在Mac上的VM安装程序上运行的Linux容器的“Docker for Windows” 建立。但是,来自社区的Mac环境和Windows Containers的进一步测试和反馈将不胜感激。 发送反馈和建议 如上所述,我们非常感谢您的反馈,改进和想法。您可以在问题部分创建新问题, 或发送电子邮件至eshop_feedback@service.microsoft.com 问题 问题列表:https://github.com/dotnet/eShopOnContainers/issues/107 标签:docker  微服务
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值