Skip to content

Commit a666674

Browse files
author
Carlos Cañizares Estévez
committed
2 parents 47fd952 + b466659 commit a666674

10 files changed

Lines changed: 94 additions & 12 deletions

README.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,74 @@ Powered by Microsoft
44

55
<img src="img/eshop_cover.png">
66

7-
#Overview
8-
In this repo you will fin samples that will help you to get introduced into <b>.net core</b>, microservices environment and <b>docker</b>.
7+
## Overview
8+
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>.
99

10+
The demo scenario is based on an eShop or eCommerce which is composed by a multi-container application. Each container is a microservice (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. Finally, those microservices are consumed by multiple client web and mobile apps, which are the following.
11+
12+
MVC Application: Its an MVC 6 development where you can find good samples about how to work with microservices in a MVC asp.net core application.
13+
14+
SPA Application: Developed with Angular.js 2, Typescript and MVC 6. This is another approach for client web applications when you want to have a more modern behavior which is not having the typical browser round-trip on every action but behaving like a Single-Page-Application, more similar to a desktop app behavior.
15+
16+
Xamarin Application (Ios, Windows, Android): Its a client application that run in mobile devices (ios, android, windows) and you can find another example on how to build a microservices oriented application.
17+
18+
## Development Environment Setup
1019

1120
#Tools
12-
#### Windows
21+
### Installing and configuring Docker in your development machine
1322
<a href='https://github.com/docker/toolbox/releases/download/v1.12.3/DockerToolbox-1.12.3.exe'>Docker tools for windows</a>
1423

1524
####Mac
1625
<a href='https://github.com/docker/toolbox/releases/download/v1.12.3/DockerToolbox-1.12.3.pkg'>Docker tools for Mac</a>
1726

18-
##Set up Cpu and Memory
19-
In this demo we will run 3 instances of SQL Server, 6 asp.net core applications and 1 redis server it's important to set up properly the Cpu and Ram assigned to docker. This can be set, once installed docker in your device through the whale icon, right click, settings and in the Advanced option you will need to adjust the default to the new values shown in the image:
27+
##Set up assinged Memory and CPU to Docker
28+
In this application we run 3 instances of SQL Server running as containers plus 6 ASP.NET Core apps/services and 1 Redis server all of them running as Docker containers, as well. So it's important to set Docker up properly with enough memory RAM and CPU assigned to it. Once Docker for Windows is installed in your machine, enter into "Docker for Windows" Settings and its Advanced menu option so you are able to adjust the default values to the new values (Memory: Around 7GB and CPU:4) as shown in the image. Usually you might need a 16GB or 12GB memory machine for this configuration. If you have a less powerful machine, you can try with a lower configuration and/or by not starting certain containers like the basket and Redis. But if you don't start any of the containers, the application will not fully function properly, of course.
2029

2130
<img src="img/docker_settings.png">
2231

23-
#Demo
24-
The demo scenario is based on a ecommerce shop, each service is a .net core web application (basket, catalog, ordering, identity) and this services are consumed by differents web and mobile applications.
32+
Bower and Gulp global installation
33+
Before generating the Docker images, and specifically when generating the web apps binaries with "dotnet publish" from the custom stripts (like when running the build-images.ps1 script from PowerShell or the build-images.sh from bash in a Mac), you need to have access to the paths where you have installed Bower and Gulp. For that, the recomendation is to install Bower and Gulp with a global installation by running the following commands from command-line or bash:
2534

26-
MVC Application: Its an Mvc 6 development where you can find good samples about how to work with microservices in a MVC asp.net core application.
35+
**npm install -g bower**
2736

28-
SPA Application: Developed with Angular2, Typescript and Mvc 6, is another different aproach in web on how to work in a Microservices oriented solution.
37+
**npm install -g gulp**
38+
39+
Below you can see how those commands are run in Windows:
40+
<img src="img/Bower_and_Gulp_setup.png">
2941

30-
Xamarin Application (Ios, Windows, Android): Its a client application that run in mobile devices (ios, android, windows) and you can find another example on how to build a microservices oriented application.
3142

3243
#Deploy goblal
3344
In the global directory you will find the scripts needed to run and deploy the demo into your local docker infraestructure. The steps:
3445

3546

36-
- <a href='build-images.ps1'>build-images.ps1</a> <b>Build .net applications and docker images</b>: This power shell script that you will find in the <u>root directory of the solution</u> is the responsible of building .net applications and package in a pub folder and use docker commands to build the images needed to run the previously packaged .net applications.
47+
- <a href='build-images.ps1'>build-images.ps1</a> <b>Build the .NET applications and Docker images</b>: This Power-Shell script that you will find in the <u>root directory of the solution</u> is the responsible for building the .NET applications, copy binaries and package in a pub folder and use Docker commands to build the images needed to run the containers. You can see how to run that PowerShell script in the screenshot below:
48+
<img src="img/Generating_Docker_Images.png">
49+
50+
Once it finishes, you can check it out with Docker CLI if the images were generated correctly by typing in the PowerShell console:
51+
52+
**docker images**
53+
54+
You might have additional images, but at least, you should see the following list of images which are 6 custom images starting with the prefix "eshop" which is the name of the image repo:
55+
56+
<img src="img/list-of-images.png">
57+
58+
- <b>Compose containers in your docker local VM</b>: Finally you have to open your favourite command tool <u>pointing to the root directory of the solution</u> where docker-compose.yml file is located and run the command "docker-compose up"
59+
60+
when running "docker-compose up" you should see something similar to the following screenshot in the PowerShell command line, although it will be very long, even showing internal SQL commands from the services when populating the first time the sample data.
61+
62+
**docker-compose up**
63+
64+
<img src="img/docker-compose-up-1.png">
65+
66+
Note that the first time it detects that it needs the SQL Server image and the Redis image, it will pull or download the base images from the Internet, from the public repo at the Docker registry named DOCKER HUB by pulling the "microsoft/mssql-server-linux" which is the base image for the SQL Server for Linux on a Docker image, and the "library/redis" which is the base Redis image, so it might take more time until it spins up your custom containers.
67+
The next time you run docker-compose up, since it'll have those base images already downloaded, it will just start the containers, like in the following screenshot:
68+
69+
<img src="img/docker-compose-up-2.png">
70+
71+
Once docker-compose up finishes after a few minutes, you will have that PowerShell showing output from the execution, so in order to ask to Docker about how it went, you need to open a new PowerShell command and type "docker ps" so you'll see all the running containers, as shown in the following screenshot.
3772

38-
- <b>Compose containers in your docker local VM</b>: Finally you have to open your favourite command tool <u>pointing to the root directory of the solution</u> where docker-compose.yml file is located and run the command `docker-compose up`
73+
<img src="img/docker-ps-with-all-microservices.png">
74+
You can see the 6 custom containers running the microservices plus the 2 web applications. In adition you have the containers with the databases and the Redis cache for the basket data.
3975

4076
#Run
4177
Once the deploy process of docker-compose finishes you have to be able to access the services in this urls from your machine:

build-images.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ $webPathToPub = $scriptPath + "\pub\webMVC"
1212
Write-Host "webPathToPub is $webPathToPub" -ForegroundColor Yellow
1313

1414
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
15+
Write-Host "****************************************" -ForegroundColor Red
16+
Write-Host "webPathToJson: " + $webPathToJson -ForegroundColor Red
17+
Write-Host "webPathToPub: " + $webPathToPub -ForegroundColor Red
1518
dotnet restore $webPathToJson
1619
dotnet build $webPathToJson
1720
dotnet publish $webPathToJson -o $webPathToPub
21+
Write-Host "****************************************" -ForegroundColor Red
1822

1923

2024
# *** WebSPA image ***

hosts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 1993-2009 Microsoft Corp.
2+
#
3+
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
4+
#
5+
# This file contains the mappings of IP addresses to host names. Each
6+
# entry should be kept on an individual line. The IP address should
7+
# be placed in the first column followed by the corresponding host name.
8+
# The IP address and the host name should be separated by at least one
9+
# space.
10+
#
11+
# Additionally, comments (such as these) may be inserted on individual
12+
# lines or following the machine name denoted by a '#' symbol.
13+
#
14+
# For example:
15+
#
16+
# 102.54.94.97 rhino.acme.com # source server
17+
# 38.25.63.10 x.acme.com # x client host
18+
19+
# localhost name resolution is handled within DNS itself.
20+
# 127.0.0.1 localhost
21+
# ::1 localhost
22+
23+
10.0.75.1 identity.service

img/Bower_and_Gulp_setup.png

123 KB
Loading

img/Generating_Docker_Images.png

152 KB
Loading

img/docker-compose-up-1.png

198 KB
Loading

img/docker-compose-up-2.png

162 KB
Loading
103 KB
Loading

img/list-of-images.png

60.3 KB
Loading
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[cmdletbinding(SupportsShouldProcess=$true)]
2+
param($publishProperties=@{}, $packOutput, $pubProfilePath)
3+
4+
# to learn more about this file visit https://go.microsoft.com/fwlink/?LinkId=524327
5+
6+
try{
7+
if ($publishProperties['ProjectGuid'] -eq $null){
8+
$publishProperties['ProjectGuid'] = 'f0333d8e-0b27-42b7-b2c6-78f3657624e2'
9+
}
10+
11+
$publishModulePath = Join-Path (Split-Path $MyInvocation.MyCommand.Path) 'publish-module.psm1'
12+
Import-Module $publishModulePath -DisableNameChecking -Force
13+
14+
# call Publish-AspNet to perform the publish operation
15+
Publish-AspNet -publishProperties $publishProperties -packOutput $packOutput -pubProfilePath $pubProfilePath
16+
}
17+
catch{
18+
"An error occurred during publish.`n{0}" -f $_.Exception.Message | Write-Error
19+
}

0 commit comments

Comments
 (0)