Jim-Lin / bee-bee-alert

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

architecture

architecture

service

  • elasticsearch

    search similar product

  • redis

    counter for hit product

  • golang backend

    • check product price and notify when it's expensive
    • notify hit product for marketing
  • nginx reverse proxy

chrome extension

notification

notification

local env.

requirements

  • Docker

Docker Compose

build & run

$ docker-compose up -d

cleanup

$ docker-compose rm -s

Elasticsearch

init fake data

$ curl -X PUT 'localhost:9200/bee' -H 'Content-Type: application/json' -d @./elasticsearch/fake/schema.json

$ curl -X POST 'localhost:9200/_bulk?pretty' -H 'Content-Type: application/x-ndjson' --data-binary @./elasticsearch/fake/water.json

# check index information
$ curl -X GET "localhost:9200/_cat/indices?v"

cleanup

$ curl -X DELETE "localhost:9200/bee"

cloud env. with GCP

gcp

requirements

  • Cloud SDK

create project

$ gcloud projects create bee-bee-alert-jimlin --name=bee-bee-alert --set-as-default

$ gcloud config set project bee-bee-alert-jimlin

$ gcloud config set compute/zone asia-east1-b

Take the following steps to enable the Kubernetes Engine API:

  1. Visit the https://console.cloud.google.com/projectselector/kubernetes in the Google Cloud Platform Console.
  2. Create or select a project.
  3. Wait for the API and related services to be enabled. This can take several minutes.

GKE

create cluster

$ gcloud container clusters create bee-bee-alert --machine-type n1-standard-1 --num-nodes 3 --enable-autoscaling --min-nodes 3 --max-nodes 7 --zone asia-east1-b

$ gcloud config set container/cluster bee-bee-alert

$ gcloud container clusters get-credentials bee-bee-alert

create configmap

$ kubectl create configmap nginx-config --from-file=./nginx/default.conf

$ kubectl create configmap backend-config --from-file=./backend/backend.properties

Continuous Deployment with Google Container Registry (GCR)

cd

Cloud Container Builder

enable the Container Builder API
https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com

give Container Builder Service Account container.developer role access to your Kubernetes Engine clusters

$ PROJECT="$(gcloud projects describe \
    $(gcloud config get-value core/project -q) --format='get(projectNumber)')"

$ gcloud projects add-iam-policy-binding $PROJECT \
    --member=serviceAccount:$PROJECT@cloudbuild.gserviceaccount.com \
    --role=roles/container.developer

add trigger

trigger

when push tag to GitHub, it will auto run by builder with cloudbuild.yaml
builder

init fake data

$ kubectl get pods
NAME                             READY     STATUS    RESTARTS   AGE
backend-6c78d66f56-8gkvc         1/1       Running   0          1m
backend-6c78d66f56-k7fkv         1/1       Running   0          1m
elasticsearch-5b7dc6659b-b98tf   1/1       Running   0          9m
nginx-8db8dbcdb-vpfkr            1/1       Running   0          40m
redis-54868fc78b-5jq9c           1/1       Running   0          2h

# run shell in the elasticsearch container
$ kubectl exec -it elasticsearch-5b7dc6659b-b98tf sh

$ curl -X PUT 'localhost:9200/bee' -H 'Content-Type: application/json' -d @./fake/schema.json

$ curl -X POST 'localhost:9200/_bulk?pretty' -H 'Content-Type: application/x-ndjson' --data-binary @./fake/water.json

$ exit

cleanup

$ kubectl delete configmap nginx-config
$ kubectl delete configmap backend-config

$ kubectl delete --all svc
$ kubectl delete --all deployment

# wait for the load balancer delete
$ gcloud compute forwarding-rules list

$ gcloud container clusters delete bee-bee-alert

About

License:MIT License


Languages

Language:Go 70.1%Language:JavaScript 29.9%