Tutorial: Build sample Docker type IOx app which consumes GPS service
In this tutorial, we will go through quick start quide on how to build a sample docker type application which will access GPS service, using docker development environment and package it to an IOx application. For more details on what are the different types of IOx application supported, refer this section.
Requirements
- Supported development environment architecture for ioxclient tool
- amd64
- darwin_386 (MACOS 10)
- darwin_amd64
- linux_386
- linux_amd64
- windows_386
- windows_amd64
- Minimum Docker version 1.10 (API 1.22)
- Docker daemon up and running
- Cisco IR800 device with GPS antenna.
- IOxCore and IOxGPS service running on the device. To know more about how to deploy and get the GPS service running on IR800 refer to this section.
Setup Docker development environment for IOx
Refer this section to setup docker daemon on your development machine for authentication with Cisco hosted DevHub repository.
Create Dockerfile
Create a file called Dockerfile and copy the below contents into it.You can chose any baserootfs comptabile with Linux 4.1 kernel x86 arch.IOx base rootfs is hosted on cisco dev as well.Below oneis for reference
- Lets create a simple python application which configures the gps service to stream location co-ordinates every 5 seconds and prints the output to a log file called app.log.
IOx exposes location of peristent log directory for apps via environment variable CAF_APP_LOG_DIR. Default location of this dir is /data/logs. Refer this section for more environment variables exposed by IOx to applications.
Printing to console can overflow the buffer and hang the target application. It is recommended not to print infinitely to console.
Copy below contents into a file called gps_app.py.
Copy below contents into a file called gps_api.py in the same directory as gps_app.py.
Copy below contents into a file called oauth.py in the same directory as gps_app.py.
Copy below contents into a file called gpsapp.sh in the same directory as gps_app.py.
Copy below contents into a file called GPS_Config.json in the same directory as gps_app.py.
Build Docker image
Now build docker image named gpsapp with version 1.0 using previously created dockerfile. Prepend sudo if the docker build command fails due to permission restrictions.
Verify application dependencies in docker image - optional
You can verify if the docker image now has all the applicantions's dependant libraries or modules by running docker container locally in developement environment. Execute below command to run docker container and getting access to shell session inside the container. For this tutorial, make sure that application binary is copied under /var/helloworld/ directory.
Create IOx package descriptor file
IOx package descriptor file contains metadata about the application, minimum resource requirements for running the application. Refer this section for more detailed description of various attributes and schema for package descriptor contents. Note: In some cases target field needs to be specified as an array like in case of python based target application, specify target value like ["python", "/usr/bin/app.py"].
Copy below contents into a file called package.yaml in the same directory as gps_app.py.
Create final IOx application package
Download and install latest version of ioxclient for your development environment from this location. Setup ioxclient device profile by configuring device IP, credentials and SSH port.
Use below ioxclient command to build final IOx application package named package.tar. Need to pass same docker image name and version that has been previously used to build the image. Prepend sudo if the ioxclient command fails due to permission restrictions.
Deploy/Activate/Start the application
Now you can deploy the application onto a physical or virtual IOx device using
either of the clients ioxclient or Local Manager or Fog Director. You can access
device Local Manager UI using the URL path https://:8443. Lets
use ioxclient to deploy this application to a device. Execute below ioxclient
commands to setup device profile, install, activate and start the application.
Refer profiles and
app management
for more ioxclient details. Note: Here we are using default attributes for
application activation.Provide the right activation payload as mentioned in gps
service page
Verify the application is running
Now lets console into the application and confirm that application is running successfully by logging the string at /data/logs/app.log. Use below ioxclient command to console into the application.
Tail the app log and you must see Location coordinates streamed every 5 seconds.
More sample applications