# envinfo
## Getting started
EnvInfo is an open-source project. This goal is to provide a very small micro-service which display the execution environment in a JSON on the HTTP protocol.
It is written in the Rust language with the Rocket framework and offers a container image for using in a Kubernetes cluster, for example.
Below, find the instruction for localy rebuild the project and create a container image (based on docker runtime). Else, the current docker image is provide in gitlab registry `registry.gitlab.com/tech-engineering/tools/envinfo`.
## Build and run source codes
Build source code:
```bash
cargo build
```
And run the source code, run http server on port 8000:
```bash
ROCKET_PROFILE=debug cargo run
```
Test with httpie:
```
http http://127.0.0.1:8000
```
## Build container image
Build image for two platform CPU architecture (amd64 and arm64):
```bash
docker buildx build \
--push \
--platform linux/amd64,linux/arm64 \
-t envinfo:v0.1-test \
-f Dockerfile.alpine .
```
```bash
docker run --rm --name info -p 8080:8080 \
-d envinfo:v0.1-test
```
Remark: The port and address allow are configured for `0.0.0.0` on `8080`.
Test the endpoints (with httpie):
```bash
http http://localhost:8080
http http://localhost:8080/health
http http://localhost:8080/health/ready
http http://localhost:8080/health/alive
http http://localhost:8080/health/started
```
## Health probes implemented
The microservice implemented 4 endpoints:
- `/health/alive`
- `/health/ready`
- `/health/started`
- `/health`
These endpoints respond with HTTP status 200 OK on success or 503 Service Unavailable on failure, and a JSON object like the following:
Successful response for endpoints without additional per-check information:
```json
{
"status": "UP",
"checks": []
}
```
Only for `/health/started` endpoint:
```json
{
"status": "STARTED",
"endpoints": ["/health","/health/alive","/health/ready","/health/started"]
}
```
## Deploy on kubernetes cluster
The yaml manifest is ready to use. Apply on your cluster:
```bash
kubectl apply -f deploy/k8s/envinfo-deploy.yaml
```
Check it:
```bash
kubectl port-forward svc/envinfo-svc --address 0.0.0.0 80:8080
```
## Using
Test the endpoints (with httpie):
```bash
http http://localhost
http http://localhost/health
http http://localhost/health/ready
http http://localhost/health/alive
http http://localhost/health/started
```
Example, hostname of container:
```bash
or distro:
```bash
http http://localhost | jq ".distro"
```
or ip:
```bash
http http://localhost | jq ".net_interface.[].ip"
```
or name of environment variables:
```bash
http http://localhost | jq ".environment.[].name"
```
Search in particular an environment variable (here `ROCKET_ADDRESS`):
```bash
http http://localhost | jq '.environment.[] | select (.name=="ROCKET_ADDRESS")'
```
or (only value):
```bash
http http://localhost | jq '.environment.[] | select (.name=="ROCKET_ADDRESS")' | jq ".value"
```
## Contributing
Thanks to participate at this project if you want :)
I need any ideas about what display informations, or other.
## License
[MIT License](LICENSE)