EGO WebServer
Skills up project. Uses the following staff:
- docker compose
- gin-gonic web server
- gorm database ORM
- swag docs generator
- prometheus + grafana
- wrk performance testing tool
- nginx reverse proxy with ssl
Prepare .env file based on template (see sample values):
export DB_HOST=127.0.0.1 # for local run only, not used by docker
export DB_PORT=5432 # for local run only, not used by docker
export DB_USER=anybody
export DB_PASSWORD=qwerty
export DB_NAME=ego
Prepare self-signed certificate for nginx:
$ mkdir .cert
# create certificate using any instruction from the internet,
# e.g. https://devopscube.com/create-self-signed-certificates-openssl/
# finally you need to have two files in ./.cert: server.crt & server.key
Start service locally:
$ source .env
$ make build
$ ./ego_server
Start service in docker:
$ source .env
$ docker compose up
Request sample:
$ curl http://localhost:8080/driver/count
$ curl -k https://localhost:8443/driver/count
Swagger generation:
$ go install github.com/swaggo/swag/cmd/swag@latest
$ make swagger
Grafana usage:
- Goto: localhost:3000, Login: admin/admin
- Create datasource: Type: Prometheus, URL: http://prometheus:9090
- Import dashboard: grafana.json
- Download wrk image:
docker pull williamyeh/wrk
- Generate drivers:
curl http://localhost:8080/testapi/drivers -d '{"count": 1000, "cleanup": true}'
- Generate requests:
for (( i=1; i <= 1000; i++ )); do echo "/driver/$i"; done > perftest/paths.txt
- Run test:
docker run --rm \
--net=host \
-v `pwd`/perftest:/ego \
williamyeh/wrk -t4 -c100 -d10s -s /ego/script.lua http://localhost:8080/`
Kubernetes local cluster
Service can be deployed into K8S local cluster.
Please see details here.