Skip to content

Commit

Permalink
Merge pull request #140 from ibm-watson-iot/dockertest
Browse files Browse the repository at this point in the history
Dockertest
  • Loading branch information
durera authored May 7, 2019
2 parents c5f8580 + a364e1a commit c650313
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 21 deletions.
20 changes: 17 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
group: travis_latest

language: python

services:
- docker

cache: pip

matrix:
include:
- python: "2.7"
- python: "3.5"
- python: "3.6"
- python: "3.7"
dist: xenial # required for Python >= 3.7
install: pip install tox-travis coveralls
script: tox
env: BUILD_DOCKER_IMAGES=true

install:
- pip install tox-travis coveralls
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

script:
- tox
- ./buildDockerImages.sh

after_success:
- coveralls
- coveralls
22 changes: 22 additions & 0 deletions buildDockerImages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# If BUILD_DOCKER_IMAGES is defined then build the docker container for the sample and upload it to dockerhub
# We only build this on the python 3.7 branch, and we don't build for PRs
if [ -n "$BUILD_DOCKER_IMAGES" ]; then
echo "Building docker images"

IMAGE_NAME=wiotp/psutil
IMAGE_SRC=samples/psutil

docker build -t ${IMAGE_NAME}:$TRAVIS_BRANCH ${IMAGE_SRC}
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
if [ "$TRAVIS_BRANCH" == "master" ]; then
docker tag ${IMAGE_NAME}:$TRAVIS_BRANCH ${IMAGE_NAME}:latest
docker push ${IMAGE_NAME}:latest
else
docker push ${IMAGE_NAME}:$TRAVIS_BRANCH
fi
fi
else
echo "Skipped docker image building"
fi
5 changes: 2 additions & 3 deletions samples/psutil/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ FROM python:3.7-alpine3.9
RUN apk add gcc linux-headers libc-dev

# Begin the install proper
RUN pip install wiotp-sdk psutil

RUN pip install wiotp-sdk==0.9.1 psutil
ADD src/ /opt/ibm/iotpsutil/
RUN ls /opt/ibm/iotpsutil && chmod +x /opt/ibm/iotpsutil/*.py
RUN chmod +x /opt/ibm/iotpsutil/*.py

ENTRYPOINT ["python", "/opt/ibm/iotpsutil/iotpsutil.py"]
44 changes: 29 additions & 15 deletions samples/psutil/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# IBM Watson IoT Platform PSUtil Device Client

Device code for sending system utilization data to IBM Watson IoT Platform
Device code for sending system utilization data to IBM Watson IoT Platform, powered by [giampaolo/psutil](https://github.com/giampaolo/psutil).

The following data points are supported:
> psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python.
The following data points are collected:
* CPU utilization (%)
* Memory utilization (%)
* Outbound network utilization across all network interfaces (KB/s)
Expand All @@ -18,8 +20,32 @@ The following data points are supported:
- `network.down` calculated using `psutil.net_io_counters()`


## Setup
## Docker

The easiest way to test out the sample is via the [wiotp/psutil](https://cloud.docker.com/u/wiotp/repository/docker/wiotp/psutil) Docker image provided and the `--quickstart` command line option.

```
$ docker run -d --name psutil wiotp/psutil --quickstart
psutil
$ docker logs -tf psutil
2019-05-07T11:09:19.672513500Z 2019-05-07 11:09:19,671 wiotp.sdk.device.client.DeviceClient INFO Connected successfully: d:quickstart:sample-iotpsutil:242ac110002
```

To connect as a registered device in your organization you must set the following environment variables: `WIOTP_IDENTITY_ORGID`, `WIOTP_IDENTITY_TYPEID`, `WIOTP_IDENTITY_DEVICEID`, and `WIOTP_AUTH_TOKEN` in the container's environment.

```
$ export WIOTP_IDENTITY_ORGID=myorgid
$ export WIOTP_IDENTITY_TYPEID=mytypeid
$ export WIOTP_IDENTITY_DEVICEID=mydeviceid
$ export WIOTP_AUTH_TOKEN=myauthtoken
$ docker run -d -e WIOTP_IDENTITY_ORGID -e WIOTP_IDENTITY_ORGID -e WIOTP_AUTH_TOKEN --name psutil wiotp/psutil
psutil
$ docker logs -tf psutil
2019-05-07T11:09:19.672513500Z 2019-05-07 11:09:19,671 wiotp.sdk.device.client.DeviceClient INFO Connected successfully: d:myorgid:mytypeid:mydeviceid
```


## Installation
Installation across all OS's is pretty much the same:

- Install any necessary system packages missing from the host (In order to [install psutil on Windows]((https://github.com/giampaolo/psutil/blob/master/INSTALL.rst#windows)) you'll need Visual Studio installed)
Expand All @@ -42,18 +68,6 @@ pi@raspberrypi ~ $ python iotpsutil.py --quickstart
```


## Registered Usage
The device sample supports using either a device configuration file or command line arguments to connect to your [private organization](https://internetofthings.ibmcloud.com/dashboard/)

```
python iotpsutil.py -c device.yaml
```

```
python iotpsutil.py -o organizationIf -t typeIf -i deviceId -T authToken
```


## Support Application
A sample application is provided that allows commands to be sent to the device when used in registered mode only.

Expand Down

0 comments on commit c650313

Please sign in to comment.