This was an interview related thing that I spent far too much time on, I do not actively use it anywhere so don't be fooled by the nice looking docs and pretty green passing build icon. It may work well as an example for how to operationalize a simple service though. For the puppet repo that goes along side this see https://github.com/RyanJarv/puppet-randrust.
- Description
- Usage - Configuration options and additional functionality
- Nagios Check
- Development - Guide for contributing to the module
- Contributors/References
A rust web app that returns a random base64 encoded string of a given length.
This assumes you have a kubernetes cluster setup with helm installed.
On OSx you can use the Edge install of docker-for-mac to setup Kubernetes by enabling it under the running Docker Icon -> Preferences -> Kubernetes.
For setting up helm on Kubernetes see the helm install guide.
After this is setup you can deploy by cloning this repo and running the deploy script.
git clone https://github.com/RyanJarv/randrust.git
cd randrust
./scripts/helm_deploy.sh
This uses Let's Encrypt for setting up SSL but without changes like using a valid domain name it will generate a self signed cert.
- Ubuntu 18.04
- Ubuntu 16.04
- Debian 9
curl -s https://packagecloud.io/install/repositories/jarv/test/script.deb.sh | sudo bash
apt install randrust
This listens on the port configured in /etc/default/randrust. By default it is 31531
.
Puppet supports the same systems as the package install.
See the puppet-randrust repo for more info.
# Install rust
curl https://sh.rustup.rs -sSf | sh
# Clone and build
git clone https://github.com/RyanJarv/randrust.git
cd randrust
./scripts/build.sh
# Run and test
./target/release/randrust 3413 &
curl localhost:3413/key/5
This uses nginx as a frontend with a self signed SSL cert.
See the reference docs for installing Docker Compose.
git clone https://github.com/RyanJarv/randrust.git
cd randrust
bash ./scripts/generate_test_certs.sh
docker-compose up
curl -k https://localhost/key/4
NOTE: This uses a self signed test key at ssl/test. This should be updated if it's used for anything but testing.
docker run -p 127.0.0.1:8080:80 ryanjarv/randrust &
curl http://localhost:8080/key/5
This repo includes the check_randrust.py
script you can use as a check in nagios.
Dependencies in requirements.txt
need to be installed.
python3 -m venv .venv
. .venv/bin/activate
./check_randrust.py
NOTE: Currently there is no option to disable SSL verification, so using it on self signed cert's will not work.
usage: check_randrust.py [-h] [-wt RANGE] [-ct RANGE] -u URL [-wl RANGE]
[-cl RANGE] [-v]
Randrust Nagios check.
optional arguments:
-h, --help show this help message and exit
-wt RANGE, --twarning RANGE
return warning if response time is greater out of
RANGE in seconds
-ct RANGE, --tcritical RANGE
return critical if response time is longer out of
RANGE in seconds)
-u URL, --url URL URL to check
-wl RANGE, --wlength RANGE
return warning if decoded string length is outside of
RANGE
-cl RANGE, --clength RANGE
return critical if decoded string length is outside of
RANGE
-v, --verbose increase output verbosity (use up to 3 times)
./check_randrust.py --url http://localhost:8000/key/4 --twarning .1 --tcritical .2 --clength 4:4
RANDRUST OK - Decoded returned string length is 4 | length=4;1:;4:4;0 rtime=0.00957179069519043;0.1;0.2;0
See Usage for setup info.
To lint and test deployment's you can use helm_lint.sh
and helm_deploy.sh
.
./scripts/helm_lint.sh
./scripts/helm_deploy.sh
At one point this repo was set up with the Circle CI helm orb for testing in AWS EKS, however it takes a long time to run and isn't cheap without some changes. May look into some other options at somepoint here.
I tried a few other way's like Kubernetes in Docker but ran into issues with setting up the ingress route (if you end up trying this check out this post, had some inconsistent luck there).
Right now though I just have Travis CI setup to lint the scripts and chart's while it's building the rust package.
Travis CI build's the rust app and debian package with cargo-deb and deploy's to crates.io.
Right now there isn't any testing on the Rust app, may change soon though.
In cases where other open source packages, repos or work helped with writing the source for this package I list what it is along with the original license.
- Icon used for the helm package was created by ibrandify (https://thenounproject.com/ibrandify/)
- CCPL.
- Ubuntu's 18.04 rsyslogd package was used as reference for control and init scripts, though some of it is simplified.
- Helm's scaffolding from the
helm create
command.
The rest is written by Ryan Gerstenkorn and licensed under BSD-2.