Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
thinhnotes committed Aug 19, 2018
2 parents 97811b7 + 6ce2014 commit 2cfbc88
Show file tree
Hide file tree
Showing 60 changed files with 453 additions and 687 deletions.
85 changes: 44 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Cool Store Application on Service Mesh
# Cool Store: Cloud-Native Microservices Application on Service Mesh

<p align="left">
<a href="https://github.com/vietnam-devs/coolstore-microservices/blob/master/LICENSE"><img src="https://img.shields.io/badge/price-FREE-0098f7.svg" alt="Price"></a>
Expand All @@ -12,64 +12,63 @@ CoolStore is a containerised polyglot microservices application consisting of se
It demonstrates how to wire up small microservices into a larger application using microservice architectural principals.

### Presentation
Our team uses this application to demonstrate Kubernetes, AKS, Istio and similar cloud-native technologies in events as following

- [From Microservices to Service Mesh - DevCafe Event - July 2018](https://www.slideshare.net/ThangChung/from-microservices-to-service-mesh-devcafe-event-july-2018)
- [Service Mesh for Microservices- Vietnam Mobile Day Event - June 2018](https://www.slideshare.net/ThangChung/service-mesh-for-microservices-vietnam-mobile-day-june-2017)

# Table of contents

* [Prerequisites](https://github.com/vietnam-devs/coolstore-microservices#prerequisites)
* [Services](https://github.com/vietnam-devs/coolstore-microservices#services)
* [Up and Running](https://github.com/vietnam-devs/coolstore-microservices#up-and-running)
* [µServices](https://github.com/vietnam-devs/coolstore-microservices#services)
* [Installation](https://github.com/vietnam-devs/coolstore-microservices#up-and-running)
* [µService Development](https://github.com/vietnam-devs/coolstore-microservices#microservice-development)
* [Open API](https://github.com/vietnam-devs/coolstore-microservices#open-api)
* [CI/CD](https://github.com/vietnam-devs/coolstore-microservices#ci-cd)
* [Contributing](https://github.com/vietnam-devs/coolstore-microservices#contributing)
* [Contributors](https://github.com/vietnam-devs/coolstore-microservices#contributors)
* [Licence](https://github.com/vietnam-devs/coolstore-microservices#licence)

### Prerequisites
## Prerequisites

- Windows 10
- Windows Subsystem Linux (WSL - Ubuntu OS)
- Docker for Windows (Kubernetes enabled)
- Docker for Desktop (Kubernetes enabled)
- kubectl
- helm
- istioctl

### Services

There are several individual microservices and infrastructure components that make up this app:

1. Catalog Service: NodeJS service and MongoDB, serves products and prices for retail products
- [`http://localhost:5002`](http://localhost:5002)
- [`http://api.coolstore.local/catalog`](http://api.coolstore.local/catalog/swagger/)
2. Cart Service: .NET Core service which manages shopping cart for each customer
- [`http://localhost:5003`](http://localhost:5003)
- [`http://api.coolstore.local/cart`](http://api.coolstore.local/cart/swagger/)
3. Inventory Service: .NET Core service and SQL Server, serves inventory and availability data for retail products
- [`http://localhost:5004`](http://localhost:5004)
- [`http://api.coolstore.local/inventory`](http://api.coolstore.local/inventory/swagger/)
4. Pricing Service: .NET Core service which is a business rules application for product pricing
- [`http://localhost:5005`](http://localhost:5005)
- [`http://api.coolstore.local/pricing`](http://api.coolstore.local/pricing/swagger/)
5. Review Service: .NET Core service and SQL Server running for writing and displaying reviews for products
- [`http://localhost:5006`](http://localhost:5006)
- [`http://api.coolstore.local/review`](http://api.coolstore.local/review/swagger/)
6. Rating Service: NodeJS service running for rating products
- [`http://localhost:5007`](http://localhost:5007)
- [`http://api.coolstore.local/rating`](http://api.coolstore.local/rating/swagger/)
7. IdP: Identity Provider using [IdentityServer4](https://github.com/IdentityServer/IdentityServer4) to authentication with OAuth 2.0 and OpenID Connect for the whole stack
- [`http://localhost:5001`](http://localhost:5001)
- [`http://id.coolstore.local`](http://id.coolstore.local)
8. Web UI (PWA): A frontend based on [vuejs](https://vuejs.org/) and [Node.js](https://nodejs.org)
- [`http://localhost:8080`](http://localhost:8080)
- [`http://coolstore.local`](http://coolstore.local)
## µServices

There are several individual µservices and infrastructure components that make up this app:

| No. | Service | Language | Database | Description | Endpoints |
|-----|---------|----------|----------|-------------|-----------|
| 1 | Catalog | Node.js | Mongo | Serves products and prices for retail products | [`http://localhost:5002`](http://localhost:5002) or [`http://api.coolstore.local/catalog`](http://api.coolstore.local/catalog/swagger)
| 2 | Cart | .NET Core | MySQL | Manages shopping cart for each customer | [`http://localhost:5003`](http://localhost:5003) or [`http://api.coolstore.local/cart`](http://api.coolstore.local/cart/swagger)
| 3 | Inventory | .NET Core | MySQL | Serves inventory and availability data for retail products | [`http://localhost:5004`](http://localhost:5004) or [`http://api.coolstore.local/inventory`](http://api.coolstore.local/inventory/swagger)
| 4 | Pricing | .NET Core | MySQL | Handles a business rules application for product pricing | [`http://localhost:5005`](http://localhost:5005) or [`http://api.coolstore.local/pricing`](http://api.coolstore.local/pricing/swagger)
| 5 | Review | .NET Core | MySQL | Runs for writing and displaying reviews for products | [`http://localhost:5006`](http://localhost:5006) or [`http://api.coolstore.local/review`](http://api.coolstore.local/review/swagger)
| 6 | Rating | Node.js | Mongo | Runs for rating products | [`http://localhost:5007`](http://localhost:5007) or [`http://api.coolstore.local/rating`](http://api.coolstore.local/rating/swagger)
| 7 | IdP | .NET Core | In Memory | Uses [IdentityServer4](https://github.com/IdentityServer/IdentityServer4) to authentication with OAuth 2.0 and OpenID Connect for the whole stack | [`http://localhost:5001`](http://localhost:5001) or [`http://id.coolstore.local`](http://id.coolstore.local)
| 8 | Web UI (PWA) | Vuejs + Node.js | N/A | Frontend based on [vuejs](https://vuejs.org/) and [Node.js](https://nodejs.org) | [`http://localhost:8080`](http://localhost:8080) or [`http://coolstore.local`](http://coolstore.local)

### Architecture of µServices

![Architecture Screenshot](assets/images/arch-diagram.png?raw=true 'Architecture Diagram')

### Up and Running
## Features
- **[Kubernetes](https://kubernetes.io)/[AKS](https://docs.microsoft.com/en-us/azure/aks):**
The app is designed to run on Kubernetes (both locally on "Docker for
Desktop", as well as on the cloud with AKS).
- **[Istio](https://istio.io):** Application works on Istio service mesh.
- **[NetCoreKit](https://github.com/cloudnative-netcore/netcore-kit):** Set of Cloud Native tools and utilities for .NET Core.

1. Make sure we have **`Docker for Windows`** running with **`Kubernetes`** option enabled. We need to install **`kubectl`**, **`helm`** and **`istioctl`** on the build machine as well.
## Installation

### Option 1: Up and Running locally with "Docker for Desktop", development only

1. Make sure we have **`Docker for Desktop`** running with **`Kubernetes`** option enabled. We need to install **`kubectl`**, **`helm`** and **`istioctl`** on the build machine as well.

2. From current console, type `bash` to enter `Linux Subsystem (Ubuntu)`

Expand Down Expand Up @@ -149,32 +148,36 @@ Waiting for the container provision completed
> helm install --name cs-nginx stable/nginx-ingress
> ```
### µService Development
### Option 2: Up and Running on Azure Kubernetes Service (AKS)
TODO
## µService Development
![µService Screenshot](assets/images/miniservice-development.PNG?raw=true 'Microservice')
### Open API
## Open API
![OpenAPI Screenshot](assets/images/open-api.png?raw=true 'OpenAPI')
### CI/CD
## CI/CD
![Lift and Shift](assets/images/lift-and-shift.PNG?raw=true 'liftandshift')
### Contributing
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :p
### Contributors
## Contributors
| [Thang Chung](https://github.com/thangchung) | [Thinh Nguyen](https://github.com/thinhnotes) |
| ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| <img src="https://avatars3.githubusercontent.com/u/422341?s=460&v=4" alt="thangchung" width="150"/> | <img src="https://avatars2.githubusercontent.com/u/4660531?s=460&v=4" alt="thinhnguyen" width="150" /> |
### Licence
## Licence
Code released under [the MIT license](https://github.com/vietnam-devs/coolstore-microservices/blob/master/LICENSE).
2 changes: 1 addition & 1 deletion deploys/charts/coolstore/templates/nginx-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
- path: /
backend:
serviceName: spa-service
servicePort: 8080
servicePort: 80
- host: {{ .Values.hosts.idp }}
http:
paths:
Expand Down
5 changes: 5 additions & 0 deletions deploys/dockers/mysqldb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM mysql:8.0.12

# MYSQL_ROOT_PASSWORD must be supplied as an env var

COPY ./deploys/dockers/mysqldb/mysqldb-init.sql /docker-entrypoint-initdb.d
2 changes: 2 additions & 0 deletions deploys/dockers/mysqldb/mysqldb-init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE DATABASE maindb;
USE maindb;
7 changes: 5 additions & 2 deletions src/services/cart/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM microsoft/dotnet:2.1.2-aspnetcore-runtime-alpine AS base
WORKDIR /app

ENV PROJECT /src/src/services/cart
ENV EXECUTE_FILE VND.CoolStore.Services.Cart.dll

ARG service_version
ENV SERVICE_VERSION ${service_version:-0.0.1}

Expand All @@ -14,7 +17,7 @@ FROM microsoft/dotnet:2.1.302-sdk-alpine AS build
WORKDIR /src
COPY . .

WORKDIR /src/src/services/cart
WORKDIR $PROJECT

RUN dotnet restore -nowarn:msb3202,nu1503
RUN dotnet build --no-restore -c Release -o /app
Expand All @@ -25,4 +28,4 @@ RUN dotnet publish --no-restore -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "VND.CoolStore.Services.Cart.dll"]
ENTRYPOINT ["dotnet", "$EXECUTE_FILE"]
13 changes: 6 additions & 7 deletions src/services/cart/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using NetCoreKit.Infrastructure.EfCore.Extensions;
using VND.CoolStore.Services.Cart.Infrastructure.Db;

Expand All @@ -9,17 +10,15 @@ public class Program
{
public static void Main(string[] args)
{
var webHost = BuildWebHost(args);
if ((webHost.Services.GetService(typeof(IHostingEnvironment)) as IHostingEnvironment).IsDevelopment())
{
var webHost = CreateWebHostBuilder(args).Build();
var env = webHost.Services.GetService<IHostingEnvironment>();
if (env.IsDevelopment())
webHost = webHost.RegisterDbContext<CartDbContext>();
}
webHost.Run();
}

public static IWebHost BuildWebHost(string[] args) =>
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
.UseStartup<Startup>();
}
}
53 changes: 25 additions & 28 deletions src/services/cart/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using NetCoreKit.Infrastructure.AspNetCore.Miniservice;
using NetCoreKit.Infrastructure.EfCore.SqlServer;
using NetCoreKit.Infrastructure.EfCore.MySql;
using VND.CoolStore.Services.Cart.Infrastructure.Db;
using VND.CoolStore.Services.Cart.v1.Services;
using VND.CoolStore.Services.Cart.v2.Services;
Expand All @@ -14,35 +13,33 @@ public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var assemblies = new HashSet<Assembly>
{
typeof(Startup).GetTypeInfo().Assembly,
typeof(MiniServiceExtensions).GetTypeInfo().Assembly
};
services.AddMiniService<CartDbContext>(
new[] {typeof(Startup)},
svc =>
{
//svc.AddEfCoreMySqlDb();
svc.AddExternalSystemHealthChecks();
},
() => new Dictionary<string, object>
{
{
Constants.ClaimToScopeMap, new Dictionary<string, string>
{
{"access_cart_api", "cart_api_scope"}
}
},
{
Constants.Scopes, new Dictionary<string, string>
{
{"cart_api_scope", "Cart APIs"}
}
},
{Constants.Audience, "api"}
}
);

var claimToScopeMap = new Dictionary<string, string>
{
{"access_cart_api", "cart_api_scope"}
};

var scopes = new Dictionary<string, string>
{
{"cart_api_scope", "Cart APIs"}
};

var serviceParams = new ServiceParams
{
{"assemblies", assemblies},
{"audience", "api"},
{"claimToScopeMap", claimToScopeMap},
{"scopes", scopes}
};

services.AddScoped(sp => serviceParams);
services.AddEfCoreSqlServer();
services.AddScoped<NoTaxCaculator>();
services.AddScoped<TenPercentTaxCalculator>();
services.AddMiniService<CartDbContext>();
}

public void Configure(IApplicationBuilder app)
Expand Down
24 changes: 15 additions & 9 deletions src/services/cart/VND.CoolStore.Services.Cart.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.1.2" />
<PackageReference Include="Microsoft.Extensions.Http" Version="2.1.1" />
<PackageReference Include="NetCoreKit.Domain" Version="0.0.1" />
<PackageReference Include="NetCoreKit.Infrastructure.AspNetCore" Version="0.0.1" />
<PackageReference Include="NetCoreKit.Infrastructure.AspNetCore.CleanArch" Version="0.0.1" />
<PackageReference Include="NetCoreKit.Infrastructure.AspNetCore.Miniservice" Version="0.0.1" />
<PackageReference Include="NetCoreKit.Infrastructure.AspNetCore.OpenApi" Version="0.0.1" />
<PackageReference Include="NetCoreKit.Infrastructure.EfCore" Version="0.0.1" />
<PackageReference Include="NetCoreKit.Infrastructure.EfCore.SqlServer" Version="0.0.1" />
<PackageReference Include="NetCoreKit.Utils" Version="0.0.1" />
<PackageReference Include="NetCoreKit.Domain" Version="0.1.25" />
<PackageReference Include="NetCoreKit.Infrastructure" Version="0.1.25" />
<PackageReference Include="NetCoreKit.Infrastructure.AspNetCore" Version="0.1.25" />
<PackageReference Include="NetCoreKit.Infrastructure.AspNetCore.CleanArch" Version="0.1.25" />
<PackageReference Include="NetCoreKit.Infrastructure.AspNetCore.Miniservice" Version="0.1.25" />
<PackageReference Include="NetCoreKit.Infrastructure.AspNetCore.OpenApi" Version="0.1.25" />
<PackageReference Include="NetCoreKit.Infrastructure.EfCore" Version="0.1.25" />
<PackageReference Include="NetCoreKit.Infrastructure.EfCore.MySql" Version="0.1.25" />
<PackageReference Include="NetCoreKit.Infrastructure.EfCore.SqlServer" Version="0.1.25" />
<PackageReference Include="NetCoreKit.Utils" Version="0.1.25" />
<PackageReference Include="Scrutor" Version="2.2.2" />
<PackageReference Include="System.Reactive" Version="4.0.0" />
<PackageReference Include="System.Reactive" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="App_Data\" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/services/cart/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"ConnectionStrings": {
"mssqldb": "Server=tcp:127.0.0.1,1433;Database=maindb;User Id=cs;Password=P@ssw0rd;"
"mssqldb": "Server=tcp:127.0.0.1,1433;Database=maindb;User Id=cs;Password=P@ssw0rd;",
"mysqldb": "server=127.0.0.1;port=3306;uid=root;pwd=P@ssw0rd;database=maindb"
},
"Hosts": {
"Externals": {
Expand Down
11 changes: 11 additions & 0 deletions src/services/cart/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
"Database": "maindb",
"UserName": "cs",
"Password": "P@ssw0rd"
},
"mysqldb": {
"Host": "CART_DB_SERVICE_SERVICE_HOST",
"Port": "CART_DB_SERVICE_SERVICE_PORT",
"Database": "maindb",
"UserName": "root",
"Password": "P@ssw0rd",
"Major": 8,
"Minor": 0,
"Build": 12,
"DbType": 0
}
},
"Hosts": {
Expand Down
Loading

0 comments on commit 2cfbc88

Please sign in to comment.