How to Build & Deploy edgeSDK Microservices

This guide focuses on the building and deployment of edgeSDK microservices with mimik's provided edgeSDK microservices. The instructions on this guide are also applicable to other edgeSDK microservices built by third-party developers to serve applications with edgeSDK.


Download

To begin, you need to download one of the mimik provided edgeSDK microservices, feel free to use them in your development project:

Name of MicroserviceDownload LinkSwaggerHub API GuideOpen Source Code
mSuperDrive DownloadAPI DefinitionN/A
mDrive DownloadAPI DefinitionN/A
mBeam DownloadAPI Definition Open Source Code
mIoT DownloadAPI Definition Open Source Code
mMessages DownloadAPI Definition Open Source Code
mGameLobby DownloadAPI Definition Open Source Code
mModelShare DownloadAPI Definition Open Source Code
mSidecar DownloadN/A Open Source Code

Build A Microservice

This guide applies to whenever the source code of a microservice is changed and developer wants to build a new microservice image.


Prerequisites

First, gather the tools that you will need:


Steps to Build

  1. This guide starts from the working directory that contains the microservice project. (e.g. the directory that you perform npm install to install dependencies of the project.)

  2. Verify the installation of dependencies:

    npm install
  3. Next run build script:

    npm run-script build
  4. Verify that index.js is copied under /build directory.

    **Attention: You will need to have the root permission to perform the following task.**

  5. Change owner group of the build script in the deploy directory. Note: If you don't have a build.sh file, feel free to get one from source code of mimik's example edgeSDK microservice. But remember to change the project name "example" to your own project name.

    Note: For Windows user, please download Cygwin or Git Bash to perform this.

    sudo chmod a+x deploy/build.sh
  6. Run build script to create an image for the container under deploy directory:

    cd deploy && ./build.sh
  7. Verify that a tar file of mimik container image is created as xxxx-v1.tar under deploy directory.

  8. Now you can redirect back to the deployment section and deploy your newly built microservice.


Deployment

  1. Please make sure that you have downloaded the latest edgeSDK and it is running on your targeted development platform. You can always find the instructions on how to install and run edgeSDK on your development machine from:

  2. Please check that you have performed all the following prerequisite steps to setup you edgeSDK on your targeted platform:

    • Register yourself on mimik's developer portal and add your application information to the portal to get authorization of edgeSDK access.

      Note: You will need to know about OAuth 2.0 Authentication Flow. If you need more information about Redirect URL, please go HERE.

      **Attention: Please safe keep your App-ID and Redirect URL for OAuth authorization later on.**

  3. Get your edgeSDK access token from following OAuth tool of your targeted platform:

  4. Now you are ready to deploy microservice on the edgeSDK, please run the following commands on the bash terminal for corresponding microservices:

    Note: For Windows user, please download Cygwin or Git Bash to perform this.

    **Attention: Please run the following commend under the same directory/folder of your downloaded microservice file.** (replace everything with <> with your own parameters in following commands)

    The following curl command is for deploying this microservice to the edgeSDK:

    curl -i -H 'Authorization: Bearer <YourEdgeAccessToken>' -F "image=@<FileNameOfMicroservice>" http://localhost:8083/mcm/v1/images

    The following curl command is for specifying the environment variable and it is dependent on specific microservice: (Note: only MCM.BASE_API_PATH is required and unique for all microservices.)

    MicroserviceCommand
    mSuperDrive
    curl -i -H 'Authorization: Bearer <yourEdgeAccessToken>' -d '{"name": "superdrive-v1", "image": "superdrive-v1", "env": {"superdrive": "http://127.0.0.1:8083/superdrive/v1","MCM.BASE_API_PATH": "/superdrive/v1", "MCM.WEBSOCKET_SUPPORT": "false", "MFD": "https://mfd.mimik360.com/mFD/v1", "MPO": "https://mpo.mimik360.com/mPO/v1", "uMDS": "http://127.0.0.1:8083/mds/v1"} }' http://localhost:8083/mcm/v1/containers
    mDrive
    curl -i -H 'Authorization: Bearer <yourEdgeAccessToken>' -d '{"name": "drive-v1", "image": "drive-v1", "env": {"MCM.BASE_API_PATH": "/drive/v1", "AUTHORIZATION_KEY": "<yourCustomAuthorizationKey>"} }' http://localhost:8083/mcm/v1/containers
    mBeam
    curl -i -H 'Authorization: Bearer <yourEdgeAccessToken>' -d '{"name": "beam-v1", "image": "beam-v1", "env": {"MCM.BASE_API_PATH": "/beam/v1", "MCM.WEBSOCKET_SUPPORT": "true", "securityKey": "<yourSecurityKey>", "ownerCode": "<yourOwnerCode>", }}' http://localhost:8083/mcm/v1/containers
    mIoT
    curl -i -H 'Authorization: Bearer <YourEdgeAccessToken>' -d '{"name": "iot-v1", "image": "iot-v1", "env": {"MCM.BASE_API_PATH": "/iot/v1", "MATCH": "iot-v1", "uMDS": "http://localhost:8083/mds/v1", "PUB_URI": "iot/v1/notification", "PUB_TOPIC": "<Data_Description>"} }' http://localhost:8083/mcm/v1/containers
    mMessages
    curl -i -H 'Authorization: Bearer <YourEdgeAccessToken>' -d '{"name": "messages-v1", "image": "messages-v1", "env": {"MCM.BASE_API_PATH": "/messages/v1"} }' http://localhost:8083/mcm/v1/containers
    mGameLobby
    curl -i -H 'Authorization: Bearer <YourEdgeAccessToken>' -d '{"name": "games-v1", "image": "games-v1", "env": {"MCM.BASE_API_PATH": "/games/v1"} }' http://localhost:8083/mcm/v1/containers
    mModelShare
    curl -i -H 'Authorization: Bearer <YourEdgeAccessToken>' -d '{"name": "model-v1", "image": "model-v1", "env": {"MCM.BASE_API_PATH": "/modelshare/v1", "uMDS": "http://localhost:8083/mds/v1"} }' http://localhost:8083/mcm/v1/containers
    mSidecar
    curl -i -H 'Authorization: Bearer <YourEdgeAccessToken>' -d '{"name": "sidecar-v1", "image": "sidecar-v1", "env": {"MCM.BASE_API_PATH": "/sidecar/v1", "uMDS": "http://localhost:8083/mds/v1", "midUrl": "https://mid.mimik360.com", "clientId": "<YourAppIDfromDevPortal>", "<CustomEndpoint>": "<CustomRedirectURL>"} }' http://localhost:8083/mcm/v1/containers

    Note: We can always specify multiple objects of CustomEndpoint and CustomRedirectURL for HTTP proxy with mSidecar. i.e. { "/endpoint1" : "endpoint1.com", "/endpoint2": "endpoint2.com" }

  5. The output of the above command will return status code of 200 after the deployment is successful.

  6. Now you can read about the APIs in this microservice and check their functionalities on [SwaggerHub].