Appsody stack and OpenShift Do component for Mobile Foundation

Developing a microservice from scratch is generally a cumbersome process. Components or stacks help microservice developers to jump-start their apps without much effort. Currently, there are two popular CLI tools that enable this - Appsody and OpenShift Do (odo).

Appsody calls these as stacks while odo calls them components. Microservice developers who are coding for mobile clients (like mobile backend-for-frontends) need specialized versions of these jump-start kits, which are available now as Mobile Foudation Nodejs Appsody stack and Mobile Foundation Nodejs Openshift Do (odo) component. Both of these provide ready to use APIs for Push, Live Update and Analytics services.

Appsody

An Apssody stack can be initialized by using the following steps.

  1. Add the Mobile stacks repository to the repo list.
    appsody repo add mobile https://github.com/MobileFirst-Platform-Developer-Center/stacks/releases/download/latest/mobile-index.yaml
    
  2. Create a folder and traverse it. Initialize the Appsody stack.
     mkdir appsodymobile
     cd appsodymobile 
     appsody init mobile/nodejs-mobile-foundation
    

    These steps create a ready to use Appsody project. Sample APIs can be found in app.js of the created project.

  3. After your project has been initialized you can then run your application using the following command.
     appsody run --docker-options "--env MF_ENVVARS={\"push\":{\"mf_url\":\"<MFSERVER>\",\"mf_app_id\":\"<APPID>\",\"username\":\"<UNAME>\",\"password\":\"<PWD>\"},\"liveupdate\":{\"mf_url\":\"<MFSERVER>\",\"mf_app_id\":\"<APPID>\",\"username\":\"<UNAME>\",\"password\":\"<PWD>\"},\"analytics\":{\"mf_url\":\"<MFSERVER>\",\"mf_app_name\":\"<APPNAME>\",\"username\":\"<UNAME>\",\"password\":\"<PWD>\"},\"passport_filter\":{\"mf_url\":\"<MFSERVER>\",\"username\":\"<UNAME>\",\"password\":\"<PWD>\"}}"
    

    Each of the parameter in the Docker environment variable is explained below.

    MFSERVER

    The fully qualified Mobile Foundation service endpoint. For example, https://mf-xxxxx-mfpserver.mf.cluster.svc.local:9080 (Note the complete server address including the port is necesssary). If your Mobile Foundation service is running in an external cluster, provide the fully qualified ingress route.

    APPID

    For Android applications, APPID is the package name of the app and for iOS applications, it is the bundle ID. For example, com.acme.myapp.

    UNAME

    The confidential client username. For example, bffclient.

    PASSWORD

    The confidential client password. For example, bffclientpassword.

    APPNAME

    The application’s display name. For example, Acme’s Awesome App.

    Additionally, user context (user specific data like username, device details etc.) is made available to the end developer with the help of the passport strategy. The required Mobile Foundation URL, username and passport can be provided in the environment variables as values for key passport_filter in MF_ENVVARS environment variable.

    Alternatively, you can provide individual environment variables when all your services are pointing to a single Mobile Foundation server and a single application as below.

     appsody run --docker-options "-e mf_url=<MFSERVER> -e mf_app_id=<APPID> -e push_mf_username=<PUSH_UNAME> -e push_mf_password=<PUSH_PWD> -e liveupdate_mf_username=<LIVEUPDATE_UNAME> -e liveupdate_mf_password=<LIVEUPDATE_PWD> -e analytics_mf_username=<ANALYICS_UNAME> -e analytics_mf_password=<ANALYTICS_PWD> -e pf_mf_username=<PASSPORT_FILTER_UNAME> -e pf_mf_password=<PASSPORT_FILTER_PWD>"
    

    This launches a Docker container that continuously re-builds and re-runs your project, exposing it on port 3000.

    You can continue to edit the application in your preferred IDE (VSCode or others) and your changes will be reflected in the container that is running within a few seconds.

OpenShift Do (odo)

OpenShift Do is the CLI tool for developers provided by Red Hat for rapidly building and deploying micoservices. The Mobile Foundation Node.js odo component is tailored for developers to build backend or backend-for-frontend microservices for mobile apps. This component provides microservice developers with easy to use APIs to consume Mobile Foundation services such as Push Notifications, Mobile Foundation Analytics and Live Update. As an example, a push notification can be trigerred from the Nodejs backend based on the customer’s purchase value for an order placed from the mobile client.

The odo component can be intialized and used as explained here.

Note:

  • You can learn more about Appsody here.
  • You can learn more about OpenShift Do here.
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on June 26, 2020