Gourmet is a work in progress application that allow you to execute little applications on an isolated environment, it dowloads your manifest and runs it in a container. I start this application to improve my go knowledge and to work with the Docker API I am happy to share my idea and my tests with Swam an easy way to scale this type of application.
Gourmet exposes an HTTP API available at the
/project endpoint that accept a JSON request body like:
imgis the started point docker image
sourceis your script
envis a list of environment variables that you can use on your script
During my test I use this php script that send a message on SQS.
Your script has a console entrypoint executables in this path
gourmet uses it to run your program.
To integrate it with Docker I used
fsouza/go-dockerclient an open source
library written in go.
This is a snippet that can be used to create a new container. With the container started I use the exec feature to extract your source and to run it.
After each build Gourmet cleans all and destroies the environment.
At the moment it is gourmet, It could be different hypothetical use cases:
- high separated task
- run a testsuite
- dispatch specific functions
A microservice to work with docker container easily.
I thought about an easy way to scale this application and I found Swarm, it is a native cluster for docker and it seems awesome in first because it is compatibile with the docker api.
Swarm’s cluster has two actors:
- A master is the entrypoint of your requests, it provide an HTTP api compatible with docker.
- A series of nodes that communicate with the master.
During this example we will work with 1 master and 2 nodes. Build this machine with virtualbox , with another tool, or in cloud is not a problem and install docker.
Into the master pull swarm and create a cluster identifier.
swarm create returns a cluster_id use them to start the manager and the
manager_ip is the ip of your master server.
Now go into the node, because we must do few things.
cluster_id is the id created in the previous step and the
node_id is the ip
of your current node.
Enter into the master and restart your manager container
Now we are ready to test if all it’s up.
0.0.0.0.0 with your master ip if you are in the same server.
You’ll wait this type of response
Gourmet is a set of environment variables to create a connection with docker
api, in particular this function
Docker Swarm supports the same Docker API in this way gourmet uses more nodes.