Creating new service

Now it may be a good time to roll your own service on Armada. The easiest way to create a new service is to base it on a template. As an example we will use Armada's template for Python:

$ armada create uppercase-service -b python
Service uppercase-service has been created in /home/vagrant/uppercase-service from python template.
$ cd uppercase-service ; find
. ./README.md ./Dockerfile ./Vagrantfile ./supervisor ./supervisor/uppercase-service.conf ./src ./src/uppercase-service.py

As we can see number of files have been created. The template service has no useful functionality yet. Let's try to add something simple like echoing it's input in uppercase.

~/uppercase-service$ vim ./src/uppercase-service.py
import web class Index(object): def GET(self): return 'Service works!' class Shout(object): def GET(self, txt): return txt.upper() + "\n" def main(): urls = ( '/', Index.__name__, '/shout/(.*)', Shout.__name__, ) app = web.application(urls, globals()) app.run() if __name__ == '__main__': main()

Colored lines are the only ones that we've added. The rest was in a template. We can build the service image now.

~/uppercase-service$ armada build upcase-service
Pulling repository dockyard.armada.sh/microservice_python cae965566422: Pulling dependent layers 511136ea3c5a: Download complete ...(skipped)... 356e562e6310: Download complete Uploading context 9.728 kB Uploading context Step 0 : FROM dockyard.armada.sh/microservice_python ---> cae965566422 ...(skipped)... Removing intermediate container dbdff2a06a09 Successfully built c0b134888b7a

Building the service for the first time can take a little bit longer, because Armada downloads image microservice_python on which our template is based. This in turn is based on image microservice which is our recommended base docker image for microservices run on Armada. It contains some useful features such as autoregistering service in Armada catalog, and some other service discovery goodies.

Now, we can test our new service by running it from local dockyard (armada run upcase-service -d local) or push it to some other dockyard, so it will be available from every ship.

~/uppercase-service$ armada push upcase-service
Pushing microservice upcase-service to dockyard: 192.168.3.141:10000... The push refers to a repository [192.168.3.141:10000/upcase-service] (len: 1) Sending image list Pushing repository 192.168.3.141:10000/upcase-service (1 tags) Image 511136ea3c5a already pushed, skipping ...(skipped)... f87353915cb3: Image successfully pushed Pushing tag for rev [f87353915cb3] on {http://192.168.3.141:10000/v1/repositories/upcase-service/tags/latest}
~/uppercase-service$ armada run upcase-service
Running microservice upcase-service from dockyard: 192.168.3.141:10000 (alias: myrepo) locally... Service is running in container 9707b42a4c77 available at addresses: 192.168.3.141:49168 (80/tcp)
~/uppercase-service$ curl http://192.168.3.141:49168/shout/Armada-is-cool!
ARMADA-IS-COOL!

Many more fun functionalities can be added later on, but basics of building and running new REST services with Armada templates are that easy.

To learn how to operate many ships under Armada, please go to Connecting ships part.