Creating Microservices

In order to create your microservice and make it work you have to pass three major steps:

  1. Create code for the Container
  2. Build the container image and push it to Docker hub repository
  3. Publish your Microservice using ioAuthoring

Step 1. Creating Code for the Container

Choose your language:

Step 2. Build and push to Docker Hub repository

Here we explain how to build the container image and push it to docker hub repository.

1. Sign up here https://hub.docker.com, sign in and create your public repository:

ms-create-build-01.png

2. Go to Terminal.

3. Go to the folder where your files are (final code and docker file) with the following command:

cd folder_full_path

for example, cd Desktop/folder...

4. Build the container image with the following command:

sudo docker build --no-cache -t marylin/catalog:sub_select_nodejs . (use your own repository name and folder)

NOTE:You need to append '-arm' to command above if you're building conatainer for ARM architecture:

sudo docker build --no-cache -t marylin/catalog:sub_select_nodejs-arm .

Be sure to type the '.' at the end of the command. This tells Docker to look in the current directory for the Dockerfile

What's really happening is that you are tagging your image so it can be distinguished from other microservices in the catalog

In the end you will see smth like this: Successfully built 356d14821233

TIP: If the result of docker build is ...returned a non-zero code: 137, try to stop ioFog Agent with sudo service iofog stop command, then build docker again and start ioFog agent with the command sudo service iofog start.

5. Be sure to login to Docker Hub via command line:

sudo docker login

6. Push the image into your catalog with:

sudo docker push marylin/catalog:sub_select_nodejs

ms-create-build-02.png

NOTE: You need to append '-arm' to command above if you're pushing conatainer for ARM architecture:

sudo docker push marylin/catalog:sub_select_nodejs-arm

7. Go to your Public repository at https://hub.docker.com

ms-create-build-03.png

You will see your pushed container image on the Tags tab.

Step 3. Publishing your Microservice

Use the "Publish" menu in the ioAuthoring tool to access the publishing portal.

Publish page allows to publish containers and use them on Build page afterwards.

The Elements that you publish in the portal will be available to you and other members of your organization. They will not be available to the general public.

  1. Drag and drop the element to the main area.
  2. Add Name to your Element.
  3. Add Container Image URL. It is the path to repository where the container is posted

Be sure to enter your container image string properly, such as:

marylin/catalog:sub_select_nodejs

ms-create-publish-01.png

NOTE: No matter you are building for an arm device or x86 device, DO NOT ADD -arm at the end of your identifier in Container Image field.

4. If you want to change the icon of your element, you can click on Choose File button below and upload an image:

ms-create-publish-02.png

After that click on Change Icon Image button and you will see your image on the element

ms-create-publish-03.png

5. The element that you have published appears in the catalog alongside the publicly available elements on Build page:

ms-create-publish-04.png

You can use your microservice right now for IoT system creation.