Skip to content

Commit

Permalink
update readme for repo and sub-project
Browse files Browse the repository at this point in the history
  • Loading branch information
felix committed Dec 31, 2021
1 parent 0aca9ee commit c3bd6a1
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 45 deletions.
6 changes: 6 additions & 0 deletions date-api/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# date api

## functionalities
1. calculate distance of 2 given date, support Gregorian calendar and Lunar calender
2. return month date info for given date (with leap month, lunar date info)

## Docker Guide

### Build
Expand Down
12 changes: 6 additions & 6 deletions deployment/kubernetes/deployment_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ spec:
- containerPort: 8383
env:
- name: AWS_ACCESS_KEY_ID
value: "abc"
value: "AKIAVKEIRSYCJT2IJRZ6"
- name: AWS_SECRET_ACCESS_KEY
value: "xyz"
value: "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"
- name: AWS_REGION
value: "ap-southeast-1"
resources:
Expand Down Expand Up @@ -114,9 +114,9 @@ spec:
- containerPort: 8282
env:
- name: AWS_ACCESS_KEY_ID
value: "abc"
value: "AKIAVKEIRSYCJT2IJRZ6"
- name: AWS_SECRET_ACCESS_KEY
value: "xyz"
value: "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"
- name: AWS_REGION
value: "ap-southeast-1"
resources:
Expand Down Expand Up @@ -151,9 +151,9 @@ spec:
- containerPort: 8181
env:
- name: AWS_ACCESS_KEY_ID
value: "abc"
value: "AKIAVKEIRSYCJT2IJRZ6"
- name: AWS_SECRET_ACCESS_KEY
value: "xyz"
value: "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"
- name: AWS_REGION
value: "ap-southeast-1"
resources:
Expand Down
8 changes: 8 additions & 0 deletions memo-api/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# memo api

## functionalities
1. save user cared date - memo to db (in Gregorian calendar and Lunar calender)
2. search memo for user
3. call date api to calculate recent memo date (MMdd) for given memo


## Docker Guide

### Build
Expand Down
130 changes: 100 additions & 30 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,100 @@
# design for daily life web microservices

# auth api
auth/register
auth/login
auth/logout

# user api
GET users/

GET users/:userId
POST users/:userId
DELETE --
PUT --

type User struct{
id int
name string
email string
phone string
birthday time.Time
home *Address
}

type Address struct {
Country string
State string
City string
Details string
}
# dlw - daily life web microservices

## APIs
1. user api service
2. memo api service
3. date api service

## local test
1. set go env: profile=dev
2. start consul service and client: https://learn.hashicorp.com/tutorials/consul/docker-container-agents?in=consul/docker
1. start server

```bash
docker run \
-d \
-p 8500:8500 \
-p 8600:8600/udp \
--name=badger \
consul agent -server -ui -node=server-1 -bootstrap-expect=1 -client=0.0.0.0

```

check ip of the consul server by exec command inside badger server

```bash
docker exec badger consul members
```

2. register a client

```bash
docker run \
--name=fox \
consul agent -node=client-1 -join=172.17.0.2
```
3. store your aws credentials in place: https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html
1. for local recommand: Shared Credentials File
2. for docker container not in ecs/eks/ec2: use env
3. for docker container in ecs/eks/ec2: use aws role assume
4. start user-api on port 8181
1. run in local system:
```bash
go run .
```
2. run from local docker container:
```bash
docker run -d -e AWS_ACCESS_KEY_ID=xyz -e AWS_SECRET_ACCESS_KEY=abc -e AWS_REGION=ap-southeast-1 --publish 8383:8383 date-api:1.0.0
```
5. start memo-api on port 8282
6. start date-api on port 8383
7. test your api works
1. get github redirectUrl:
```bash
curl --location --request GET 'http://localhost:8181/oauth2/github/authorize/url'
```
2. copy to browser, and keep the token returned
3. login to user api with the github token
```bash
curl --location --request GET 'http://localhost:8181/oauth2/github/user?access_code=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'
```
4. add one user memo
```bash
curl --location --request PUT 'http://localhost:8282/memos/' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxNjM4MzYzMDY1MDgxIiwiZW1haWwiOiJ5dWVjbnVAaG90bWFpbC5jb20iLCJleHAiOjE2NDAzMjk1MjB9.uOvsu9mLS95Wc9uWONGR-DZx6WPfGxChrHJ6dPaAsag' \
--header 'Content-Type: application/json' \
--data-raw '{
"Subject": "Test Item 8",
"Description":"Test Description 8",
"MonthDay":1208,
"StartYear": 1999,
"Lunar":true
}'
```
5. find the memo just added, and see the previous and next memo date distance
```bash
curl --location --request GET 'http://localhost:8282/memos/recent?start=1124&end=1227' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxNjM4MzYzMDY1MDgxIiwiZW1haWwiOiJ5dWVjbnVAaG90bWFpbC5jb20iLCJleHAiOjE2NDAzMjk1MjB9.uOvsu9mLS95Wc9uWONGR-DZx6WPfGxChrHJ6dPaAsag'
```

## kubernete test

1. setup ingress-nginx by following: https://kubernetes.github.io/ingress-nginx/deploy/#docker-desktop
2. cd to deployment folder, update the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to correct value
3. start deployment from deployment folder:
```bash
kubectl apply -f deployment_dev.yaml
```

4. wait for the ingress resource ready
```bash
kubectl config set-context --current --namespace=dlw-dev
kubectl get ingress
```
5. now, you can access from local browser: http://localhost/date/status

6. clean resource when you finished the local test:
```bash
kubectl delete -f deployment_dev.yaml
```
9 changes: 0 additions & 9 deletions test.yaml

This file was deleted.

0 comments on commit c3bd6a1

Please sign in to comment.