forked from open-horizon/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
92 lines (80 loc) · 4.1 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
sudo: true
language: minimal
os: linux
arch: amd64
dist: bionic
services:
- docker
branches:
only:
- master
# Install kafkacat to test cpu2evtstreams IBM Event Streams data
before_install:
- sudo apt-get update
- sudo apt-get -y install librdkafka-dev libyajl-dev
- sudo apt-get -y install kafkacat
# Install packages needed for docker, and qemu to build multi arch builds
addons:
apt:
update: true
packages:
- docker-ce
- qemu
- qemu-user-static
- binfmt-support
- dpkg-cross
# Required travis secret env vars for docker, publishing, and event streams:
# DOCKER_HUB_USER, DOCKER_HUB_PASS, PRIVATE_KEY, PUBLIC_KEY, HZN_EXCHANGE_USER_AUTH, EVTSTREAMS_API_KEY, EVTSTREAMS_BROKER_URL
# Publish to staging if successful
env:
- HZN_EXCHANGE_URL=https://stg.edge-fabric.com/v1 EVTSTREAMS_TOPIC=cpu2evtstreams HZN_DEVICE_ID=travis-test
# Install the hzn command
install:
- wget https://github.com/open-horizon/anax/releases/latest/download/horizon-agent-linux-deb-amd64.tar.gz -O /tmp/horizon-agent-linux-deb-amd64.tar.gz
- tar -zxf /tmp/horizon-agent-linux-deb-amd64.tar.gz -C /tmp/
- sudo apt-get install -y /tmp/horizon-cli*.deb
# Build and test the example services that were changed in the PR for all arches
# Note: tools/travis-find determines if the specified "service" was modified, so we know if we should test it.
# The three docker commands are to simulate the arm and arm64 arches for cross-compiling
# cpu2evtstreams is the only service that is checked end to end, making sure data is delivered to IBM Event Streams
script:
- services=( edge/services/helloworld edge/services/cpu_percent edge/services/gps edge/services/sdr edge/services/helloMMS edge/services/mqtt_broker edge/services/mqtt2kafka edge/services/hotword_detection edge/services/stopword_removal edge/services/audio2text edge/services/text2speech edge/services/voice2audio edge/services/processtext edge/evtstreams/cpu2evtstreams edge/evtstreams/sdr2evtstreams edge/evtstreams/watson_speech2text edge/services/volantmq edge/services/fft_server edge/services/fft_client )
- |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker run --rm -t arm32v6/alpine uname -m
docker run --rm -t arm64v8/ubuntu uname -m
for service in "${services[@]}"; do
if git diff --name-only $TRAVIS_COMMIT_RANGE | $TRAVIS_BUILD_DIR/tools/travis-find $service -v; then
if [[ $service == *"cpu2evtstreams"* ]]; then
echo "Monitor IBM Event Streams!"
kafkacat -C -c 1 -q -o end -f "%t/%p/%o/%k: %s\n" -b $EVTSTREAMS_BROKER_URL -X api.version.request=true -X security.protocol=sasl_ssl -X sasl.mechanisms=PLAIN -X sasl.username=token -X sasl.password=$EVTSTREAMS_API_KEY -t $EVTSTREAMS_TOPIC > $TRAVIS_BUILD_DIR/output.txt 2>&1 &
fi
cd $TRAVIS_BUILD_DIR/$service && make test-all-arches;
if [ $? -eq 0 ]; then
if [[ $service == *"cpu2evtstreams"* ]]; then
if grep -Fq "$HZN_DEVICE_ID" $TRAVIS_BUILD_DIR/output.txt; then
cat $TRAVIS_BUILD_DIR/output.txt
passed=( "${passed[@]}" "$service" )
fi
else
passed=( "${passed[@]}" "$service" )
fi
fi
fi
done
- cd $TRAVIS_BUILD_DIR
# If this is after the PR has been merged into master, and the test was successful, then publish the example
# Copy the public and provate signing keys to the location horizon searches for them,
# Log into docker and publish services and pattern "test-all-arches"
after_success:
- |
mkdir /home/travis/.hzn && mkdir /home/travis/.hzn/keys
echo $PUBLIC_KEY | base64 -d > /home/travis/.hzn/keys/service.public.pem
echo $PRIVATE_KEY | base64 -d > /home/travis/.hzn/keys/service.private.key
echo "$DOCKER_HUB_PASS" | docker login -u "$DOCKER_HUB_USER" --password-stdin &&
for service in "${passed[@]}"; do
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]] && git diff --name-only $TRAVIS_COMMIT_RANGE | $TRAVIS_BUILD_DIR/tools/travis-find $service -v; then
echo "Publishing $service..." &&
cd $TRAVIS_BUILD_DIR/$service && make publish;
fi
done