Microsample installs the microsample snap, which is a snapped flask microservice.
It exposes an endpoint at: http://public-ip:8080/api/info
It also provides the (interface: http) enpoint, which allows you to relate this charm
with for example an ssl-termination-proxy, haproxy or any other charm that implements the interface: http)
This charm deploys a flask application and provides the interface:http for other charms to relate to it.
The deployed snap is a flask webservice named microsample. Here is the code for it. microsample-flask-snap. The webservice is the development flask web-server and is a starting point for more production grade implementations.
The snap runs on any linux distribution, which is one of the advantages with snaps. You could consider placing snaps in your IoT devices and deploy them with juju for automated tests and CI/CD pipelines.
This charm is a "hooks only charm" (Learn about it in the tutorial-a-tiny-hooks-charm). The charm is lightweight in the sense that it doesn't pull in a full python environmet which is the case with reactive based charms.
Stand alone usage
To deploy this charm its as simple as
juju deploy cs:~erik-lonroth/charm-microsample
Once the service is "Online", you can test accessing the service on default port 8080.
curl http://microsample-public-ip:8080/api/info curl http://microsample-public-ip:8080
Usage with an haproxy for availablity/loadbalancing
juju deploy cs:~erik-lonroth/charm-microsample juju add-unit microsample juju deploy haproxy juju relate microsample:website haproxy:reverseproxy juju expose haproxy
Now, access the service on port 80 as:
curl http://haproxy-public-ip/api/info curl http://haproxy-public-ip
You can verify the high availability by shuting down one of the units and you should still get a reply.
Practice material and tutorials
Consider tutorial-a-tiny-hooks-charm to get the hang of hook-only charms. (Beginner level)
Studying the code for microsample-flask-snap is a great excersise to learn snap/snapping.
Installing the microsample snap without juju
sudo snap install --edge microsample
After its installed, you can access it with:
Erik Lonroth (email@example.com)