gokit-todo

module
v0.0.0-...-dd0ccd7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2022 License: MIT

README

gokit-todo

GitHub Workflow Status GoDev codecov Go Report Card MIT license

Service Description
todo todoMVC backend API
gokit-todo-frontend todoMVC client

gokit-todo

Features

  • Kubernetes/GKE: The app is designed to run on Kubernetes (both locally on "Docker for Desktop", as well as on the cloud with GKE).
  • gRPC: Microservices use a high volume of gRPC calls to communicate to each other.
  • Istio: Application works on Istio service mesh.
  • Skaffold: Application is deployed to Kubernetes with a single command using Skaffold.
  • go-kit/kit: Go kit is a programming toolkit for building microservices (or elegant monoliths) in Go. We solve common problems in distributed systems and application architecture so you can focus on delivering business value.
  • todomvc: Helping you select an MV* framework

Motivation

I use go-kit/kit(microservices toolkit) to build business project and run on Kubernetes and Istio. I also to give few talks about How i use gokit

Go kit microservices toolkit include many microservices components itself (auth, circuitbreaker, ratelimit etcs.). We build microservices application and deploy to Kubernetes. We could drop those microservices components out with Service Mesh soluation (Istion Envoy proxy) and keep single microservice core business logic clear without any infra codes.

This demo project is todomvc/gokit-todo-frontend backend API implemented by gokit microservice tookit with best practice by myself.

Goals

  • Project: quick start a new microservice by toolchain cage1016/gk. Team member could follow same guideline to develop microservice quickly.
    • project layout
  • Testing: how to write unit test with table test go-sqlmock and gomock. integration test, e2e test with TestMain and docker-compose
  • DevOps: setup CI/CD workflow to increase devops lifecycle
    • skaffold
    • github action (CI)
    • Kubernetes
    • Istio

Install

this demo support docker-compose or nginx-ingress and istio

Docker-Compose
  1. Run todomvc frontend & gokit-todo backend API with docker-compose
    docker-compose -f docker-compose.full.yaml up -d
    
  2. Visit http://localhost:8080 for demo
  3. Clean docker-compose
    docker-compose -f docker-compose.full.yaml down --volume
    
k8s + Istio
  1. Prepare a Kubernetes cluster
  2. Install Istio (1.6.11)
    istioctl install
    kubectl label namespace default istio-injection=enabled
    
  3. Install gokit-todo & frontend
    kubectl apply -f https://raw.githubusercontent.com/cage1016/gokit-todo/master/deployments/k8s-istio.yaml
    
  4. Set up GATEWAY_HTTP_URL
    export INGRESS_HTTP_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
    export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
    export GATEWAY_HTTP_URL=$INGRESS_HOST:$INGRESS_HTTP_PORT
    echo $GATEWAY_HTTP_URL
    
  5. Visit $GATEWAY_HTTP_URL to access todomvc with gokit-todo backend API
  6. Delete gokit-todo & frontend
    kubectl delete -f https://raw.githubusercontent.com/cage1016/gokit-todo/master/deployments/k8s-istio.yaml
    
  7. Uninstall Istio
    istioctl manifest generate | kubectl delete -f -
    kubectl delete namespace istio-system
    kubectl label namespace default istio-injection=enabled --overwrite
    
k8s + nginx-ingress
  1. Prepare a Kubernetes cluster
  2. Install nginx-ingress CRD by helm3
    helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
    helm repo update
    helm install ingress-nginx ingress-nginx/ingress-nginx
    
  3. Install gokit-todo & frontend
    kubectl apply -f https://raw.githubusercontent.com/cage1016/gokit-todo/master/deployments/k8s-nginx-ingress.yaml
    
  4. Set up INGRESS_HTTP_URL
    export INGRESS_HTTP_PORT=$(kubectl get ingress frontend-ingress -o jsonpath='{.spec.rules.*.http.paths.*.backend.servicePort}')
    export INGRESS_HOST=$(kubectl get ingress frontend-ingress -o jsonpath='{.status.loadBalancer.ingress.*.hostname}')
    export INGRESS_HTTP_URL=$INGRESS_HOST:$INGRESS_HTTP_PORT
    echo $INGRESS_HTTP_URL
    
  5. Visit $INGRESS_HTTP_URL to access todomvc with gokit-todo backend API
  6. Delete gokit-todo & frontend
    kubectl delete -f https://raw.githubusercontent.com/cage1016/gokit-todo/master/deployments/k8s-nginx-ingress.yaml
    
  7. Uninstall nginx ingress
    helm uninstall ingress-nginx
    

Testing

  1. Makefile
    $ make
      down                           docker-compose down
      generate                       Regenerates GRPC proto and gomock
      help                           this help
      mod                            tidy go mod
      run                            docker-compose stop & up
      stop                           docker-compose stop
      test                           test: run unit test
      test-e2e                       test-e2e: run e2e test
      test-integration               test-integration: run integration test
      up                             docker-compose up
    
  2. unit test
    make test
    
  3. unit integration test by docker-compose
    make test-integration
    
  4. unit e2e test by docker-compose
    make test-e2e
    

License

Copyright © 2020 kaichu.io.
This project is MIT licensed.

Directories

Path Synopsis
cmd
internal
mocks/app/todo/model
Package automocks is a generated GoMock package.
Package automocks is a generated GoMock package.
mocks/app/todo/service
Package automocks is a generated GoMock package.
Package automocks is a generated GoMock package.
pb
test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL