Skip to content

Commit 42f3537

Browse files
author
Carlos Cañizares Estévez
committed
scripts to build individual services, readme files for all services and clients, compose in all projects, fix build problems (Dependent seeds), solve some kwnon build problems in solution (identity on localhost, ...)
1 parent 0a344f6 commit 42f3537

84 files changed

Lines changed: 1807 additions & 695 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,57 @@
11
# Containerized eShop
22
Sample reference containerized application, cross-platform and microservices architecture.
3-
Powered by .NET Core, Docker and Docker Swarm mode
3+
Powered by Microsoft
4+
5+
<img src="img/eshop_cover.png">
6+
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>.
9+
10+
11+
#Tools
12+
#### Windows
13+
<a href='https://github.com/docker/toolbox/releases/download/v1.12.3/DockerToolbox-1.12.3.exe'>Docker tools for windows</a>
14+
15+
####Mac
16+
<a href='https://github.com/docker/toolbox/releases/download/v1.12.3/DockerToolbox-1.12.3.pkg'>Docker tools for Mac</a>
17+
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:
20+
21+
<img src="img/docker_settings.png">
22+
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.
25+
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.
27+
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.
29+
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.
31+
32+
#Deploy goblal
33+
In the global directory you will find the scripts needed to run and deploy the demo into your local docker infraestructure. The steps:
34+
35+
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.
37+
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`
39+
40+
#Run
41+
Once the deploy process of docker-compose finishes you have to be able to access the services in this urls from your machine:
42+
- Web: http://localhost:5100
43+
- Web Spa: http://localhost:5104
44+
- Catalog service: http://localhost:5101
45+
- Orders service: http://localhost:5102
46+
- Basket service: http://localhost:5103
47+
- Identity service: http://localhost:5105
48+
- Orders data (SQL Server): Server=tcp:localhost,5432;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;
49+
- Catalog data (SQL Server): Server=tcp:localhost,5434;Database=CatalogDB;User Id=sa;Password=Pass@word
50+
- Identity data (SQL Server): Server=localhost,5433;Database=aspnet-Microsoft.eShopOnContainers;User Id=sa;Password=Pass@word
51+
- Basket data (Redis): listening in localhost:6379
52+
53+
#Deploy individiual services into docker
54+
Under each project root you will find a readme.md file as this that describes how to run and deploy the service individually into a docker container.
55+
56+
57+

add-host-entry.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
param([switch]$Elevated)
2+
function Check-Admin {
3+
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
4+
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
5+
}
6+
if ((Check-Admin) -eq $false) {
7+
if ($elevated)
8+
{
9+
# could not elevate, quit
10+
}
11+
12+
else {
13+
14+
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
15+
}
16+
exit
17+
}
18+
19+
ac -Encoding UTF8 C:\Windows\system32\drivers\etc\hosts "127.0.0.1 identity.service"

build-image-service-basket.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
2+
3+
Write-Host "Current script directory is $scriptPath" -ForegroundColor Yellow
4+
5+
#*** Basket service image ***
6+
$basketPathToJson = $scriptPath + "\src\Services\Basket\Basket.API\project.json"
7+
Write-Host "basketPathToJson is $basketPathToJson" -ForegroundColor Yellow
8+
$basketPathToPub = $scriptPath + "\pub\basket"
9+
Write-Host "basketPathToPub is $basketPathToPub" -ForegroundColor Yellow
10+
11+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
12+
dotnet restore $basketPathToJson
13+
dotnet build $basketPathToJson
14+
dotnet publish $basketPathToJson -o $basketPathToPub
15+
16+
docker build -t eshop/basket.api $basketPathToPub

build-image-service-catalog.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
2+
3+
Write-Host "Current script directory is $scriptPath" -ForegroundColor Yellow
4+
5+
#*** Catalog service image ***
6+
$catalogPathToJson = $scriptPath + "\src\Services\Catalog\Catalog.API\project.json"
7+
Write-Host "catalogPathToJson is $catalogPathToJson" -ForegroundColor Yellow
8+
$catalogPathToPub = $scriptPath + "\pub\catalog"
9+
Write-Host "catalogPathToPub is $catalogPathToPub" -ForegroundColor Yellow
10+
11+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
12+
dotnet restore $catalogPathToJson
13+
dotnet build $catalogPathToJson
14+
dotnet publish $catalogPathToJson -o $catalogPathToPub
15+
16+
docker build -t eshop/catalog.api $catalogPathToPub

build-image-service-identity.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
2+
3+
Write-Host "Current script directory is $scriptPath" -ForegroundColor Yellow
4+
5+
# *** identitySvc image ***
6+
$identitySvcPathToJson = $scriptPath + "\src\Services\Identity\eShopOnContainers.Identity\project.json"
7+
Write-Host "identitySvcPathToJson is $identitySvcPathToJson" -ForegroundColor Yellow
8+
$identitySvcPathToPub = $scriptPath + "\pub\identity"
9+
Write-Host "identitySvcPathToPub is $identitySvcPathToPub" -ForegroundColor Yellow
10+
11+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
12+
dotnet restore $identitySvcPathToJson
13+
dotnet build $identitySvcPathToJson
14+
dotnet publish $identitySvcPathToJson -o $identitySvcPathToPub
15+
16+
docker build -t eshop/identity $identitySvcPathToPub

build-image-service-orders.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
2+
3+
Write-Host "Current script directory is $scriptPath" -ForegroundColor Yellow
4+
5+
#*** Ordering service image ***
6+
$orderingPathToJson = $scriptPath + "\src\Services\Ordering\Ordering.API\project.json"
7+
Write-Host "orderingPathToJson is $orderingPathToJson" -ForegroundColor Yellow
8+
$orderingPathToPub = $scriptPath + "\pub\ordering"
9+
Write-Host "orderingPathToPub is $orderingPathToPub" -ForegroundColor Yellow
10+
11+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
12+
dotnet restore $orderingPathToJson
13+
dotnet build $orderingPathToJson
14+
dotnet publish $orderingPathToJson -o $orderingPathToPub
15+
16+
docker build -t eshop/ordering.api $orderingPathToPub

build-image-web-spa.ps1

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
2+
3+
Write-Host "Current script directory is $scriptPath" -ForegroundColor Yellow
4+
5+
$pubFolderToDelete = $scriptPath + "\pub"
6+
remove-item -path $pubFolderToDelete -Force -Recurse -ErrorAction SilentlyContinue
7+
8+
# *** WebSPA image ***
9+
$webSPAPathToJson = $scriptPath + "\src\Web\WebSPA\eShopOnContainers.WebSPA\project.json"
10+
Write-Host "webSPAPathToJson is $webSPAPathToJson" -ForegroundColor Yellow
11+
$webSPAPathToPub = $scriptPath + "\pub\webSPA"
12+
$webSPAPathToNpmBat = $scriptPath + "\src\Web\WebSPA\eShopOnContainers.WebSPA\buildspa.bat"
13+
Write-Host "webSPAPathToPub is $webSPAPathToPub" -ForegroundColor Yellow
14+
15+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
16+
dotnet restore $webSPAPathToJson
17+
dotnet build $webSPAPathToJson
18+
# Start-Process "cmd.exe" "/c " + $webSPAPathToNpmBat
19+
dotnet publish $webSPAPathToJson -o $webSPAPathToPub
20+
21+
# *** identitySvc image ***
22+
$identitySvcPathToJson = $scriptPath + "\src\Services\Identity\eShopOnContainers.Identity\project.json"
23+
Write-Host "identitySvcPathToJson is $identitySvcPathToJson" -ForegroundColor Yellow
24+
$identitySvcPathToPub = $scriptPath + "\pub\identity"
25+
Write-Host "identitySvcPathToPub is $identitySvcPathToPub" -ForegroundColor Yellow
26+
27+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
28+
dotnet restore $identitySvcPathToJson
29+
dotnet build $identitySvcPathToJson
30+
dotnet publish $identitySvcPathToJson -o $identitySvcPathToPub
31+
32+
33+
#*** Catalog service image ***
34+
$catalogPathToJson = $scriptPath + "\src\Services\Catalog\Catalog.API\project.json"
35+
Write-Host "catalogPathToJson is $catalogPathToJson" -ForegroundColor Yellow
36+
$catalogPathToPub = $scriptPath + "\pub\catalog"
37+
Write-Host "catalogPathToPub is $catalogPathToPub" -ForegroundColor Yellow
38+
39+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
40+
dotnet restore $catalogPathToJson
41+
dotnet build $catalogPathToJson
42+
dotnet publish $catalogPathToJson -o $catalogPathToPub
43+
44+
#*** Ordering service image ***
45+
$orderingPathToJson = $scriptPath + "\src\Services\Ordering\Ordering.API\project.json"
46+
Write-Host "orderingPathToJson is $orderingPathToJson" -ForegroundColor Yellow
47+
$orderingPathToPub = $scriptPath + "\pub\ordering"
48+
Write-Host "orderingPathToPub is $orderingPathToPub" -ForegroundColor Yellow
49+
50+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
51+
dotnet restore $orderingPathToJson
52+
dotnet build $orderingPathToJson
53+
dotnet publish $orderingPathToJson -o $orderingPathToPub
54+
55+
#*** Basket service image ***
56+
$basketPathToJson = $scriptPath + "\src\Services\Basket\Basket.API\project.json"
57+
Write-Host "basketPathToJson is $basketPathToJson" -ForegroundColor Yellow
58+
$basketPathToPub = $scriptPath + "\pub\basket"
59+
Write-Host "basketPathToPub is $basketPathToPub" -ForegroundColor Yellow
60+
61+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
62+
dotnet restore $basketPathToJson
63+
dotnet build $basketPathToJson
64+
dotnet publish $basketPathToJson -o $basketPathToPub
65+
66+
#!/bin/bash
67+
# Delete all containers
68+
docker rm $(docker ps -a -q) -f
69+
# Delete all images
70+
docker rmi $(docker images -q)
71+
72+
#*** build docker images ***
73+
docker build -t eshop/catalog.api $catalogPathToPub
74+
docker build -t eshop/ordering.api $orderingPathToPub
75+
docker build -t eshop/basket.api $basketPathToPub
76+
docker build -t eshop/webspa $webSPAPathToPub
77+
docker build -t eshop/identity $identitySvcPathToPub

build-image-web.ps1

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
2+
3+
Write-Host "Current script directory is $scriptPath" -ForegroundColor Yellow
4+
5+
$pubFolderToDelete = $scriptPath + "..\..\pub"
6+
remove-item -path $pubFolderToDelete -Force -Recurse -ErrorAction SilentlyContinue
7+
#cmd /c "rd /s pub" /q
8+
9+
# *** WebMVC image ***
10+
$webPathToJson = $scriptPath + "\src\Web\WebMVC\project.json"
11+
Write-Host "webPathToJson is $webPathToJson" -ForegroundColor Yellow
12+
$webPathToPub = $scriptPath + "\pub\webMVC"
13+
Write-Host "webPathToPub is $webPathToPub" -ForegroundColor Yellow
14+
15+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
16+
dotnet restore $webPathToJson
17+
dotnet build $webPathToJson
18+
dotnet publish $webPathToJson -o $webPathToPub
19+
20+
# *** identitySvc image ***
21+
$identitySvcPathToJson = $scriptPath + "\src\Services\Identity\eShopOnContainers.Identity\project.json"
22+
Write-Host "identitySvcPathToJson is $identitySvcPathToJson" -ForegroundColor Yellow
23+
$identitySvcPathToPub = $scriptPath + "\pub\identity"
24+
Write-Host "identitySvcPathToPub is $identitySvcPathToPub" -ForegroundColor Yellow
25+
26+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
27+
dotnet restore $identitySvcPathToJson
28+
dotnet build $identitySvcPathToJson
29+
dotnet publish $identitySvcPathToJson -o $identitySvcPathToPub
30+
31+
#*** Catalog service image ***
32+
$catalogPathToJson = $scriptPath + "\src\Services\Catalog\Catalog.API\project.json"
33+
Write-Host "catalogPathToJson is $catalogPathToJson" -ForegroundColor Yellow
34+
$catalogPathToPub = $scriptPath + "\pub\catalog"
35+
Write-Host "catalogPathToPub is $catalogPathToPub" -ForegroundColor Yellow
36+
37+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
38+
dotnet restore $catalogPathToJson
39+
dotnet build $catalogPathToJson
40+
dotnet publish $catalogPathToJson -o $catalogPathToPub
41+
42+
#*** Ordering service image ***
43+
$orderingPathToJson = $scriptPath + "\src\Services\Ordering\Ordering.API\project.json"
44+
Write-Host "orderingPathToJson is $orderingPathToJson" -ForegroundColor Yellow
45+
$orderingPathToPub = $scriptPath + "\pub\ordering"
46+
Write-Host "orderingPathToPub is $orderingPathToPub" -ForegroundColor Yellow
47+
48+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
49+
dotnet restore $orderingPathToJson
50+
dotnet build $orderingPathToJson
51+
dotnet publish $orderingPathToJson -o $orderingPathToPub
52+
53+
#*** Basket service image ***
54+
$basketPathToJson = $scriptPath + "\src\Services\Basket\Basket.API\project.json"
55+
Write-Host "basketPathToJson is $basketPathToJson" -ForegroundColor Yellow
56+
$basketPathToPub = $scriptPath + "\pub\basket"
57+
Write-Host "basketPathToPub is $basketPathToPub" -ForegroundColor Yellow
58+
59+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
60+
dotnet restore $basketPathToJson
61+
dotnet build $basketPathToJson
62+
dotnet publish $basketPathToJson -o $basketPathToPub
63+
64+
#!/bin/bash
65+
# Delete all containers
66+
docker rm $(docker ps -a -q) -f
67+
# Delete all images
68+
docker rmi $(docker images -q)
69+
70+
#*** build docker images ***
71+
docker build -t eshop/web $webPathToPub
72+
docker build -t eshop/catalog.api $catalogPathToPub
73+
docker build -t eshop/ordering.api $orderingPathToPub
74+
docker build -t eshop/basket.api $basketPathToPub
75+
docker build -t eshop/identity $identitySvcPathToPub

build-images.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
21
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
32

43
Write-Host "Current script directory is $scriptPath" -ForegroundColor Yellow
54

65
$pubFolderToDelete = $scriptPath + "\pub"
76
remove-item -path $pubFolderToDelete -Force -Recurse -ErrorAction SilentlyContinue
8-
#cmd /c "rd /s pub" /q
97

108
# *** WebMVC image ***
119
$webPathToJson = $scriptPath + "\src\Web\WebMVC\project.json"
@@ -18,17 +16,18 @@ dotnet restore $webPathToJson
1816
dotnet build $webPathToJson
1917
dotnet publish $webPathToJson -o $webPathToPub
2018

19+
2120
# *** WebSPA image ***
2221
$webSPAPathToJson = $scriptPath + "\src\Web\WebSPA\eShopOnContainers.WebSPA\project.json"
2322
Write-Host "webSPAPathToJson is $webSPAPathToJson" -ForegroundColor Yellow
2423
$webSPAPathToPub = $scriptPath + "\pub\webSPA"
25-
#$webSPAPathToNpmBat = $scriptPath + "\src\Web\WebSPA\eShopOnContainers.WebSPA\buildspa.bat"
24+
$webSPAPathToNpmBat = $scriptPath + "\src\Web\WebSPA\eShopOnContainers.WebSPA\buildspa.bat"
2625
Write-Host "webSPAPathToPub is $webSPAPathToPub" -ForegroundColor Yellow
2726

2827
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
2928
dotnet restore $webSPAPathToJson
3029
dotnet build $webSPAPathToJson
31-
#Start-Process "cmd.exe" "/c " + $webSPAPathToNpmBat
30+
# Start-Process "cmd.exe" "/c " + $webSPAPathToNpmBat
3231
dotnet publish $webSPAPathToJson -o $webSPAPathToPub
3332

3433
# *** identitySvc image ***
@@ -76,6 +75,12 @@ dotnet restore $basketPathToJson
7675
dotnet build $basketPathToJson
7776
dotnet publish $basketPathToJson -o $basketPathToPub
7877

78+
#!/bin/bash
79+
# Delete all containers
80+
docker rm $(docker ps -a -q) -f
81+
# Delete all images
82+
docker rmi $(docker images -q)
83+
7984
#*** build docker images ***
8085
docker build -t eshop/web $webPathToPub
8186
docker build -t eshop/catalog.api $catalogPathToPub

0 commit comments

Comments
 (0)