Skip to content

FelixAnna/web-service-dlw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dlw - daily life web microservices (RESTful)

Build Status codecov Go Report Card

Table of Contents

Prepare

  1. Register OAuth Apps in https://github.com/settings/developers (2+ for different environment)

    the Authorization callback URL should be: {baseApiUrl}/user/oauth2/github/redirect

    keep the ClientID and ClientSecret

  2. Add parameters in aws parameter store:

    https://ap-southeast-1.console.aws.amazon.com/systems-manager/parameters/?region=ap-southeast-1&tab=Table ,

    use KMS customer managed keys if necessary.

3. [deprecated]Create Tables in aws DynamoDB: dlf.Memos, dlf.Users

  1. Prepare an SQL Server instance to store data for finance api, table will be automatic migrated

  2. Prepare database in MongoDB atlas (free forever for first 500MB)

    • database: dlw_mathematicals

    • collections: answers, questions

    • database: dlw_memo

    • collections: users, memos (replace dynamodb)

Tools

  1. install git: https://git-scm.com/downloads;
  2. install [dotnet 6 sdk] (https://dotnet.microsoft.com/en-us/download/dotnet/6.0);
  3. install nodejs and npm;
  4. install and configure azure cli;
  5. install kubectl;
  6. install helm;
  7. install terraform;
  8. install consul.

  1. [optional] install postman;
  2. [optional] install draw.io;
  3. [optional] install docker;
  4. [optional] install kind;
  5. [optional] install and configure aws cli.

Switch kubectl context

after you connected to aks, you context is attached to aks by default, if you want to check your local Kubernetes status, you need switch context:

kubectl config view
kubectl config use-context kind-dlw-cluster

Components

Microservices

(Here is the Application Gateway version, Nginx version is very similar) architecture overview

Service Path Tags
User api service user api service Go Report Card
Memo api service memo api service Go Report Card
Date api service date api service Go Report Card
Finance api service finance api service Go Report Card

Ingress

reference ingress

Metric Server

devops/metrics/*.yaml: enable metrics server which is necessary for horizontalautoscaler or veticalautoscaler if metric server not deployed by default, --kubelet-insecure-tls args is used for local, --metric-resolution can be set to longer if use docker-desktop

cloud based kubernetes already include metric server by default.

Dashboard

devops/dashboard: follow the instructions to enable dashboard.

DevOps

in "devops" folder, you can find how to deploy the microservices to azure Kubernetes service.

microservice helm chart is located in "./dlw-chart" and "./dlw-chart-nossl".

Docker build & push to azure container registry

  ## if you have docker, and want to push to docker hub

  tag=latest

  cd src/date-api
  docker build -t dlw-date-api:$tag -f date-api/Dockerfile . 
  docker image tag dlw-date-api:$tag yufelix/dlw-date-api:$tag
  docker image push yufelix/dlw-date-api:$tag
  
  cd ../finance-api
  docker build -t dlw-finance-api:$tag -f finance-api/Dockerfile . 
  docker image tag dlw-finance-api:$tag yufelix/dlw-finance-api:$tag
  docker image push yufelix/dlw-finance-api:$tag

  cd ../memo-api
  docker build -t dlw-memo-api:$tag -f memo-api/Dockerfile . 
  docker image tag dlw-memo-api:$tag yufelix/dlw-memo-api:$tag
  docker image push yufelix/dlw-memo-api:$tag

  cd ../user-api
  docker build -t dlw-user-api:$tag -f user-api/Dockerfile . 
  docker image tag dlw-user-api:$tag yufelix/dlw-user-api:$tag
  docker image push yufelix/dlw-user-api:$tag
# from devops/docker-compose dir
docker compose build --push
  ## if you do not have docker, and want to push to acr
    
  tag=latest
  cd src/date-api
  az acr build -t dlw-date-api:$tag -f Dockerfile -r hssdevacr -g felix-configuration-rg .
  cd ../finance-api
  az acr build -t dlw-finance-api:$tag -f Dockerfile -r hssdevacr -g felix-configuration-rg .
  cd ../memo-api
  az acr build -t dlw-memo-api:$tag -f Dockerfile -r hssdevacr -g felix-configuration-rg .
  cd ../user-api
  az acr build -t dlw-user-api:$tag -f Dockerfile -r hssdevacr -g felix-configuration-rg .

AKS(nginx)

deploy to aks with "prod" argument will create valid cert by cert-manager, and use consul as service register,

## deploy (need AWS CLI configured)
cd aks
sh install.sh prod  ## prod/dev
## destroy (need AWS CLI configured)
cd aks
sh uninstall.sh prod  ## prod/dev
## install/upgrade our microservices only (don't need to configure AWS CLI)
cd aks/services
sh main_services.sh prod ## prod/dev

following: ./devops/aks_nginx/readme.md

refer: Securing NGINX-ingress, Let's Encrypt

AKS(appgw)

This version contains SSL/TLS termination and https redirection, and use consul service discovery.

following: ./devops/aks_appgw/readme.md

refer: aks, application gateway for aks, application-gateway-kubernetes-ingress

local deployment

There is another folder "./dlw-chart-nossl" which is for deploying to a local kind cluster, it doesn't depend on cert-manager, and consul.

follow: ./devops/kind/readme.md

Front-end

implemented by ReactJs + Redux